hydra-node-0.19.0: The Hydra node
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.Chain.CardanoClient

Description

A basic cardano-node client that can talk to a local cardano-node.

The idea of this module is to provide a Haskell interface on top of cardano-cli's API, using cardano-api types.

Synopsis

Documentation

CardanoClient handle

data CardanoClient Source #

Handle interface for abstract querying of a cardano node.

Constructors

CardanoClient 

Fields

mkCardanoClient :: NetworkId -> SocketPath -> CardanoClient Source #

Construct a CardanoClient handle.

Tx Construction / Submission

buildTransaction Source #

Arguments

:: NetworkId

Current network identifier

-> SocketPath

Filepath to the cardano-node's domain socket

-> AddressInEra

Change address to send

-> UTxO

Unspent transaction outputs to spend.

-> [TxIn]

Collateral inputs.

-> [TxOut CtxTx]

Outputs to create.

-> IO (Either (TxBodyErrorAutoBalance Era) TxBody) 

Construct a simple payment consuming some inputs and producing some outputs (no certificates or withdrawals involved).

On success, the returned transaction is fully balanced. On error, return TxBodyErrorAutoBalance.

submitTransaction Source #

Arguments

:: NetworkId

Current network discriminant

-> SocketPath

Filepath to the cardano-node's domain socket

-> Tx

A signed transaction.

-> IO () 

Submit a (signed) transaction to the node.

Throws SubmitTransactionException if submission fails.

data SubmitTransactionException Source #

Exceptions that can occur during a transaction submission.

In principle, we can only encounter an EraMismatch at era boundaries, when we try to submit a "next era" transaction as a "current era" transaction, or vice-versa. Similarly, TxValidationError shouldn't occur given that the transaction was safely constructed through buildTransaction.

Constructors

SubmitEraMismatch EraMismatch 
SubmitTxValidationError TxValidationErrorInCardanoMode 

awaitTransaction Source #

Arguments

:: NetworkId

Current network discriminant

-> SocketPath

Filepath to the cardano-node's domain socket

-> Tx

The transaction to watch / await

-> IO UTxO 

Await until the given transaction is visible on-chain. Returns the UTxO set produced by that transaction.

Note that this function loops forever; hence, one probably wants to couple it with a surrounding timeout.

Local state query

data QueryPoint Source #

Describes whether to query at the tip or at a specific point.

Constructors

QueryTip 
QueryAt ChainPoint 

Instances

Instances details
Arbitrary QueryPoint Source # 
Instance details

Defined in Hydra.Chain.CardanoClient

ToJSON QueryPoint Source # 
Instance details

Defined in Hydra.Chain.CardanoClient

Methods

toJSON :: QueryPoint -> Value

toEncoding :: QueryPoint -> Encoding

toJSONList :: [QueryPoint] -> Value

toEncodingList :: [QueryPoint] -> Encoding

omitField :: QueryPoint -> Bool

Generic QueryPoint Source # 
Instance details

Defined in Hydra.Chain.CardanoClient

Associated Types

type Rep QueryPoint :: Type -> Type Source #

Show QueryPoint Source # 
Instance details

Defined in Hydra.Chain.CardanoClient

Eq QueryPoint Source # 
Instance details

Defined in Hydra.Chain.CardanoClient

type Rep QueryPoint Source # 
Instance details

Defined in Hydra.Chain.CardanoClient

type Rep QueryPoint = D1 ('MetaData "QueryPoint" "Hydra.Chain.CardanoClient" "hydra-node-0.19.0-6Z4E5vp1s1XJuLOmmEVMTw" 'False) (C1 ('MetaCons "QueryTip" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "QueryAt" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ChainPoint)))

queryTip :: NetworkId -> SocketPath -> IO ChainPoint Source #

Query the latest chain point aka "the tip".

queryTipSlotNo :: NetworkId -> SocketPath -> IO SlotNo Source #

Query the latest chain point just for the slot number.

querySystemStart :: NetworkId -> SocketPath -> QueryPoint -> IO SystemStart Source #

Query the system start parameter at given point.

Throws at least QueryException if query fails.

queryEraHistory :: NetworkId -> SocketPath -> QueryPoint -> IO EraHistory Source #

Query the era history at given point.

Throws at least QueryException if query fails.

queryEpochNo :: NetworkId -> SocketPath -> QueryPoint -> IO EpochNo Source #

Query the current epoch number.

Throws at least QueryException if query fails.

queryProtocolParameters Source #

Arguments

:: NetworkId

Current network discriminant

-> SocketPath

Filepath to the cardano-node's domain socket

-> QueryPoint 
-> IO (PParams LedgerEra) 

Query the protocol parameters at given point and convert them to Babbage era protocol parameters.

Throws at least QueryException if query fails.

queryProtocolParameters' Source #

Arguments

:: IsShelleyBasedEra era 
=> NetworkId

Current network discriminant

-> SocketPath

Filepath to the cardano-node's domain socket

-> QueryPoint 
-> IO (PParams (ShelleyLedgerEra era)) 

Query the protocol parameters at given point. NOTE: If the era is not matching this fails with an era mismatch.

Throws at least QueryException if query fails.

queryGenesisParameters Source #

Arguments

:: NetworkId

Current network discriminant

-> SocketPath

Filepath to the cardano-node's domain socket

-> QueryPoint 
-> IO (GenesisParameters ShelleyEra) 

Query GenesisParameters at a given point.

Throws at least QueryException if query fails.

queryUTxO :: NetworkId -> SocketPath -> QueryPoint -> [Address ShelleyAddr] -> IO UTxO Source #

Query UTxO for all given addresses at given point.

Throws at least QueryException if query fails.

queryUTxOExpr :: ShelleyBasedEra era -> [Address ShelleyAddr] -> LocalStateQueryExpr b p QueryInMode r IO UTxO Source #

queryUTxOByTxIn Source #

Arguments

:: NetworkId

Current network discriminant

-> SocketPath

Filepath to the cardano-node's domain socket

-> QueryPoint 
-> [TxIn] 
-> IO UTxO 

Query UTxO for given tx inputs at given point.

Throws at least QueryException if query fails.

assumeShelleyBasedEraOrThrow :: MonadThrow m => CardanoEra era -> m (ShelleyBasedEra era) Source #

queryUTxOWhole Source #

Arguments

:: NetworkId

Current network discriminant

-> SocketPath

Filepath to the cardano-node's domain socket

-> QueryPoint 
-> IO UTxO 

Query the whole UTxO from node at given point. Useful for debugging, but should obviously not be used in production code.

Throws at least QueryException if query fails.

queryUTxOFor :: NetworkId -> SocketPath -> QueryPoint -> VerificationKey PaymentKey -> IO UTxO Source #

Query UTxO for the address of given verification key at point.

Throws at least QueryException if query fails.

queryStakePools Source #

Arguments

:: NetworkId

Current network discriminant

-> SocketPath

Filepath to the cardano-node's domain socket

-> QueryPoint 
-> IO (Set PoolId) 

Query the current set of registered stake pools.

Throws at least QueryException if query fails.

Helpers

queryCurrentEraExpr :: LocalStateQueryExpr b p QueryInMode r IO AnyCardanoEra Source #

Monadic query expression to get current era.

queryInShelleyBasedEraExpr Source #

Arguments

:: ShelleyBasedEra era

The current running era we can use to query the node

-> QueryInShelleyBasedEra era a 
-> LocalStateQueryExpr b p QueryInMode r IO a 

Monadic query expression for a QueryInShelleyBasedEra.

runQuery :: NetworkId -> SocketPath -> QueryPoint -> QueryInMode a -> IO a Source #

Throws at least QueryException if query fails.

runQueryExpr :: NetworkId -> SocketPath -> QueryPoint -> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a -> IO a Source #

Throws at least QueryException if query fails.

throwOnEraMismatch :: MonadThrow m => Either EraMismatch a -> m a Source #

throwOnUnsupportedNtcVersion :: MonadThrow m => Either UnsupportedNtcVersionError a -> m a Source #

localNodeConnectInfo :: NetworkId -> SocketPath -> LocalNodeConnectInfo Source #

cardanoModeParams :: ConsensusModeParams Source #