| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
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
- data LocalChainState m tx = LocalChainState {
- getLatest :: STM m (ChainStateType tx)
- pushNew :: ChainStateType tx -> STM m ()
- rollback :: ChainSlot -> STM m (ChainStateType tx)
- history :: STM m (ChainStateHistory tx)
- newLocalChainState :: (MonadSTM m, IsChainState tx) => ChainStateHistory tx -> m (LocalChainState m tx)
- type SubmitTx m = Tx -> m ()
- type GetTimeHandle m = m TimeHandle
- mkChain :: (MonadSTM m, MonadThrow (STM m)) => Tracer m DirectChainLog -> GetTimeHandle m -> TinyWallet m -> ChainContext -> LocalChainState m Tx -> SubmitTx m -> Chain Tx m
- finalizeTx :: MonadThrow m => TinyWallet m -> ChainContext -> UTxO -> UTxO -> Tx -> m Tx
- data ChainSyncHandler m = ChainSyncHandler {
- onRollForward :: BlockHeader -> [Tx] -> m ()
- onRollBackward :: ChainPoint -> m ()
- data TimeConversionException = TimeConversionException {}
- chainSyncHandler :: forall m. (MonadSTM m, MonadThrow m) => Tracer m DirectChainLog -> ChainCallback Tx m -> GetTimeHandle m -> ChainContext -> LocalChainState m Tx -> ChainSyncHandler m
- convertObservation :: HeadObservation -> Maybe (OnChainTx Tx)
- prepareTxToPost :: (MonadSTM m, MonadThrow (STM m)) => TimeHandle -> TinyWallet m -> ChainContext -> UTxOType Tx -> PostChainTx Tx -> STM m Tx
- maxGraceTime :: NominalDiffTime
- data DirectChainLog
- = ToPost {
- toPost :: PostChainTx Tx
- | PostingTx {
- txId :: TxId
- | PostedTx {
- txId :: TxId
- | PostingFailed {
- tx :: Tx
- postTxError :: PostTxError Tx
- | RolledForward {
- point :: ChainPoint
- receivedTxIds :: [TxId]
- | RolledBackward {
- point :: ChainPoint
- | Wallet TinyWalletLog
- = ToPost {
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 GetTimeHandle m = m TimeHandle Source #
A way to acquire a TimeHandle
Arguments
| :: (MonadSTM m, MonadThrow (STM m)) | |
| => Tracer m DirectChainLog | |
| -> GetTimeHandle m | Means to acquire a new |
| -> 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
| |
data TimeConversionException Source #
Conversion of a slot number to a time failed. This can be usually be considered an internal error and may be happening because the used era history is too old.
Constructors
| TimeConversionException | |
Instances
| Exception TimeConversionException Source # | |
Defined in Hydra.Chain.Direct.Handlers | |
| Show TimeConversionException Source # | |
Defined in Hydra.Chain.Direct.Handlers | |
| Eq TimeConversionException Source # | |
Defined in Hydra.Chain.Direct.Handlers Methods (==) :: TimeConversionException -> TimeConversionException -> Bool Source # (/=) :: TimeConversionException -> TimeConversionException -> Bool Source # | |
Arguments
| :: forall m. (MonadSTM m, MonadThrow m) | |
| => Tracer m DirectChainLog | Tracer for logging |
| -> ChainCallback Tx m | |
| -> GetTimeHandle m | Means to acquire a new |
| -> 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.
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 | |