bcc-api-1.99.0
Safe HaskellNone
LanguageHaskell2010

Bcc.Api.LedgerState

Synopsis

Initialization / Accumulation

data Env Source #

Constructors

Env 

Fields

newtype LedgerState Source #

Constructors

LedgerState 

Fields

Bundled Patterns

pattern LedgerStateColeLedgerState ColeBlock → LedgerState 
pattern LedgerStateSophieLedgerState (SophieBlock (SophieEra StandardCrypto)) → LedgerState 
pattern LedgerStateEvieLedgerState (SophieBlock (EvieEra StandardCrypto)) → LedgerState 
pattern LedgerStateJenLedgerState (SophieBlock (JenEra StandardCrypto)) → LedgerState 

initialLedgerState Source #

Arguments

FilePath

Path to the bcc-node config file (e.g. to bcc-node projectconfigurationbcc/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 (BccEras StandardCrypto) 
Either Text LedgerStateEvents 

Traversing the block chain

foldBlocks Source #

Arguments

∷ ∀ a. FilePath

Path to the bcc-node config file (e.g. to bcc-node projectconfigurationbcc/mainnet-config.json)

ConsensusModeParams BccMode

This is needed for the number of slots per epoch for the Cole era (on mainnet that should be 21600).

FilePath

Path to local bcc-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 BccMode → 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 BccMode, 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 BccMode) 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.