Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Specifies the Head-Chain Interaction part of the protocol
Incoming and outgoing on-chain transactions are modelled respectively as OnChainTx
and PostChainTx
which are data type that abstracts away the details of the structure
of the transaction.
Synopsis
- maxMainnetLovelace :: Coin
- maximumNumberOfParties :: Int
- data HeadParameters = HeadParameters {}
- mkHeadParameters :: Environment -> HeadParameters
- data PostChainTx tx
- = InitTx { }
- | AbortTx { }
- | CollectComTx {
- utxo :: UTxOType tx
- headId :: HeadId
- headParameters :: HeadParameters
- | CloseTx { }
- | ContestTx { }
- | FanoutTx { }
- data OnChainTx tx
- = OnInitTx { }
- | OnCommitTx { }
- | OnAbortTx { }
- | OnCollectComTx { }
- | OnCloseTx { }
- | OnContestTx { }
- | OnFanoutTx { }
- data PostTxError tx
- = NoSeedInput
- | InvalidSeed { }
- | InvalidHeadId { }
- | CannotFindOwnInitial { }
- | UnsupportedLegacyOutput {
- byronAddress :: Address ByronAddr
- | CannotCommitReferenceScript
- | InvalidStateToPost {
- txTried :: PostChainTx tx
- chainState :: ChainStateType tx
- | NotEnoughFuel
- | NoFuelUTXOFound
- | ScriptFailedInWallet {
- redeemerPtr :: Text
- failureReason :: Text
- | InternalWalletError { }
- | FailedToPostTx { }
- | PlutusValidationFailed { }
- | CommittedTooMuchADAForMainnet {
- userCommittedLovelace :: Coin
- mainnetLimitLovelace :: Coin
- | FailedToDraftTxNotInitializing
- | SpendingNodeUtxoForbidden
- | FailedToConstructAbortTx
- | FailedToConstructCloseTx
- | FailedToConstructContestTx
- | FailedToConstructCollectTx
- | FailedToConstructFanoutTx
- data ChainStateHistory tx = UnsafeChainStateHistory {
- history :: NonEmpty (ChainStateType tx)
- defaultChainState :: ChainStateType tx
- currentState :: ChainStateHistory tx -> ChainStateType tx
- pushNewState :: ChainStateType tx -> ChainStateHistory tx -> ChainStateHistory tx
- initHistory :: ChainStateType tx -> ChainStateHistory tx
- rollbackHistory :: IsChainState tx => ChainSlot -> ChainStateHistory tx -> ChainStateHistory tx
- class (IsTx tx, Eq (ChainStateType tx), Show (ChainStateType tx), Arbitrary (ChainStateType tx), FromJSON (ChainStateType tx), ToJSON (ChainStateType tx)) => IsChainState tx where
- type ChainStateType tx = c | c -> tx
- chainStateSlot :: ChainStateType tx -> ChainSlot
- data Chain tx m = Chain {
- postTx :: MonadThrow m => PostChainTx tx -> m ()
- draftCommitTx :: MonadThrow m => HeadId -> UTxO' (TxOut CtxUTxO, Witness WitCtxTxIn) -> m (Either (PostTxError Tx) Tx)
- submitTx :: MonadThrow m => Tx -> m ()
- data ChainEvent tx
- = Observation {
- observedTx :: OnChainTx tx
- newChainState :: ChainStateType tx
- | Rollback { }
- | Tick { }
- | PostTxError {
- postChainTx :: PostChainTx tx
- postTxError :: PostTxError tx
- = Observation {
- type ChainCallback tx m = ChainEvent tx -> m ()
- type ChainComponent tx m a = ChainCallback tx m -> (Chain tx m -> m a) -> m a
Documentation
maxMainnetLovelace :: Coin Source #
Hardcoded limit for commit tx on mainnet
maximumNumberOfParties :: Int Source #
Hardcoded limit for maximum number of parties in a head protocol
The value is obtained from calculating the costs of running the scripts
and on-chan validators (see computeCollectComCost
computeAbortCost
)
data HeadParameters Source #
Contains the head's parameters as established in the initial transaction.
Instances
mkHeadParameters :: Environment -> HeadParameters Source #
Make HeadParameters
that are consistent with the given Environment
.
data PostChainTx tx Source #
Data type used to post transactions on chain. It holds everything to construct corresponding Head protocol transactions.
InitTx | |
AbortTx | |
CollectComTx | |
| |
CloseTx | |
ContestTx | |
FanoutTx | |
Instances
Describes transactions as seen on chain. Holds as minimal information as possible to simplify observing the chain.
OnInitTx | |
| |
OnCommitTx | |
OnAbortTx | |
OnCollectComTx | |
OnCloseTx | |
OnContestTx | |
OnFanoutTx | |
Instances
data PostTxError tx Source #
Exceptions thrown by $sel:postTx:Chain
.
NoSeedInput | |
InvalidSeed | |
InvalidHeadId | |
CannotFindOwnInitial | |
UnsupportedLegacyOutput | Comitting byron addresses is not supported. |
| |
CannotCommitReferenceScript | Comitting reference scripts is not supported right now. |
InvalidStateToPost | |
| |
NotEnoughFuel | |
NoFuelUTXOFound | |
ScriptFailedInWallet | Script execution failed when finalizing a transaction in the wallet.
XXX: Ideally we want a cardano-api type with corresonding JSON instance
here. But the wallet still uses ledger types and we don't want to copy the
conversion from ledger |
| |
InternalWalletError | A generic error happened when finalizing a transction in the wallet. |
FailedToPostTx | An error occurred when submitting a transaction to the cardano-node. |
PlutusValidationFailed | A plutus script failed in a transaction submitted to the cardano-node. NOTE: PlutusDebugInfo does not have much available instances so we put it in Text form but it's lame |
| |
CommittedTooMuchADAForMainnet | User tried to commit more than |
| |
FailedToDraftTxNotInitializing | We can only draft commit tx for the user when in Initializing state |
SpendingNodeUtxoForbidden | Committing UTxO addressed to the internal wallet is forbidden. |
FailedToConstructAbortTx | |
FailedToConstructCloseTx | |
FailedToConstructContestTx | |
FailedToConstructCollectTx | |
FailedToConstructFanoutTx |
Instances
data ChainStateHistory tx Source #
A non empty sequence of chain states that can be rolled back.
This is expected to be constructed by using the smart constructor
initHistory
.
UnsafeChainStateHistory | |
|
Instances
currentState :: ChainStateHistory tx -> ChainStateType tx Source #
pushNewState :: ChainStateType tx -> ChainStateHistory tx -> ChainStateHistory tx Source #
initHistory :: ChainStateType tx -> ChainStateHistory tx Source #
rollbackHistory :: IsChainState tx => ChainSlot -> ChainStateHistory tx -> ChainStateHistory tx Source #
class (IsTx tx, Eq (ChainStateType tx), Show (ChainStateType tx), Arbitrary (ChainStateType tx), FromJSON (ChainStateType tx), ToJSON (ChainStateType tx)) => IsChainState tx where Source #
Types that can be used on-chain by the Hydra protocol. XXX: Find a better name for this. Maybe IsChainTx or IsL1Tx?
type ChainStateType tx = c | c -> tx Source #
Types of what to keep as L1 chain state.
chainStateSlot :: ChainStateType tx -> ChainSlot Source #
Get the chain slot for a chain state. NOTE: For any sequence of a
encountered, we assume monotonically increasing slots.
Instances
IsChainState Tx Source # | |
Defined in Hydra.Chain.Direct.State type ChainStateType Tx = (c :: Type) Source # | |
IsChainState SimpleTx Source # | |
Defined in Hydra.Ledger.Simple type ChainStateType SimpleTx = (c :: Type) Source # |
Handle to interface with the main chain network
Chain | |
|
data ChainEvent tx Source #
Observation | Indicates a head protocol transaction has been observed. |
| |
Rollback | |
Tick | Indicate time has advanced on the chain. NOTE: While the type does not guarantee that the UTCTime and ChainSlot are consistent the alternative would be provide the means to do the conversion. For Cardano, this would be a systemStart and eraHistory.. which is annoying and if it's kept in the chain layer, it would mean another round trip / state to keep there. |
PostTxError | Event to re-ingest errors from |
|
Instances
type ChainCallback tx m = ChainEvent tx -> m () Source #
A callback indicating a 'ChainEvent tx' happened. Most importantly the
Observation
of a relevant Hydra transaction.
type ChainComponent tx m a = ChainCallback tx m -> (Chain tx m -> m a) -> m a Source #
A type tying both posting and observing transactions into a single Component.