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

Hydra.Chain.Direct.Handlers

Description

Provide infrastructure-independent "handlers" for posting transactions and following the chain.

This module encapsulates the transformation logic between cardano transactions and HydraNode abstractions PostChainTx and OnChainTx, and maintainance of on-chain relevant state.

Synopsis

Documentation

data LocalChainState m tx Source #

Handle of a mutable local chain state that is kept in the direct chain layer.

Constructors

LocalChainState 

Fields

newLocalChainState :: (MonadSTM m, IsChainState tx) => ChainStateHistory tx -> m (LocalChainState m tx) Source #

Initialize a new local chain state from a given chain state history.

Posting Transactions

type SubmitTx m = Tx -> m () Source #

A callback used to actually submit a transaction to the chain.

type GetTimeHandle m = m TimeHandle Source #

A way to acquire a TimeHandle

mkChain Source #

Arguments

:: (MonadSTM m, MonadThrow (STM m)) 
=> Tracer m DirectChainLog 
-> GetTimeHandle m

Means to acquire a new TimeHandle.

-> TinyWallet m 
-> ChainContext 
-> LocalChainState m Tx 
-> SubmitTx m 
-> Chain Tx m 

Create a Chain component for posting "real" cardano transactions.

This component does not actually interact with a cardano-node, but creates cardano transactions from PostChainTx transactions emitted by a HydraNode, balancing and signing them using given TinyWallet, before handing it off to the given SubmitTx callback. There is also a draftTx option for drafting a commit tx on behalf of the user using their selected utxo.

NOTE: Given the constraints on m this function should work within IOSim and does not require any actual IO to happen which makes it highly suitable for simulations and testing.

finalizeTx :: MonadThrow m => TinyWallet m -> ChainContext -> UTxO -> UTxO -> Tx -> m Tx Source #

Balance and sign the given partial transaction.

Following the Chain

data ChainSyncHandler m Source #

A handler that takes care of following the chain.

Constructors

ChainSyncHandler 

Fields

chainSyncHandler Source #

Arguments

:: forall m. (MonadSTM m, MonadThrow m) 
=> Tracer m DirectChainLog

Tracer for logging

-> ChainCallback Tx m 
-> GetTimeHandle m

Means to acquire a new TimeHandle.

-> ChainContext

Contextual information about our chain connection.

-> LocalChainState m Tx 
-> ChainSyncHandler m

A chain-sync handler to use in a local-chain-sync client.

Creates a ChainSyncHandler that can notify the given callback of events happening on-chain.

This forms the other half of a ChainComponent along with mkChain but is decoupled from actual interactions with the chain.

A TimeHandle is needed to do `SlotNo -> POSIXTime` conversions for Tick events.

Throws TimeConversionException when a received block's SlotNo cannot be converted to a UTCTime with the given TimeHandle.

prepareTxToPost Source #

Arguments

:: (MonadSTM m, MonadThrow (STM m)) 
=> TimeHandle 
-> TinyWallet m 
-> ChainContext 
-> UTxOType Tx

Spendable UTxO

-> PostChainTx Tx 
-> STM m Tx 

maxGraceTime :: NominalDiffTime Source #

Maximum delay we put on the upper bound of transactions to fit into a block. NOTE: This is highly depending on the network. If the security parameter and epoch length result in a short horizon, this is problematic.

data DirectChainLog Source #

Constructors

ToPost 

Fields

PostingTx 

Fields

PostedTx 

Fields

PostingFailed 

Fields

RolledForward 

Fields

RolledBackward 

Fields

Wallet TinyWalletLog 

Instances

Instances details
Arbitrary DirectChainLog Source # 
Instance details

Defined in Hydra.Chain.Direct.Handlers

FromJSON DirectChainLog Source # 
Instance details

Defined in Hydra.Chain.Direct.Handlers

Methods

parseJSON :: Value -> Parser DirectChainLog

parseJSONList :: Value -> Parser [DirectChainLog]

omittedField :: Maybe DirectChainLog

ToJSON DirectChainLog Source # 
Instance details

Defined in Hydra.Chain.Direct.Handlers

Generic DirectChainLog Source # 
Instance details

Defined in Hydra.Chain.Direct.Handlers

Associated Types

type Rep DirectChainLog :: Type -> Type Source #

Show DirectChainLog Source # 
Instance details

Defined in Hydra.Chain.Direct.Handlers

Eq DirectChainLog Source # 
Instance details

Defined in Hydra.Chain.Direct.Handlers

type Rep DirectChainLog Source # 
Instance details

Defined in Hydra.Chain.Direct.Handlers

type Rep DirectChainLog = D1 ('MetaData "DirectChainLog" "Hydra.Chain.Direct.Handlers" "hydra-node-0.20.0-5pXAEiXeWsXH8K4KfwlMxW" 'False) ((C1 ('MetaCons "ToPost" 'PrefixI 'True) (S1 ('MetaSel ('Just "toPost") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PostChainTx Tx))) :+: (C1 ('MetaCons "PostingTx" 'PrefixI 'True) (S1 ('MetaSel ('Just "txId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TxId)) :+: C1 ('MetaCons "PostedTx" 'PrefixI 'True) (S1 ('MetaSel ('Just "txId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TxId)))) :+: ((C1 ('MetaCons "PostingFailed" 'PrefixI 'True) (S1 ('MetaSel ('Just "tx") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Tx) :*: S1 ('MetaSel ('Just "postTxError") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PostTxError Tx))) :+: C1 ('MetaCons "RolledForward" 'PrefixI 'True) (S1 ('MetaSel ('Just "point") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ChainPoint) :*: S1 ('MetaSel ('Just "receivedTxIds") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TxId]))) :+: (C1 ('MetaCons "RolledBackward" 'PrefixI 'True) (S1 ('MetaSel ('Just "point") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ChainPoint)) :+: C1 ('MetaCons "Wallet" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TinyWalletLog)))))