cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.MockChain.Read

Description

This module exposes primitives to query the current state of the blockchain.

Synopsis

The MockChainRead effect

data MockChainRead :: Effect Source #

An effect that offers primitives to query the current state of the mockchain. As its name suggests, this effect is read-only and does not alter the state in any way.

runMockChainRead :: forall effs a. Members '[State MockChainState, Error ToCardanoError, Error MockChainError] effs => Sem (MockChainRead : effs) a -> Sem effs a Source #

The interpretation for read-only effect in the blockchain state

Queries related to protocol parameters

getParams :: Member MockChainRead effs => Sem effs Params Source #

Returns the emulator parameters, including protocol parameters

govActionDeposit :: Member MockChainRead effs => Sem effs Lovelace Source #

Retrieves the required governance action deposit amount

dRepDeposit :: Member MockChainRead effs => Sem effs Lovelace Source #

Retrieves the required drep deposit amount

stakeAddressDeposit :: Member MockChainRead effs => Sem effs Lovelace Source #

Retrieves the required stake address deposit amount

stakePoolDeposit :: Member MockChainRead effs => Sem effs Lovelace Source #

Retrieves the required stake pool deposit amount

Queries related to TxSkel

txSkelDepositedValueInCertificates :: Member MockChainRead effs => TxSkel -> Sem effs Lovelace Source #

Retrieves the total amount of lovelace deposited in certificates in this skeleton. Note that unregistering a staking address or a dRep lead to a negative deposit (a withdrawal, in fact) which means this function can return a negative amount of lovelace, which is intended. The deposited amounts are dictated by the current protocol parameters, and computed as such.

txSkelDepositedValueInProposals :: Member MockChainRead effs => TxSkel -> Sem effs Lovelace Source #

Retrieves the total amount of lovelace deposited in proposals in this skeleton (equal to govActionDeposit times the number of proposals)

txSkelAllScripts :: Member MockChainRead effs => TxSkel -> Sem effs [VScript] Source #

Returns all scripts involved in this TxSkel

txSkelInputScripts :: Member MockChainRead effs => TxSkel -> Sem effs [VScript] Source #

Returns all scripts which guard transaction inputs

txSkelInputValue :: Member MockChainRead effs => TxSkel -> Sem effs Value Source #

look up the UTxOs the transaction consumes, and sum their values.

Queries related to timing

currentSlot :: Member MockChainRead effs => Sem effs Slot Source #

Returns the current slot

currentMSRange :: Members '[MockChainRead, Fail] effs => Sem effs (POSIXTime, POSIXTime) Source #

Returns the closed ms interval corresponding to the current slot

getEnclosingSlot :: Member MockChainRead effs => POSIXTime -> Sem effs Slot Source #

Return the slot that contains the given time. See slotToMSRange for some satisfied equational properties.

slotRangeBefore :: Members '[MockChainRead, Fail] effs => POSIXTime -> Sem effs SlotRange Source #

The infinite range of slots ending before or at the given time

slotRangeAfter :: Members '[MockChainRead, Fail] effs => POSIXTime -> Sem effs SlotRange Source #

The infinite range of slots starting after or at the given time

slotToMSRange :: (Members '[MockChainRead, Fail] effs, Integral i) => i -> Sem effs (POSIXTime, POSIXTime) Source #

Returns the closed ms interval corresponding to the slot with the given number. It holds that

slotToMSRange (getEnclosingSlot t) == (a, b)    ==>   a <= t <= b

and

slotToMSRange n == (a, b)   ==>   getEnclosingSlot a == n && getEnclosingSlot b == n

and

slotToMSRange n == (a, b)   ==>   getEnclosingSlot (a-1) == n-1 && getEnclosingSlot (b+1) == n+1

Queries related to fetching UTxOs

allUtxos :: Member MockChainRead effs => Sem effs Utxos Source #

Returns a list of all currently known outputs

utxosAt :: (Member MockChainRead effs, ToCredential cred) => cred -> Sem effs Utxos Source #

Returns a list of all UTxOs at a certain address.

txSkelOutByRef :: Member MockChainRead effs => TxOutRef -> Sem effs TxSkelOut Source #

Returns an output given a reference to it

utxosFromCardanoTx :: Member MockChainRead effs => CardanoTx -> Sem effs [(TxOutRef, TxSkelOut)] Source #

Retrieves the ordered list of outputs of the given CardanoTx.

This is useful when writing endpoints and/or traces to fetch utxos of interest right from the start and avoid querying the chain for them afterwards using allUtxos or similar functions.

lookupUtxos :: Member MockChainRead effs => [TxOutRef] -> Sem effs (Map TxOutRef TxSkelOut) Source #

Go through all of the TxOutRefs in the list and look them up in the state of the blockchain, throwing an error if one of them cannot be resolved.

previewByRef :: (Member MockChainRead effs, Is af An_AffineFold) => Optic' af is TxSkelOut c -> TxOutRef -> Sem effs (Maybe c) Source #

Retrieves an output and previews a specific element out of it

viewByRef :: (Member MockChainRead effs, Is g A_Getter) => Optic' g is TxSkelOut c -> TxOutRef -> Sem effs c Source #

Retrieves an output and views a specific element out of it

Other queries

getConstitutionScript :: Member MockChainRead effs => Sem effs (Maybe VScript) Source #

Gets the current official constitution script

getCurrentReward :: (Member MockChainRead effs, ToCredential c) => c -> Sem effs (Maybe Lovelace) Source #

Gets the current reward associated with a credential