module Cooked.MockChain.GenerateTx.Proposal
  ( toProposalProcedures,
  )
where

import Cardano.Api qualified as Cardano
import Cardano.Ledger.BaseTypes qualified as Cardano
import Cardano.Ledger.Conway.Core qualified as Conway
import Cardano.Ledger.Conway.Governance qualified as Conway
import Cardano.Ledger.Core qualified as Cardano (emptyPParamsStrictMaybe)
import Cardano.Ledger.Plutus.ExUnits qualified as Cardano
import Cardano.Node.Emulator.Internal.Node qualified as Emulator
import Control.Lens qualified as Lens
import Control.Monad.Catch
import Control.Monad.Reader
import Cooked.Conversion
import Cooked.MockChain.GenerateTx.Common
import Cooked.MockChain.GenerateTx.Witness
import Cooked.Skeleton
import Data.Default
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Map.Strict qualified as SMap
import Data.Maybe
import Data.Maybe.Strict
import Data.OSet.Strict qualified as OSet
import Data.Set qualified as Set
import Data.Text qualified as Text
import GHC.IO.Unsafe
import Ledger.Tx.CardanoAPI qualified as Ledger
import Lens.Micro qualified as MicroLens
import Network.HTTP.Simple qualified as Network
import Optics.Core
import PlutusLedgerApi.V1.Value qualified as Api
import PlutusLedgerApi.V3 qualified as Api

type ProposalGen a = TxGen (Emulator.PParams, Map Api.TxOutRef Api.TxOut) a

-- | Transorms a `TxParameterChange` into an actual change over a Cardano
-- parameter update
toPParamsUpdate :: TxParameterChange -> Conway.PParamsUpdate Emulator.EmulatorEra -> Conway.PParamsUpdate Emulator.EmulatorEra
toPParamsUpdate :: TxParameterChange
-> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
toPParamsUpdate TxParameterChange
pChange =
  -- From rational to bounded rational
  let toBR :: (Cardano.BoundedRational r) => Rational -> r
      toBR :: forall r. BoundedRational r => Rational -> r
toBR = r -> Maybe r -> r
forall a. a -> Maybe a -> a
fromMaybe r
forall a. Bounded a => a
minBound (Maybe r -> r) -> (Rational -> Maybe r) -> Rational -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> Maybe r
forall r. BoundedRational r => Rational -> Maybe r
Cardano.boundRational
      -- Helper to set one of the param update with a lens
      setL :: ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter s t a (StrictMaybe a)
l = ASetter s t a (StrictMaybe a) -> StrictMaybe a -> s -> t
forall s t a b. ASetter s t a b -> b -> s -> t
MicroLens.set ASetter s t a (StrictMaybe a)
l (StrictMaybe a -> s -> t) -> (a -> StrictMaybe a) -> a -> s -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> StrictMaybe a
forall a. a -> StrictMaybe a
SJust
   in case TxParameterChange
pChange of
        -- will exist later on: MinFeeRefScriptCostPerByte n -> setL Conway.ppuMinFeeRefScriptCostPerByteL $ fromIntegral n
        FeePerByte Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Coin)
Conway.ppuMinFeeAL (Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Coin
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        FeeFixed Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Coin)
Conway.ppuMinFeeBL (Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Coin
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        MaxBlockBodySize Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Word32)
  (StrictMaybe Word32)
-> Word32 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Word32)
  (StrictMaybe Word32)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Word32)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Word32)
Conway.ppuMaxBBSizeL (Word32 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Word32 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        MaxTxSize Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Word32)
  (StrictMaybe Word32)
-> Word32 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Word32)
  (StrictMaybe Word32)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Word32)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Word32)
Conway.ppuMaxTxSizeL (Word32 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Word32 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        MaxBlockHeaderSize Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Word16)
  (StrictMaybe Word16)
-> Word16 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Word16)
  (StrictMaybe Word16)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Word16)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Word16)
Conway.ppuMaxBHSizeL (Word16 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Word16 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        KeyDeposit Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Coin)
Conway.ppuKeyDepositL (Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Coin
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        PoolDeposit Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Coin)
Conway.ppuPoolDepositL (Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Coin
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        PoolRetirementMaxEpoch Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe EpochInterval)
  (StrictMaybe EpochInterval)
-> EpochInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe EpochInterval)
  (StrictMaybe EpochInterval)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe EpochInterval)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe EpochInterval)
Conway.ppuEMaxL (EpochInterval
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> EpochInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Word32 -> EpochInterval
Cardano.EpochInterval (Word32 -> EpochInterval) -> Word32 -> EpochInterval
forall a b. (a -> b) -> a -> b
$ Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        PoolNumber Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Natural)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Natural)
Conway.ppuNOptL (Natural -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        PoolInfluence Rational
q -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe NonNegativeInterval)
  (StrictMaybe NonNegativeInterval)
-> NonNegativeInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe NonNegativeInterval)
  (StrictMaybe NonNegativeInterval)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe NonNegativeInterval)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe NonNegativeInterval)
Conway.ppuA0L (NonNegativeInterval
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> NonNegativeInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ NonNegativeInterval
-> Maybe NonNegativeInterval -> NonNegativeInterval
forall a. a -> Maybe a -> a
fromMaybe NonNegativeInterval
forall a. Bounded a => a
minBound (Maybe NonNegativeInterval -> NonNegativeInterval)
-> Maybe NonNegativeInterval -> NonNegativeInterval
forall a b. (a -> b) -> a -> b
$ Rational -> Maybe NonNegativeInterval
forall r. BoundedRational r => Rational -> Maybe r
Cardano.boundRational Rational
q
        MonetaryExpansion Rational
q -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe UnitInterval)
  (StrictMaybe UnitInterval)
-> UnitInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe UnitInterval)
  (StrictMaybe UnitInterval)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe UnitInterval)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe UnitInterval)
Conway.ppuRhoL (UnitInterval
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> UnitInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ UnitInterval -> Maybe UnitInterval -> UnitInterval
forall a. a -> Maybe a -> a
fromMaybe UnitInterval
forall a. Bounded a => a
minBound (Maybe UnitInterval -> UnitInterval)
-> Maybe UnitInterval -> UnitInterval
forall a b. (a -> b) -> a -> b
$ Rational -> Maybe UnitInterval
forall r. BoundedRational r => Rational -> Maybe r
Cardano.boundRational Rational
q
        TreasuryCut Rational
q -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe UnitInterval)
  (StrictMaybe UnitInterval)
-> UnitInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe UnitInterval)
  (StrictMaybe UnitInterval)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe UnitInterval)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe UnitInterval)
Conway.ppuTauL (UnitInterval
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> UnitInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
q
        MinPoolCost Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Coin)
Conway.ppuMinPoolCostL (Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Coin
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        CoinsPerUTxOByte Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe CoinPerByte)
  (StrictMaybe CoinPerByte)
-> CoinPerByte
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe CoinPerByte)
  (StrictMaybe CoinPerByte)
forall era.
BabbageEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe CoinPerByte)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe CoinPerByte)
Conway.ppuCoinsPerUTxOByteL (CoinPerByte
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> CoinPerByte
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Coin -> CoinPerByte
Conway.CoinPerByte (Coin -> CoinPerByte) -> Coin -> CoinPerByte
forall a b. (a -> b) -> a -> b
$ Integer -> Coin
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        CostModels [Integer]
_pv1 [Integer]
_pv2 [Integer]
_pv3 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a. a -> a
id -- TODO unsupported for now
        Prices Rational
q Rational
r -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Prices)
  (StrictMaybe Prices)
-> Prices -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Prices)
  (StrictMaybe Prices)
forall era.
AlonzoEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Prices)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Prices)
Conway.ppuPricesL (Prices -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Prices -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ NonNegativeInterval -> NonNegativeInterval -> Prices
Cardano.Prices (Rational -> NonNegativeInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
q) (Rational -> NonNegativeInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
r)
        MaxTxExUnits Integer
n Integer
m -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe ExUnits)
  (StrictMaybe ExUnits)
-> ExUnits
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe ExUnits)
  (StrictMaybe ExUnits)
forall era.
AlonzoEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe ExUnits)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe ExUnits)
Conway.ppuMaxTxExUnitsL (ExUnits -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> ExUnits
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Natural -> Natural -> ExUnits
Cardano.ExUnits (Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n) (Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
m)
        MaxBlockExUnits Integer
n Integer
m -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe ExUnits)
  (StrictMaybe ExUnits)
-> ExUnits
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe ExUnits)
  (StrictMaybe ExUnits)
forall era.
AlonzoEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe ExUnits)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe ExUnits)
Conway.ppuMaxBlockExUnitsL (ExUnits -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> ExUnits
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Natural -> Natural -> ExUnits
Cardano.ExUnits (Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n) (Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
m)
        MaxValSize Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
forall era.
AlonzoEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Natural)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Natural)
Conway.ppuMaxValSizeL (Natural -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        CollateralPercentage Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
forall era.
AlonzoEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Natural)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Natural)
Conway.ppuCollateralPercentageL (Natural -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        MaxCollateralInputs Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
forall era.
AlonzoEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Natural)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Natural)
Conway.ppuMaxCollateralInputsL (Natural -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        PoolVotingThresholds Rational
a Rational
b Rational
c Rational
d Rational
e ->
          ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe PoolVotingThresholds)
  (StrictMaybe PoolVotingThresholds)
-> PoolVotingThresholds
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe PoolVotingThresholds)
  (StrictMaybe PoolVotingThresholds)
forall era.
ConwayEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe PoolVotingThresholds)
Lens'
  (PParamsUpdate EmulatorEra) (StrictMaybe PoolVotingThresholds)
Conway.ppuPoolVotingThresholdsL (PoolVotingThresholds
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> PoolVotingThresholds
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$
            UnitInterval
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> PoolVotingThresholds
Conway.PoolVotingThresholds (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
a) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
b) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
c) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
d) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
e)
        DRepVotingThresholds Rational
a Rational
b Rational
c Rational
d Rational
e Rational
f Rational
g Rational
h Rational
i Rational
j ->
          ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe DRepVotingThresholds)
  (StrictMaybe DRepVotingThresholds)
-> DRepVotingThresholds
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe DRepVotingThresholds)
  (StrictMaybe DRepVotingThresholds)
forall era.
ConwayEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe DRepVotingThresholds)
Lens'
  (PParamsUpdate EmulatorEra) (StrictMaybe DRepVotingThresholds)
Conway.ppuDRepVotingThresholdsL (DRepVotingThresholds
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> DRepVotingThresholds
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$
            UnitInterval
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> UnitInterval
-> DRepVotingThresholds
Conway.DRepVotingThresholds (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
a) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
b) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
c) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
d) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
e) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
f) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
g) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
h) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
i) (Rational -> UnitInterval
forall r. BoundedRational r => Rational -> r
toBR Rational
j)
        CommitteeMinSize Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Natural)
  (StrictMaybe Natural)
forall era.
ConwayEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Natural)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Natural)
Conway.ppuCommitteeMinSizeL (Natural -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Natural
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        CommitteeMaxTermLength Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe EpochInterval)
  (StrictMaybe EpochInterval)
-> EpochInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe EpochInterval)
  (StrictMaybe EpochInterval)
forall era.
ConwayEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe EpochInterval)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe EpochInterval)
Conway.ppuCommitteeMaxTermLengthL (EpochInterval
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> EpochInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Word32 -> EpochInterval
Cardano.EpochInterval (Word32 -> EpochInterval) -> Word32 -> EpochInterval
forall a b. (a -> b) -> a -> b
$ Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        GovActionLifetime Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe EpochInterval)
  (StrictMaybe EpochInterval)
-> EpochInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe EpochInterval)
  (StrictMaybe EpochInterval)
forall era.
ConwayEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe EpochInterval)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe EpochInterval)
Conway.ppuGovActionLifetimeL (EpochInterval
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> EpochInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Word32 -> EpochInterval
Cardano.EpochInterval (Word32 -> EpochInterval) -> Word32 -> EpochInterval
forall a b. (a -> b) -> a -> b
$ Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        GovActionDeposit Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
forall era.
ConwayEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Coin)
Conway.ppuGovActionDepositL (Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Coin
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        DRepRegistrationDeposit Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe Coin)
  (StrictMaybe Coin)
forall era.
ConwayEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe Coin)
Conway.ppuDRepDepositL (Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> Coin -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Integer -> Coin
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
        DRepActivity Integer
n -> ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe EpochInterval)
  (StrictMaybe EpochInterval)
-> EpochInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall {s} {t} {a} {a}.
ASetter s t a (StrictMaybe a) -> a -> s -> t
setL ASetter
  (PParamsUpdate EmulatorEra)
  (PParamsUpdate EmulatorEra)
  (StrictMaybe EpochInterval)
  (StrictMaybe EpochInterval)
forall era.
ConwayEraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe EpochInterval)
Lens' (PParamsUpdate EmulatorEra) (StrictMaybe EpochInterval)
Conway.ppuDRepActivityL (EpochInterval
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> EpochInterval
-> PParamsUpdate EmulatorEra
-> PParamsUpdate EmulatorEra
forall a b. (a -> b) -> a -> b
$ Word32 -> EpochInterval
Cardano.EpochInterval (Word32 -> EpochInterval) -> Word32 -> EpochInterval
forall a b. (a -> b) -> a -> b
$ Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n

-- | Translates a given skeleton proposal into a governance action
toGovAction :: TxSkelProposal -> ProposalGen (Conway.GovAction Emulator.EmulatorEra)
toGovAction :: TxSkelProposal -> ProposalGen (GovAction EmulatorEra)
toGovAction TxSkelProposal {Maybe [Char]
Maybe (Versioned Script, TxSkelRedeemer)
Address
TxGovAction
txSkelProposalAddress :: Address
txSkelProposalAction :: TxGovAction
txSkelProposalWitness :: Maybe (Versioned Script, TxSkelRedeemer)
txSkelProposalAnchor :: Maybe [Char]
txSkelProposalAddress :: TxSkelProposal -> Address
txSkelProposalAction :: TxSkelProposal -> TxGovAction
txSkelProposalWitness :: TxSkelProposal -> Maybe (Versioned Script, TxSkelRedeemer)
txSkelProposalAnchor :: TxSkelProposal -> Maybe [Char]
..} = do
  StrictMaybe (ScriptHash StandardCrypto)
sHash <- case Maybe (Versioned Script, TxSkelRedeemer)
txSkelProposalWitness of
    Maybe (Versioned Script, TxSkelRedeemer)
Nothing -> StrictMaybe (ScriptHash StandardCrypto)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (StrictMaybe (ScriptHash StandardCrypto))
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return StrictMaybe (ScriptHash StandardCrypto)
forall a. StrictMaybe a
SNothing
    Just (Versioned Script
script, TxSkelRedeemer
_) -> do
      Cardano.ScriptHash ScriptHash StandardCrypto
sHash <-
        [Char]
-> Either ToCardanoError ScriptHash
-> TxGen (PParams, Map TxOutRef TxOut) ScriptHash
forall a context.
[Char] -> Either ToCardanoError a -> TxGen context a
throwOnToCardanoError
          [Char]
"Unable to convert script hash"
          (ScriptHash -> Either ToCardanoError ScriptHash
Ledger.toCardanoScriptHash (Versioned Script -> ScriptHash
forall a. ToScriptHash a => a -> ScriptHash
toScriptHash Versioned Script
script))
      StrictMaybe (ScriptHash StandardCrypto)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (StrictMaybe (ScriptHash StandardCrypto))
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return (StrictMaybe (ScriptHash StandardCrypto)
 -> ReaderT
      (PParams, Map TxOutRef TxOut)
      (Either GenerateTxError)
      (StrictMaybe (ScriptHash StandardCrypto)))
-> StrictMaybe (ScriptHash StandardCrypto)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (StrictMaybe (ScriptHash StandardCrypto))
forall a b. (a -> b) -> a -> b
$ ScriptHash StandardCrypto
-> StrictMaybe (ScriptHash StandardCrypto)
forall a. a -> StrictMaybe a
SJust ScriptHash StandardCrypto
sHash
  case TxGovAction
txSkelProposalAction of
    TxGovActionParameterChange [TxParameterChange]
changes ->
      GovAction EmulatorEra -> ProposalGen (GovAction EmulatorEra)
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return (GovAction EmulatorEra -> ProposalGen (GovAction EmulatorEra))
-> GovAction EmulatorEra -> ProposalGen (GovAction EmulatorEra)
forall a b. (a -> b) -> a -> b
$
        StrictMaybe (GovPurposeId 'PParamUpdatePurpose EmulatorEra)
-> PParamsUpdate EmulatorEra
-> StrictMaybe (ScriptHash (EraCrypto EmulatorEra))
-> GovAction EmulatorEra
forall era.
StrictMaybe (GovPurposeId 'PParamUpdatePurpose era)
-> PParamsUpdate era
-> StrictMaybe (ScriptHash (EraCrypto era))
-> GovAction era
Conway.ParameterChange
          StrictMaybe (GovPurposeId 'PParamUpdatePurpose EmulatorEra)
forall a. StrictMaybe a
SNothing -- TODO, should not be Nothing later on
          ((PParamsUpdate EmulatorEra
 -> TxParameterChange -> PParamsUpdate EmulatorEra)
-> PParamsUpdate EmulatorEra
-> [TxParameterChange]
-> PParamsUpdate EmulatorEra
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl ((TxParameterChange
 -> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra)
-> PParamsUpdate EmulatorEra
-> TxParameterChange
-> PParamsUpdate EmulatorEra
forall a b c. (a -> b -> c) -> b -> a -> c
flip TxParameterChange
-> PParamsUpdate EmulatorEra -> PParamsUpdate EmulatorEra
toPParamsUpdate) (PParamsHKD StrictMaybe EmulatorEra -> PParamsUpdate EmulatorEra
forall era. PParamsHKD StrictMaybe era -> PParamsUpdate era
Conway.PParamsUpdate PParamsHKD StrictMaybe EmulatorEra
forall era. EraPParams era => PParamsHKD StrictMaybe era
Cardano.emptyPParamsStrictMaybe) [TxParameterChange]
changes)
          StrictMaybe (ScriptHash (EraCrypto EmulatorEra))
StrictMaybe (ScriptHash StandardCrypto)
sHash
    TxGovActionHardForkInitiation ProtocolVersion
_ -> [Char] -> ProposalGen (GovAction EmulatorEra)
forall context a. [Char] -> TxGen context a
throwOnString [Char]
"TxGovActionHardForkInitiation unsupported"
    TxGovActionTreasuryWithdrawals Map Credential Lovelace
mapCredentialLovelace -> do
      Map (RewardAccount StandardCrypto) Coin
cardanoMap <- [(RewardAccount StandardCrypto, Coin)]
-> Map (RewardAccount StandardCrypto) Coin
forall k a. Ord k => [(k, a)] -> Map k a
SMap.fromList ([(RewardAccount StandardCrypto, Coin)]
 -> Map (RewardAccount StandardCrypto) Coin)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     [(RewardAccount StandardCrypto, Coin)]
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Map (RewardAccount StandardCrypto) Coin)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Credential, Lovelace)
 -> ReaderT
      (PParams, Map TxOutRef TxOut)
      (Either GenerateTxError)
      (RewardAccount StandardCrypto, Coin))
-> [(Credential, Lovelace)]
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     [(RewardAccount StandardCrypto, Coin)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\(Credential
cred, Api.Lovelace Integer
lv) -> (,Integer -> Coin
Emulator.Coin Integer
lv) (RewardAccount StandardCrypto
 -> (RewardAccount StandardCrypto, Coin))
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (RewardAccount StandardCrypto)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (RewardAccount StandardCrypto, Coin)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TxGen (Map TxOutRef TxOut) (RewardAccount StandardCrypto)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (RewardAccount StandardCrypto)
forall context' context a.
Transform context' context =>
TxGen context a -> TxGen context' a
liftTxGen (Credential
-> TxGen (Map TxOutRef TxOut) (RewardAccount StandardCrypto)
toRewardAccount Credential
cred)) (Map Credential Lovelace -> [(Credential, Lovelace)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Credential Lovelace
mapCredentialLovelace)
      GovAction EmulatorEra -> ProposalGen (GovAction EmulatorEra)
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return (GovAction EmulatorEra -> ProposalGen (GovAction EmulatorEra))
-> GovAction EmulatorEra -> ProposalGen (GovAction EmulatorEra)
forall a b. (a -> b) -> a -> b
$ Map (RewardAccount (EraCrypto EmulatorEra)) Coin
-> StrictMaybe (ScriptHash (EraCrypto EmulatorEra))
-> GovAction EmulatorEra
forall era.
Map (RewardAccount (EraCrypto era)) Coin
-> StrictMaybe (ScriptHash (EraCrypto era)) -> GovAction era
Conway.TreasuryWithdrawals Map (RewardAccount (EraCrypto EmulatorEra)) Coin
Map (RewardAccount StandardCrypto) Coin
cardanoMap StrictMaybe (ScriptHash (EraCrypto EmulatorEra))
StrictMaybe (ScriptHash StandardCrypto)
sHash
    TxGovAction
TxGovActionNoConfidence -> GovAction EmulatorEra -> ProposalGen (GovAction EmulatorEra)
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return (GovAction EmulatorEra -> ProposalGen (GovAction EmulatorEra))
-> GovAction EmulatorEra -> ProposalGen (GovAction EmulatorEra)
forall a b. (a -> b) -> a -> b
$ StrictMaybe (GovPurposeId 'CommitteePurpose EmulatorEra)
-> GovAction EmulatorEra
forall era.
StrictMaybe (GovPurposeId 'CommitteePurpose era) -> GovAction era
Conway.NoConfidence StrictMaybe (GovPurposeId 'CommitteePurpose EmulatorEra)
forall a. StrictMaybe a
SNothing -- TODO, should not be Nothing later on
    TxGovActionUpdateCommittee {} -> [Char] -> ProposalGen (GovAction EmulatorEra)
forall context a. [Char] -> TxGen context a
throwOnString [Char]
"TxGovActionUpdateCommittee unsupported"
    TxGovActionNewConstitution Constitution
_ -> [Char] -> ProposalGen (GovAction EmulatorEra)
forall context a. [Char] -> TxGen context a
throwOnString [Char]
"TxGovActionNewConstitution unsupported"

-- | Translates a skeleton proposal into a proposal procedure alongside a
-- possible witness
toProposalProcedureAndWitness :: TxSkelProposal -> AnchorResolution -> ProposalGen (Conway.ProposalProcedure Emulator.EmulatorEra, Maybe (Cardano.ScriptWitness Cardano.WitCtxStake Cardano.ConwayEra))
toProposalProcedureAndWitness :: TxSkelProposal
-> AnchorResolution
-> ProposalGen
     (ProposalProcedure EmulatorEra,
      Maybe (ScriptWitness WitCtxStake ConwayEra))
toProposalProcedureAndWitness txSkelProposal :: TxSkelProposal
txSkelProposal@TxSkelProposal {Maybe [Char]
Maybe (Versioned Script, TxSkelRedeemer)
Address
TxGovAction
txSkelProposalAddress :: TxSkelProposal -> Address
txSkelProposalAction :: TxSkelProposal -> TxGovAction
txSkelProposalWitness :: TxSkelProposal -> Maybe (Versioned Script, TxSkelRedeemer)
txSkelProposalAnchor :: TxSkelProposal -> Maybe [Char]
txSkelProposalAddress :: Address
txSkelProposalAction :: TxGovAction
txSkelProposalWitness :: Maybe (Versioned Script, TxSkelRedeemer)
txSkelProposalAnchor :: Maybe [Char]
..} AnchorResolution
anchorResolution = do
  Integer
minDeposit <- ((PParams, Map TxOutRef TxOut) -> Integer)
-> ReaderT
     (PParams, Map TxOutRef TxOut) (Either GenerateTxError) Integer
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Coin -> Integer
Emulator.unCoin (Coin -> Integer)
-> ((PParams, Map TxOutRef TxOut) -> Coin)
-> (PParams, Map TxOutRef TxOut)
-> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Coin PParams Coin -> PParams -> Coin
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
Lens.view Getting Coin PParams Coin
forall era. ConwayEraPParams era => Lens' (PParams era) Coin
Lens' PParams Coin
Conway.ppGovActionDepositL (PParams -> Coin)
-> ((PParams, Map TxOutRef TxOut) -> PParams)
-> (PParams, Map TxOutRef TxOut)
-> Coin
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PParams, Map TxOutRef TxOut) -> PParams
forall a b. (a, b) -> a
fst)
  RewardAccount StandardCrypto
cred <- TxGen (Map TxOutRef TxOut) (RewardAccount StandardCrypto)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (RewardAccount StandardCrypto)
forall context' context a.
Transform context' context =>
TxGen context a -> TxGen context' a
liftTxGen (TxGen (Map TxOutRef TxOut) (RewardAccount StandardCrypto)
 -> ReaderT
      (PParams, Map TxOutRef TxOut)
      (Either GenerateTxError)
      (RewardAccount StandardCrypto))
-> TxGen (Map TxOutRef TxOut) (RewardAccount StandardCrypto)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (RewardAccount StandardCrypto)
forall a b. (a -> b) -> a -> b
$ Credential
-> TxGen (Map TxOutRef TxOut) (RewardAccount StandardCrypto)
toRewardAccount (Credential
 -> TxGen (Map TxOutRef TxOut) (RewardAccount StandardCrypto))
-> Credential
-> TxGen (Map TxOutRef TxOut) (RewardAccount StandardCrypto)
forall a b. (a -> b) -> a -> b
$ Address -> Credential
forall a. ToCredential a => a -> Credential
toCredential Address
txSkelProposalAddress
  GovAction EmulatorEra
govAction <- TxSkelProposal -> ProposalGen (GovAction EmulatorEra)
toGovAction TxSkelProposal
txSkelProposal
  let proposalAnchor :: Maybe
  (ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Anchor StandardCrypto))
proposalAnchor = do
        [Char]
anchor <- Maybe [Char]
txSkelProposalAnchor
        Url
anchorUrl <- Int -> Text -> Maybe Url
forall (m :: * -> *). MonadFail m => Int -> Text -> m Url
Cardano.textToUrl ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
anchor) ([Char] -> Text
Text.pack [Char]
anchor)
        let anchorDataHash :: TxGen (PParams, Map TxOutRef TxOut) ByteString
anchorDataHash =
              case AnchorResolution
anchorResolution of
                AnchorResolution
AnchorResolutionHttp ->
                  -- WARNING: very unsafe and unreproducible
                  IO (TxGen (PParams, Map TxOutRef TxOut) ByteString)
-> TxGen (PParams, Map TxOutRef TxOut) ByteString
forall a. IO a -> a
unsafePerformIO
                    ( (HttpException
 -> IO (TxGen (PParams, Map TxOutRef TxOut) ByteString))
-> IO (TxGen (PParams, Map TxOutRef TxOut) ByteString)
-> IO (TxGen (PParams, Map TxOutRef TxOut) ByteString)
forall (m :: * -> *) e a.
(HasCallStack, MonadCatch m, Exception e) =>
(e -> m a) -> m a -> m a
handle
                        (TxGen (PParams, Map TxOutRef TxOut) ByteString
-> IO (TxGen (PParams, Map TxOutRef TxOut) ByteString)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (TxGen (PParams, Map TxOutRef TxOut) ByteString
 -> IO (TxGen (PParams, Map TxOutRef TxOut) ByteString))
-> (HttpException
    -> TxGen (PParams, Map TxOutRef TxOut) ByteString)
-> HttpException
-> IO (TxGen (PParams, Map TxOutRef TxOut) ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> TxGen (PParams, Map TxOutRef TxOut) ByteString
forall context a. [Char] -> TxGen context a
throwOnString ([Char] -> TxGen (PParams, Map TxOutRef TxOut) ByteString)
-> (HttpException -> [Char])
-> HttpException
-> TxGen (PParams, Map TxOutRef TxOut) ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([Char]
"Error when parsing anchor " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> [Char]
forall a. Show a => a -> [Char]
show [Char]
anchor [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" with error: ") [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) ([Char] -> [Char])
-> (HttpException -> [Char]) -> HttpException -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Show a => a -> [Char]
show @Network.HttpException))
                        (([Char] -> IO Request
forall (m :: * -> *). MonadThrow m => [Char] -> m Request
Network.parseRequest [Char]
anchor IO Request
-> (Request -> IO (Response ByteString))
-> IO (Response ByteString)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Request -> IO (Response ByteString)
forall (m :: * -> *).
MonadIO m =>
Request -> m (Response ByteString)
Network.httpBS) IO (Response ByteString)
-> (Response ByteString
    -> TxGen (PParams, Map TxOutRef TxOut) ByteString)
-> IO (TxGen (PParams, Map TxOutRef TxOut) ByteString)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> ByteString -> TxGen (PParams, Map TxOutRef TxOut) ByteString
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> TxGen (PParams, Map TxOutRef TxOut) ByteString)
-> (Response ByteString -> ByteString)
-> Response ByteString
-> TxGen (PParams, Map TxOutRef TxOut) ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response ByteString -> ByteString
forall a. Response a -> a
Network.getResponseBody)
                    )
                AnchorResolutionLocal Map [Char] ByteString
urls ->
                  [Char]
-> [Char]
-> Map [Char] ByteString
-> TxGen (PParams, Map TxOutRef TxOut) ByteString
forall k a context.
Ord k =>
[Char] -> k -> Map k a -> TxGen context a
throwOnLookup [Char]
"Error when attempting to retrieve anchor url in the local anchor resolution map" [Char]
anchor Map [Char] ByteString
urls
        ReaderT
  (PParams, Map TxOutRef TxOut)
  (Either GenerateTxError)
  (Anchor StandardCrypto)
-> Maybe
     (ReaderT
        (PParams, Map TxOutRef TxOut)
        (Either GenerateTxError)
        (Anchor StandardCrypto))
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (ReaderT
   (PParams, Map TxOutRef TxOut)
   (Either GenerateTxError)
   (Anchor StandardCrypto)
 -> Maybe
      (ReaderT
         (PParams, Map TxOutRef TxOut)
         (Either GenerateTxError)
         (Anchor StandardCrypto)))
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Anchor StandardCrypto)
-> Maybe
     (ReaderT
        (PParams, Map TxOutRef TxOut)
        (Either GenerateTxError)
        (Anchor StandardCrypto))
forall a b. (a -> b) -> a -> b
$ Url -> SafeHash StandardCrypto AnchorData -> Anchor StandardCrypto
forall c. Url -> SafeHash c AnchorData -> Anchor c
Cardano.Anchor Url
anchorUrl (SafeHash StandardCrypto AnchorData -> Anchor StandardCrypto)
-> (ByteString -> SafeHash StandardCrypto AnchorData)
-> ByteString
-> Anchor StandardCrypto
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnchorData -> SafeHash StandardCrypto AnchorData
forall c. Crypto c => AnchorData -> SafeHash c AnchorData
Cardano.hashAnchorData (AnchorData -> SafeHash StandardCrypto AnchorData)
-> (ByteString -> AnchorData)
-> ByteString
-> SafeHash StandardCrypto AnchorData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> AnchorData
Cardano.AnchorData (ByteString -> Anchor StandardCrypto)
-> TxGen (PParams, Map TxOutRef TxOut) ByteString
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Anchor StandardCrypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TxGen (PParams, Map TxOutRef TxOut) ByteString
anchorDataHash
  Anchor StandardCrypto
anchor <- ReaderT
  (PParams, Map TxOutRef TxOut)
  (Either GenerateTxError)
  (Anchor StandardCrypto)
-> Maybe
     (ReaderT
        (PParams, Map TxOutRef TxOut)
        (Either GenerateTxError)
        (Anchor StandardCrypto))
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Anchor StandardCrypto)
forall a. a -> Maybe a -> a
fromMaybe (Anchor StandardCrypto
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Anchor StandardCrypto)
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return Anchor StandardCrypto
forall a. Default a => a
def) Maybe
  (ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Anchor StandardCrypto))
proposalAnchor
  let conwayProposalProcedure :: ProposalProcedure EmulatorEra
conwayProposalProcedure = Coin
-> RewardAccount (EraCrypto EmulatorEra)
-> GovAction EmulatorEra
-> Anchor (EraCrypto EmulatorEra)
-> ProposalProcedure EmulatorEra
forall era.
Coin
-> RewardAccount (EraCrypto era)
-> GovAction era
-> Anchor (EraCrypto era)
-> ProposalProcedure era
Conway.ProposalProcedure (Integer -> Coin
Emulator.Coin Integer
minDeposit) RewardAccount (EraCrypto EmulatorEra)
RewardAccount StandardCrypto
cred GovAction EmulatorEra
govAction Anchor (EraCrypto EmulatorEra)
Anchor StandardCrypto
anchor
  (ProposalProcedure EmulatorEra
conwayProposalProcedure,) (Maybe (ScriptWitness WitCtxStake ConwayEra)
 -> (ProposalProcedure EmulatorEra,
     Maybe (ScriptWitness WitCtxStake ConwayEra)))
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Maybe (ScriptWitness WitCtxStake ConwayEra))
-> ProposalGen
     (ProposalProcedure EmulatorEra,
      Maybe (ScriptWitness WitCtxStake ConwayEra))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Maybe (Versioned Script, TxSkelRedeemer)
txSkelProposalWitness of
    Maybe (Versioned Script, TxSkelRedeemer)
Nothing -> Maybe (ScriptWitness WitCtxStake ConwayEra)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Maybe (ScriptWitness WitCtxStake ConwayEra))
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (ScriptWitness WitCtxStake ConwayEra)
forall a. Maybe a
Nothing
    Just (Versioned Script
script, TxSkelRedeemer
redeemer) -> ScriptWitness WitCtxStake ConwayEra
-> Maybe (ScriptWitness WitCtxStake ConwayEra)
forall a. a -> Maybe a
Just (ScriptWitness WitCtxStake ConwayEra
 -> Maybe (ScriptWitness WitCtxStake ConwayEra))
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (ScriptWitness WitCtxStake ConwayEra)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Maybe (ScriptWitness WitCtxStake ConwayEra))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TxGen (Map TxOutRef TxOut) (ScriptWitness WitCtxStake ConwayEra)
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (ScriptWitness WitCtxStake ConwayEra)
forall context' context a.
Transform context' context =>
TxGen context a -> TxGen context' a
liftTxGen (Versioned Script
-> TxSkelRedeemer
-> ScriptDatum WitCtxStake
-> TxGen (Map TxOutRef TxOut) (ScriptWitness WitCtxStake ConwayEra)
forall a b.
ToVersionedScript a =>
a
-> TxSkelRedeemer
-> ScriptDatum b
-> WitnessGen (ScriptWitness b ConwayEra)
toScriptWitness (Versioned Script -> Versioned Script
forall a. ToVersionedScript a => a -> Versioned Script
toVersionedScript Versioned Script
script) TxSkelRedeemer
redeemer ScriptDatum WitCtxStake
Cardano.NoScriptDatumForStake)

-- | Translates a list of skeleton proposals into a proposal procedures
toProposalProcedures :: [TxSkelProposal] -> AnchorResolution -> ProposalGen (Cardano.TxProposalProcedures Cardano.BuildTx Cardano.ConwayEra)
toProposalProcedures :: [TxSkelProposal]
-> AnchorResolution
-> ProposalGen (TxProposalProcedures BuildTx ConwayEra)
toProposalProcedures [TxSkelProposal]
props AnchorResolution
anchorResolution = do
  (Set (ProposalProcedure EmulatorEra)
-> OSet (ProposalProcedure EmulatorEra)
forall a. Set a -> OSet a
OSet.fromSet -> OSet (ProposalProcedure EmulatorEra)
ppSet, Map
  (ProposalProcedure EmulatorEra)
  (ScriptWitness WitCtxStake ConwayEra)
-> BuildTxWith
     BuildTx
     (Map
        (ProposalProcedure EmulatorEra)
        (ScriptWitness WitCtxStake ConwayEra))
forall a. a -> BuildTxWith BuildTx a
Cardano.BuildTxWith -> BuildTxWith
  BuildTx
  (Map
     (ProposalProcedure EmulatorEra)
     (ScriptWitness WitCtxStake ConwayEra))
ppMap) <- [TxSkelProposal]
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Set (ProposalProcedure EmulatorEra),
      Map
        (ProposalProcedure EmulatorEra)
        (ScriptWitness WitCtxStake ConwayEra))
go [TxSkelProposal]
props
  TxProposalProcedures BuildTx ConwayEra
-> ProposalGen (TxProposalProcedures BuildTx ConwayEra)
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TxProposalProcedures BuildTx ConwayEra
 -> ProposalGen (TxProposalProcedures BuildTx ConwayEra))
-> TxProposalProcedures BuildTx ConwayEra
-> ProposalGen (TxProposalProcedures BuildTx ConwayEra)
forall a b. (a -> b) -> a -> b
$
    if OSet (ProposalProcedure EmulatorEra) -> Bool
forall a. OSet a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null OSet (ProposalProcedure EmulatorEra)
ppSet
      then TxProposalProcedures BuildTx ConwayEra
forall build era. TxProposalProcedures build era
Cardano.TxProposalProceduresNone
      else OSet (ProposalProcedure (ShelleyLedgerEra ConwayEra))
-> BuildTxWith
     BuildTx
     (Map
        (ProposalProcedure (ShelleyLedgerEra ConwayEra))
        (ScriptWitness WitCtxStake ConwayEra))
-> TxProposalProcedures BuildTx ConwayEra
forall era build.
EraPParams (ShelleyLedgerEra era) =>
OSet (ProposalProcedure (ShelleyLedgerEra era))
-> BuildTxWith
     build
     (Map
        (ProposalProcedure (ShelleyLedgerEra era))
        (ScriptWitness WitCtxStake era))
-> TxProposalProcedures build era
Cardano.TxProposalProcedures OSet (ProposalProcedure (ShelleyLedgerEra ConwayEra))
OSet (ProposalProcedure EmulatorEra)
ppSet BuildTxWith
  BuildTx
  (Map
     (ProposalProcedure (ShelleyLedgerEra ConwayEra))
     (ScriptWitness WitCtxStake ConwayEra))
BuildTxWith
  BuildTx
  (Map
     (ProposalProcedure EmulatorEra)
     (ScriptWitness WitCtxStake ConwayEra))
ppMap
  where
    go :: [TxSkelProposal]
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Set (ProposalProcedure EmulatorEra),
      Map
        (ProposalProcedure EmulatorEra)
        (ScriptWitness WitCtxStake ConwayEra))
go [] = (Set (ProposalProcedure EmulatorEra),
 Map
   (ProposalProcedure EmulatorEra)
   (ScriptWitness WitCtxStake ConwayEra))
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Set (ProposalProcedure EmulatorEra),
      Map
        (ProposalProcedure EmulatorEra)
        (ScriptWitness WitCtxStake ConwayEra))
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Set (ProposalProcedure EmulatorEra)
forall a. Set a
Set.empty, Map
  (ProposalProcedure EmulatorEra)
  (ScriptWitness WitCtxStake ConwayEra)
forall k a. Map k a
Map.empty)
    go (TxSkelProposal
h : [TxSkelProposal]
t) = do
      (Set (ProposalProcedure EmulatorEra)
proposals, Map
  (ProposalProcedure EmulatorEra)
  (ScriptWitness WitCtxStake ConwayEra)
mapWitnesses) <- [TxSkelProposal]
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Set (ProposalProcedure EmulatorEra),
      Map
        (ProposalProcedure EmulatorEra)
        (ScriptWitness WitCtxStake ConwayEra))
go [TxSkelProposal]
t
      (ProposalProcedure EmulatorEra
proposal, Maybe (ScriptWitness WitCtxStake ConwayEra)
maybeWitness) <- TxSkelProposal
-> AnchorResolution
-> ProposalGen
     (ProposalProcedure EmulatorEra,
      Maybe (ScriptWitness WitCtxStake ConwayEra))
toProposalProcedureAndWitness TxSkelProposal
h AnchorResolution
anchorResolution
      let outputMap :: Map
  (ProposalProcedure EmulatorEra)
  (ScriptWitness WitCtxStake ConwayEra)
outputMap = case Maybe (ScriptWitness WitCtxStake ConwayEra)
maybeWitness of
            Maybe (ScriptWitness WitCtxStake ConwayEra)
Nothing -> Map
  (ProposalProcedure EmulatorEra)
  (ScriptWitness WitCtxStake ConwayEra)
mapWitnesses
            Just ScriptWitness WitCtxStake ConwayEra
newWitness -> ProposalProcedure EmulatorEra
-> ScriptWitness WitCtxStake ConwayEra
-> Map
     (ProposalProcedure EmulatorEra)
     (ScriptWitness WitCtxStake ConwayEra)
-> Map
     (ProposalProcedure EmulatorEra)
     (ScriptWitness WitCtxStake ConwayEra)
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert ProposalProcedure EmulatorEra
proposal ScriptWitness WitCtxStake ConwayEra
newWitness Map
  (ProposalProcedure EmulatorEra)
  (ScriptWitness WitCtxStake ConwayEra)
mapWitnesses
      (Set (ProposalProcedure EmulatorEra),
 Map
   (ProposalProcedure EmulatorEra)
   (ScriptWitness WitCtxStake ConwayEra))
-> ReaderT
     (PParams, Map TxOutRef TxOut)
     (Either GenerateTxError)
     (Set (ProposalProcedure EmulatorEra),
      Map
        (ProposalProcedure EmulatorEra)
        (ScriptWitness WitCtxStake ConwayEra))
forall a.
a
-> ReaderT (PParams, Map TxOutRef TxOut) (Either GenerateTxError) a
forall (m :: * -> *) a. Monad m => a -> m a
return (ProposalProcedure EmulatorEra
-> Set (ProposalProcedure EmulatorEra)
-> Set (ProposalProcedure EmulatorEra)
forall a. Ord a => a -> Set a -> Set a
Set.insert ProposalProcedure EmulatorEra
proposal Set (ProposalProcedure EmulatorEra)
proposals, Map
  (ProposalProcedure EmulatorEra)
  (ScriptWitness WitCtxStake ConwayEra)
outputMap)