cardano-api-1.28.0
Safe HaskellNone
LanguageHaskell2010

Cardano.Api.LedgerState

Synopsis

Initialization / Accumulation

data Env Source #

Constructors

Env 

Fields

newtype LedgerState Source #

Constructors

LedgerState 

Fields

Bundled Patterns

pattern LedgerStateByronLedgerState ByronBlock → LedgerState 
pattern LedgerStateShelleyLedgerState (ShelleyBlock (ShelleyEra StandardCrypto)) → LedgerState 
pattern LedgerStateAllegraLedgerState (ShelleyBlock (AllegraEra StandardCrypto)) → LedgerState 
pattern LedgerStateMaryLedgerState (ShelleyBlock (MaryEra StandardCrypto)) → LedgerState 

initialLedgerState Source #

Arguments

FilePath

Path to the cardano-node config file (e.g. to cardano-node projectconfigurationcardano/mainnet-config.json)

ExceptT InitialLedgerStateError IO (Env, LedgerState)

The environment and initial ledger state

Get the environment and initial ledger state.

applyBlock Source #

Arguments

Env

The environment returned by initialLedgerState

LedgerState

The current ledger state

Bool

True to perform validation. If True, tickThenApply will be used instead of tickThenReapply.

Block era

Some block to apply

Either Text LedgerState

The new ledger state (or an error).

Apply a single block to the current ledger state.

Traversing the block chain

foldBlocks Source #

Arguments

∷ ∀ a. FilePath

Path to the cardano-node config file (e.g. to cardano-node projectconfigurationcardano/mainnet-config.json)

FilePath

Path to local cardano-node socket. This is the path specified by the --socket-path command line option when running the node.

Bool

True to enable validation. Under the hood this will use applyBlock instead of reapplyBlock from the ApplyBlock type class.

→ a

The initial accumulator state.

→ (EnvLedgerStateBlockInMode CardanoMode → a → IO a)

Accumulator function Takes: * Environment (this is a constant over the whole fold) * The current Ledger state (with the current block applied) * The current Block * The previous state

And this should return the new state.

Note: This function can safely assume no rollback will occur even though internally this is implemented with a client protocol that may require rollback. This is achieved by only calling the accumulator on states/blocks that are older than the security parameter, k. This has the side effect of truncating the last k blocks before the node's tip.

ExceptT FoldBlocksError IO a

The final state

Monadic fold over all blocks and ledger states. Stopping k blocks before the node's tip where k is the security parameter.

Errors

data InitialLedgerStateError Source #

Constructors

ILSEConfigFile Text

Failed to read or parse the network config file.

ILSEGenesisFile GenesisConfigError

Failed to read or parse a genesis file linked from the network config file.

ILSELedgerConsensusConfig GenesisConfigError

Failed to derive the Ledger or Consensus config.