cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.MockChain.State

Description

This module exposes the internal state in which our direct simulation is run (MockChainState), as well as a restricted and simplified version (UtxoState). The latter only consists of Utxos with a focus on who owns those Utxos. You can see this as having some sort of an "account" view of the ledger state, which typically does not exist in Cardano. This is useful for two reasons:

  • For printing purposes, where it is much more convient to see the available assets as "who owns what" rather than as a set of mixed Utxos.
  • For testings purposes, when querying the final state of a run is needed. For instance, properties such as "does Alice indeed owns 3 XXX tokens at the end of this run?" become much easier to express.
Synopsis

MockChainState and associated optics

data MockChainState where Source #

The state used to run the simulation in Direct

Constructors

MockChainState 

Fields

mcstParamsL :: Lens' MockChainState Params Source #

A lens to set or get the parameters of the MockChainState

mcstLedgerStateL :: Lens' MockChainState EmulatedLedgerState Source #

A lens to set or get the ledger state of the MockChainState

mcstOutputsL :: Lens' MockChainState (Map TxOutRef (TxSkelOut, Bool)) Source #

A lens to set or get the outputs of the MockChainState

mcstConstitutionL :: Lens' MockChainState (Maybe VScript) Source #

A lens to set or get the constitution script of the MockChainState

mcstMOutputL :: TxOutRef -> Lens' MockChainState (Maybe TxSkelOut) Source #

Accesses a given available Utxo from a MockChainState

Helpers to add or remove outputs from a MockChainState

removeOutput :: TxOutRef -> MockChainState -> MockChainState Source #

Removes an output from the MockChainState. This does not actually remove it from the map, but instead marks its availability to False

UtxoState: A simplified, address-focused view on a MockChainState

data UtxoPayloadDatum where Source #

A simplified version of a TxSkelOutDatum which only stores the actual datum and whether it is hashed (True) or inline (False). The only difference is that whether the datum was resolved in the transaction creating it on the ledger is absent, which makes sense after the fact.

utxoPayloadDatumTypedAT :: (DatumConstrs a, DatumConstrs b) => AffineTraversal UtxoPayloadDatum UtxoPayloadDatum a b Source #

Extracts, or sets, the typed datum of a UtxoPayloadDatum following the same rules as txSkelOutDatumTypedAT

data UtxoPayload where Source #

A convenient wrapping of the interesting information of a UTxO.

Constructors

UtxoPayload 

Fields

Instances

Instances details
Show UtxoPayload Source # 
Instance details

Defined in Cooked.MockChain.State

Eq UtxoPayload Source # 
Instance details

Defined in Cooked.MockChain.State

utxoPayloadTxOutRefL :: Lens' UtxoPayload TxOutRef Source #

A lens to set or get the UTxO reference from this UtxoPayload

utxoPayloadValueL :: Lens' UtxoPayload Value Source #

A lens to set or get the value from this UtxoPayload

utxoPayloadDatumL :: Lens' UtxoPayload UtxoPayloadDatum Source #

A lens to set or get the datum from this UtxoPayload

utxoPayloadMReferenceScriptHashL :: Lens' UtxoPayload (Maybe ScriptHash) Source #

A lens to set or get the optional reference script hash from this UtxoPayload

utxoPayloadReferenceScriptHashAT :: AffineTraversal' UtxoPayload ScriptHash Source #

Focusing on the optional reference script hash of a UtxoPayload

newtype UtxoPayloadSet Source #

Represents a set of payloads.

Constructors

UtxoPayloadSet 

Fields

Instances

Instances details
Monoid UtxoPayloadSet Source # 
Instance details

Defined in Cooked.MockChain.State

Semigroup UtxoPayloadSet Source # 
Instance details

Defined in Cooked.MockChain.State

Show UtxoPayloadSet Source # 
Instance details

Defined in Cooked.MockChain.State

PrettyCookedList UtxoPayloadSet Source #

Pretty prints the state of an address, that is the list of UTxOs (including value and datum), grouped

Instance details

Defined in Cooked.Pretty.MockChain

Eq UtxoPayloadSet Source # 
Instance details

Defined in Cooked.MockChain.State

PrettyCooked (Map Address UtxoPayloadSet) Source #

Pretty print a UtxoState. Print the known wallets first, then unknown pubkeys, then scripts.

Instance details

Defined in Cooked.Pretty.MockChain

utxoPayloadSetListI :: Iso' UtxoPayloadSet [UtxoPayload] Source #

Going back and forth between a list of UtxoPayload and a UtxoPayloadSet

data UtxoState where Source #

A description of who owns what in a blockchain. Owners are addresses and they each own a UtxoPayloadSet.

Constructors

UtxoState 

Fields

Instances

Instances details
Monoid UtxoState Source # 
Instance details

Defined in Cooked.MockChain.State

Semigroup UtxoState Source # 
Instance details

Defined in Cooked.MockChain.State

Eq UtxoState Source # 
Instance details

Defined in Cooked.MockChain.State

availableUtxosL :: Lens' UtxoState (Map Address UtxoPayloadSet) Source #

A lens to set or get the available UTxOs from a UtxoState

consumedUtxosL :: Lens' UtxoState (Map Address UtxoPayloadSet) Source #

A lens to set or get the consumed UTxOs from a UtxoState

Querying the assets owned by a given address

holdsInState :: ToAddress a => a -> UtxoState -> Value Source #

Total value accessible to what's pointed by the address.

Transforming a MockChainState into an UtxoState