cardano-api-1.30.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 
pattern LedgerStateAlonzoLedgerState (ShelleyBlock (AlonzoEra 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

ValidationMode 
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.

data ValidationMode Source #

How to do validation when applying a block to a ledger state.

Constructors

FullValidation

Do all validation implied by the ledger layer's applyBlock.

QuickValidation

Only check that the previous hash from the block matches the head hash of the ledger state.

applyBlockWithEvents Source #

Arguments

Env 
LedgerState 
Bool

True to validate

→ HardForkBlock (CardanoEras StandardCrypto) 
Either Text LedgerStateEvents 

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.

ValidationMode 
→ a

The initial accumulator state.

→ (EnvLedgerStateBlockInMode CardanoMode → a → IO a)

Accumulator function Takes:

  • Environment (this is a constant over the whole fold).
  • The Ledger state (with block i applied) at block i.
  • Block i.
  • The accumulator state at block i - 1.

And returns:

  • The accumulator state at block i

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.

chainSyncClientWithLedgerState Source #

Arguments

∷ ∀ m a. Monad m 
Env 
LedgerState

Initial ledger state

ValidationMode 
ChainSyncClient (BlockInMode CardanoMode, Either Text LedgerState) ChainPoint ChainTip m a

A client to wrap. The block is annotated with a 'Either Text LedgerState'. This is either an error from validating a block or the current LedgerState from applying the current block. If we trust the node, then we generally expect blocks to validate. Also note that after a block fails to validate we may still roll back to a validated block, in which case the valid LedgerState will be passed here again.

ChainSyncClient (BlockInMode CardanoMode) ChainPoint ChainTip m a

A client that acts just like the wrapped client but doesn't require the LedgerState annotation on the block type.

Wrap a ChainSyncClient with logic that tracks the ledger state.

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.