Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- data QueryException
- = QueryAcquireException AcquiringFailure
- | QueryEraMismatchException EraMismatch
- | QueryProtocolParamsConversionException ProtocolParametersConversionError
- data CardanoClient = CardanoClient {
- queryUTxOByAddress :: [Address ShelleyAddr] -> IO UTxO
- networkId :: NetworkId
- mkCardanoClient :: NetworkId -> SocketPath -> CardanoClient
- buildTransaction :: NetworkId -> SocketPath -> AddressInEra -> UTxO -> [TxIn] -> [TxOut CtxTx] -> IO (Either TxBodyErrorAutoBalance TxBody)
- submitTransaction :: NetworkId -> SocketPath -> Tx -> IO ()
- data SubmitTransactionException
- = SubmitEraMismatch EraMismatch
- | SubmitTxValidationError (TxValidationErrorInMode CardanoMode)
- awaitTransaction :: NetworkId -> SocketPath -> Tx -> IO UTxO
- data QueryPoint
- queryTip :: NetworkId -> SocketPath -> IO ChainPoint
- queryTipSlotNo :: NetworkId -> SocketPath -> IO SlotNo
- querySystemStart :: NetworkId -> SocketPath -> QueryPoint -> IO SystemStart
- queryEraHistory :: NetworkId -> SocketPath -> QueryPoint -> IO (EraHistory CardanoMode)
- queryProtocolParameters :: NetworkId -> SocketPath -> QueryPoint -> IO BundledProtocolParameters
- queryGenesisParameters :: NetworkId -> SocketPath -> QueryPoint -> IO GenesisParameters
- queryUTxO :: NetworkId -> SocketPath -> QueryPoint -> [Address ShelleyAddr] -> IO UTxO
- queryUTxOByTxIn :: NetworkId -> SocketPath -> QueryPoint -> [TxIn] -> IO UTxO
- queryUTxOWhole :: NetworkId -> SocketPath -> QueryPoint -> IO UTxO
- queryUTxOFor :: NetworkId -> SocketPath -> QueryPoint -> VerificationKey PaymentKey -> IO UTxO
- queryStakePools :: NetworkId -> SocketPath -> QueryPoint -> IO (Set PoolId)
- runQuery :: NetworkId -> SocketPath -> QueryPoint -> QueryInMode CardanoMode a -> IO a
- throwOnEraMismatch :: MonadThrow m => Either EraMismatch a -> m a
- localNodeConnectInfo :: NetworkId -> SocketPath -> LocalNodeConnectInfo CardanoMode
- cardanoModeParams :: ConsensusModeParams CardanoMode
Documentation
data QueryException Source #
Constructors
QueryAcquireException AcquiringFailure | |
QueryEraMismatchException EraMismatch | |
QueryProtocolParamsConversionException ProtocolParametersConversionError |
Instances
Exception QueryException Source # | |
Defined in Hydra.Chain.CardanoClient Methods toException :: QueryException -> SomeException Source # fromException :: SomeException -> Maybe QueryException Source # | |
Show QueryException Source # | |
Defined in Hydra.Chain.CardanoClient | |
Eq QueryException Source # | |
Defined in Hydra.Chain.CardanoClient Methods (==) :: QueryException -> QueryException -> Bool Source # (/=) :: QueryException -> QueryException -> Bool Source # |
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
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 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
.
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 (TxValidationErrorInMode CardanoMode) |
Instances
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.
Instances
Arbitrary QueryPoint Source # | |
Defined in Hydra.Chain.CardanoClient | |
ToJSON QueryPoint Source # | |
Defined in Hydra.Chain.CardanoClient Methods toJSON :: QueryPoint -> Value toEncoding :: QueryPoint -> Encoding toJSONList :: [QueryPoint] -> Value toEncodingList :: [QueryPoint] -> Encoding | |
Generic QueryPoint Source # | |
Defined in Hydra.Chain.CardanoClient | |
Show QueryPoint Source # | |
Defined in Hydra.Chain.CardanoClient | |
Eq QueryPoint Source # | |
Defined in Hydra.Chain.CardanoClient Methods (==) :: QueryPoint -> QueryPoint -> Bool Source # (/=) :: QueryPoint -> QueryPoint -> Bool Source # | |
type Rep QueryPoint Source # | |
Defined in Hydra.Chain.CardanoClient type Rep QueryPoint = D1 ('MetaData "QueryPoint" "Hydra.Chain.CardanoClient" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" '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 CardanoMode) Source #
Query the era history at given point.
Throws at least QueryException
if query fails.
queryProtocolParameters :: NetworkId -> SocketPath -> QueryPoint -> IO BundledProtocolParameters Source #
Query the protocol parameters at given point.
Throws at least QueryException
if query fails.
queryGenesisParameters :: NetworkId -> SocketPath -> QueryPoint -> IO GenesisParameters Source #
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.
queryUTxOByTxIn :: NetworkId -> SocketPath -> QueryPoint -> [TxIn] -> IO UTxO Source #
Query UTxO for given tx inputs at given point.
Throws at least QueryException
if query fails.
queryUTxOWhole :: NetworkId -> SocketPath -> QueryPoint -> IO UTxO Source #
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 :: NetworkId -> SocketPath -> QueryPoint -> IO (Set PoolId) Source #
Query the current set of registered stake pools.
Throws at least QueryException
if query fails.
runQuery :: NetworkId -> SocketPath -> QueryPoint -> QueryInMode CardanoMode a -> IO a Source #
Throws at least QueryException
if query fails.
Helpers
throwOnEraMismatch :: MonadThrow m => Either EraMismatch a -> m a Source #
localNodeConnectInfo :: NetworkId -> SocketPath -> LocalNodeConnectInfo CardanoMode Source #
cardanoModeParams :: ConsensusModeParams CardanoMode Source #