Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Smart constructors for creating Hydra protocol transactions to be used in
the Direct
way of talking to the main-chain.
This module also encapsulates the transaction format used when talking to the
cardano-node, which is currently different from the Cardano
,
thus we have not yet "reached" isomorphism
.
Synopsis
- type UTxOWithScript = (TxIn, TxOut CtxUTxO, HashableScriptData)
- newtype UTxOHash = UTxOHash ByteString
- data InitialThreadOutput = InitialThreadOutput {
- initialThreadUTxO :: (TxIn, TxOut CtxUTxO)
- initialContestationPeriod :: ContestationPeriod
- initialParties :: [Party]
- data OpenThreadOutput = OpenThreadOutput {
- openThreadUTxO :: (TxIn, TxOut CtxUTxO)
- openContestationPeriod :: ContestationPeriod
- openParties :: [Party]
- data ClosedThreadOutput = ClosedThreadOutput {
- closedThreadUTxO :: (TxIn, TxOut CtxUTxO)
- closedParties :: [Party]
- closedContestationDeadline :: POSIXTime
- closedContesters :: [PubKeyHash]
- hydraHeadV1AssetName :: AssetName
- hydraMetadataLabel :: Word64
- mkHydraHeadV1TxName :: Text -> TxMetadata
- getHydraHeadV1TxName :: Tx -> Maybe Text
- initTx :: NetworkId -> TxIn -> [OnChainId] -> HeadParameters -> Tx
- mkHeadOutput :: NetworkId -> PolicyId -> TxOutDatum ctx -> TxOut ctx
- mkHeadOutputInitial :: NetworkId -> TxIn -> HeadParameters -> TxOut CtxTx
- mkInitialOutput :: NetworkId -> TxIn -> OnChainId -> TxOut CtxTx
- commitTx :: NetworkId -> ScriptRegistry -> HeadId -> Party -> UTxO' (TxOut CtxUTxO, Witness WitCtxTxIn) -> (TxIn, TxOut CtxUTxO, Hash PaymentKey) -> Tx
- mkCommitDatum :: Party -> UTxO -> CurrencySymbol -> Datum
- collectComTx :: NetworkId -> ScriptRegistry -> VerificationKey PaymentKey -> HeadId -> HeadParameters -> (TxIn, TxOut CtxUTxO) -> Map TxIn (TxOut CtxUTxO) -> UTxO -> Tx
- data ClosingSnapshot
- data CloseTxError
- closeTx :: ScriptRegistry -> VerificationKey PaymentKey -> ClosingSnapshot -> SlotNo -> PointInTime -> OpenThreadOutput -> HeadId -> Tx
- data ContestTxError
- contestTx :: ScriptRegistry -> VerificationKey PaymentKey -> Snapshot Tx -> MultiSignature (Snapshot Tx) -> PointInTime -> ClosedThreadOutput -> HeadId -> ContestationPeriod -> Tx
- data FanoutTxError
- fanoutTx :: ScriptRegistry -> UTxO -> (TxIn, TxOut CtxUTxO) -> SlotNo -> PlutusScript -> Tx
- data AbortTxError
- abortTx :: UTxO -> ScriptRegistry -> VerificationKey PaymentKey -> (TxIn, TxOut CtxUTxO) -> PlutusScript -> Map TxIn (TxOut CtxUTxO) -> Map TxIn (TxOut CtxUTxO) -> Either AbortTxError Tx
- data HeadObservation
- observeHeadTx :: NetworkId -> UTxO -> Tx -> HeadObservation
- data InitObservation = InitObservation {
- initialThreadUTxO :: (TxIn, TxOut CtxUTxO)
- initials :: [(TxIn, TxOut CtxUTxO)]
- headId :: HeadId
- seedTxIn :: TxIn
- contestationPeriod :: ContestationPeriod
- parties :: [Party]
- participants :: [OnChainId]
- data NotAnInitReason
- observeInitTx :: Tx -> Either NotAnInitReason InitObservation
- data CommitObservation = CommitObservation {}
- observeCommitTx :: NetworkId -> UTxO -> Tx -> Maybe CommitObservation
- data CollectComObservation = CollectComObservation {}
- observeCollectComTx :: UTxO -> Tx -> Maybe CollectComObservation
- data CloseObservation = CloseObservation {}
- observeCloseTx :: UTxO -> Tx -> Maybe CloseObservation
- data ContestObservation = ContestObservation {
- contestedThreadOutput :: (TxIn, TxOut CtxUTxO)
- headId :: HeadId
- snapshotNumber :: SnapshotNumber
- contestationDeadline :: UTCTime
- contesters :: [PubKeyHash]
- observeContestTx :: UTxO -> Tx -> Maybe ContestObservation
- newtype FanoutObservation = FanoutObservation {}
- observeFanoutTx :: UTxO -> Tx -> Maybe FanoutObservation
- newtype AbortObservation = AbortObservation {}
- observeAbortTx :: UTxO -> Tx -> Maybe AbortObservation
- mkHeadId :: PolicyId -> HeadId
- headIdToCurrencySymbol :: HeadId -> CurrencySymbol
- currencySymbolToHeadId :: MonadFail m => CurrencySymbol -> m HeadId
- headIdToPolicyId :: MonadFail m => HeadId -> m PolicyId
- headSeedToTxIn :: MonadFail m => HeadSeed -> m TxIn
- txInToHeadSeed :: TxIn -> HeadSeed
- assetNameToOnChainId :: AssetName -> OnChainId
- onChainIdToAssetName :: OnChainId -> AssetName
- verificationKeyToOnChainId :: VerificationKey PaymentKey -> OnChainId
- headTokensFromValue :: PlutusScript -> Value -> [(AssetName, Quantity)]
- findFirst :: Foldable t => (a -> Maybe b) -> t a -> Maybe b
- findHeadAssetId :: TxOut ctx -> Maybe (PolicyId, AssetName)
- findStateToken :: TxOut ctx -> Maybe HeadId
Documentation
type UTxOWithScript = (TxIn, TxOut CtxUTxO, HashableScriptData) Source #
Needed on-chain data to create Head transactions.
Instances
Arbitrary UTxOHash Source # | |
FromJSON UTxOHash Source # | |
Defined in Hydra.Chain.Direct.Tx parseJSON :: Value -> Parser UTxOHash parseJSONList :: Value -> Parser [UTxOHash] | |
ToJSON UTxOHash Source # | |
Defined in Hydra.Chain.Direct.Tx toEncoding :: UTxOHash -> Encoding toJSONList :: [UTxOHash] -> Value toEncodingList :: [UTxOHash] -> Encoding | |
Generic UTxOHash Source # | |
Show UTxOHash Source # | |
Eq UTxOHash Source # | |
type Rep UTxOHash Source # | |
Defined in Hydra.Chain.Direct.Tx type Rep UTxOHash = D1 ('MetaData "UTxOHash" "Hydra.Chain.Direct.Tx" "hydra-node-0.16.0-C0XGScKIquG5I6dPp21445" 'True) (C1 ('MetaCons "UTxOHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) |
data InitialThreadOutput Source #
Representation of the Head output after an Init transaction.
InitialThreadOutput | |
|
Instances
data OpenThreadOutput Source #
Representation of the Head output after a CollectCom transaction.
OpenThreadOutput | |
|
Instances
data ClosedThreadOutput Source #
ClosedThreadOutput | |
|
Instances
hydraHeadV1AssetName :: AssetName Source #
hydraMetadataLabel :: Word64 Source #
The metadata label used for identifying Hydra protocol transactions. As suggested by a friendly large language model: The number most commonly associated with Hydra is 5, as in the mythological creature Hydra, which had multiple heads, and the number 5 often symbolizes multiplicity or diversity. However, there is no specific numerical association for Hydra smaller than 10000 beyond this mythological reference.
mkHydraHeadV1TxName :: Text -> TxMetadata Source #
Create a transaction metadata entry to identify Hydra transactions (for informational purposes).
getHydraHeadV1TxName :: Tx -> Maybe Text Source #
Get the metadata entry to identify Hydra transactions (for informational purposes).
Create Hydra Head transactions
:: NetworkId | |
-> TxIn | Seed input. |
-> [OnChainId] | Verification key hashes of all participants. |
-> HeadParameters | |
-> Tx |
Create the init transaction from some HeadParameters
and a single TxIn
which will be used as unique parameter for minting NFTs.
mkHeadOutput :: NetworkId -> PolicyId -> TxOutDatum ctx -> TxOut ctx Source #
mkHeadOutputInitial :: NetworkId -> TxIn -> HeadParameters -> TxOut CtxTx Source #
mkInitialOutput :: NetworkId -> TxIn -> OnChainId -> TxOut CtxTx Source #
:: NetworkId | |
-> ScriptRegistry | Published Hydra scripts to reference. |
-> HeadId | |
-> Party | |
-> UTxO' (TxOut CtxUTxO, Witness WitCtxTxIn) | The UTxO to commit to the Head along with witnesses. |
-> (TxIn, TxOut CtxUTxO, Hash PaymentKey) | The initial output (sent to each party) which should contain the PT and is locked by initial script |
-> Tx |
Craft a commit transaction which includes the "committed" utxo as a datum.
mkCommitDatum :: Party -> UTxO -> CurrencySymbol -> Datum Source #
:: NetworkId | |
-> ScriptRegistry | Published Hydra scripts to reference. |
-> VerificationKey PaymentKey | Party who's authorizing this transaction |
-> HeadId | Head identifier |
-> HeadParameters | Parameters of the head to collect . |
-> (TxIn, TxOut CtxUTxO) | Everything needed to spend the Head state-machine output. |
-> Map TxIn (TxOut CtxUTxO) | Data needed to spend the commit output produced by each party.
Should contain the PT and is locked by |
-> UTxO | UTxO to be used to collect. Should match whatever is recorded in the commit inputs. |
-> Tx |
Create a transaction collecting all "committed" utxo and opening a Head, i.e. driving the Head script state.
data ClosingSnapshot Source #
Low-level data type of a snapshot to close the head with. This is different
to the ConfirmedSnasphot
, which is provided to CloseTx
as it also
contains relevant chain state like the $sel:openUtxoHash:CloseWithInitialSnapshot
.
data CloseTxError Source #
Instances
Show CloseTxError Source # | |
Defined in Hydra.Chain.Direct.Tx |
:: ScriptRegistry | Published Hydra scripts to reference. |
-> VerificationKey PaymentKey | Party who's authorizing this transaction |
-> ClosingSnapshot | The snapshot to close with, can be either initial or confirmed one. |
-> SlotNo | Lower validity slot number, usually a current or quite recent slot number. |
-> PointInTime | Upper validity slot and UTC time to compute the contestation deadline time. |
-> OpenThreadOutput | Everything needed to spend the Head state-machine output. |
-> HeadId | Head identifier |
-> Tx |
Create a transaction closing a head with either the initial snapshot or with a multi-signed confirmed snapshot.
data ContestTxError Source #
InvalidHeadIdInContest | |
CannotFindHeadOutputToContest | |
MissingHeadDatumInContest | |
MissingHeadRedeemerInContest | |
WrongDatumInContest | |
FailedToConvertFromScriptDataInContest |
Instances
Show ContestTxError Source # | |
Defined in Hydra.Chain.Direct.Tx |
:: ScriptRegistry | Published Hydra scripts to reference. |
-> VerificationKey PaymentKey | Party who's authorizing this transaction |
-> Snapshot Tx | Contested snapshot number (i.e. the one we contest to) |
-> MultiSignature (Snapshot Tx) | Multi-signature of the whole snapshot |
-> PointInTime | Current slot and posix time to be used as the contestation time. |
-> ClosedThreadOutput | Everything needed to spend the Head state-machine output. |
-> HeadId | |
-> ContestationPeriod | |
-> Tx |
data FanoutTxError Source #
CannotFindHeadOutputToFanout | |
MissingHeadDatumInFanout | |
WrongDatumInFanout | |
FailedToConvertFromScriptDataInFanout |
Instances
Show FanoutTxError Source # | |
Defined in Hydra.Chain.Direct.Tx |
:: ScriptRegistry | Published Hydra scripts to reference. |
-> UTxO | Snapshotted UTxO to fanout on layer 1 |
-> (TxIn, TxOut CtxUTxO) | Everything needed to spend the Head state-machine output. |
-> SlotNo | Contestation deadline as SlotNo, used to set lower tx validity bound. |
-> PlutusScript | Minting Policy script, made from initial seed |
-> Tx |
Create the fanout transaction, which distributes the closed state accordingly. The head validator allows fanout only > deadline, so we need to set the lower bound to be deadline + 1 slot.
data AbortTxError Source #
Instances
Show AbortTxError Source # | |
Defined in Hydra.Chain.Direct.Tx |
:: UTxO | Committed UTxOs to reimburse. |
-> ScriptRegistry | Published Hydra scripts to reference. |
-> VerificationKey PaymentKey | Party who's authorizing this transaction |
-> (TxIn, TxOut CtxUTxO) | Everything needed to spend the Head state-machine output. |
-> PlutusScript | Script for monetary policy to burn tokens |
-> Map TxIn (TxOut CtxUTxO) | Data needed to spend the initial output sent to each party to the Head. Should contain the PT and is locked by initial script. |
-> Map TxIn (TxOut CtxUTxO) | Data needed to spend commit outputs. Should contain the PT and is locked by commit script. |
-> Either AbortTxError Tx |
Create transaction which aborts a head by spending the Head output and all other "initial" outputs.
Observe Hydra Head transactions
data HeadObservation Source #
Generalised type for arbitrary Head observations on-chain.
NoHeadTx | |
Init InitObservation | |
Abort AbortObservation | |
Commit CommitObservation | |
CollectCom CollectComObservation | |
Close CloseObservation | |
Contest ContestObservation | |
Fanout FanoutObservation |
Instances
observeHeadTx :: NetworkId -> UTxO -> Tx -> HeadObservation Source #
Observe any Hydra head transaction.
data InitObservation Source #
Data which can be observed from an initTx
.
InitObservation | |
|
Instances
data NotAnInitReason Source #
Instances
observeInitTx :: Tx -> Either NotAnInitReason InitObservation Source #
Identify a init tx by checking the output value for holding tokens that are valid head tokens (checked by seed + policy).
data CommitObservation Source #
Full observation of a commit transaction.
Instances
:: NetworkId | |
-> UTxO | A UTxO set to lookup tx inputs. Should at least contain the input spending from νInitial. |
-> Tx | |
-> Maybe CommitObservation |
Identify a commit tx by:
- Check that its spending from the init validator,
- Find the outputs which pays to the commit validator,
- Using the datum of that output, deserialize the committed output,
- Reconstruct the committed UTxO from both values (tx input and output).
data CollectComObservation Source #
Instances
Arbitrary CollectComObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Generic CollectComObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Show CollectComObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Eq CollectComObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
type Rep CollectComObservation Source # | |
Defined in Hydra.Chain.Direct.Tx type Rep CollectComObservation = D1 ('MetaData "CollectComObservation" "Hydra.Chain.Direct.Tx" "hydra-node-0.16.0-C0XGScKIquG5I6dPp21445" 'False) (C1 ('MetaCons "CollectComObservation" 'PrefixI 'True) (S1 ('MetaSel ('Just "threadOutput") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OpenThreadOutput) :*: (S1 ('MetaSel ('Just "headId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HeadId) :*: S1 ('MetaSel ('Just "utxoHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UTxOHash)))) |
:: UTxO | A UTxO set to lookup tx inputs |
-> Tx | |
-> Maybe CollectComObservation |
Identify a collectCom tx by lookup up the input spending the Head output and decoding its redeemer.
data CloseObservation Source #
Instances
:: UTxO | A UTxO set to lookup tx inputs |
-> Tx | |
-> Maybe CloseObservation |
Identify a close tx by lookup up the input spending the Head output and decoding its redeemer.
data ContestObservation Source #
ContestObservation | |
|
Instances
:: UTxO | A UTxO set to lookup tx inputs |
-> Tx | |
-> Maybe ContestObservation |
Identify a close tx by lookup up the input spending the Head output and decoding its redeemer.
newtype FanoutObservation Source #
Instances
Arbitrary FanoutObservation Source # | |
Defined in Hydra.Chain.Direct.Tx arbitrary :: Gen FanoutObservation shrink :: FanoutObservation -> [FanoutObservation] | |
Generic FanoutObservation Source # | |
Defined in Hydra.Chain.Direct.Tx from :: FanoutObservation -> Rep FanoutObservation x Source # to :: Rep FanoutObservation x -> FanoutObservation Source # | |
Show FanoutObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Eq FanoutObservation Source # | |
Defined in Hydra.Chain.Direct.Tx (==) :: FanoutObservation -> FanoutObservation -> Bool Source # (/=) :: FanoutObservation -> FanoutObservation -> Bool Source # | |
type Rep FanoutObservation Source # | |
Defined in Hydra.Chain.Direct.Tx type Rep FanoutObservation = D1 ('MetaData "FanoutObservation" "Hydra.Chain.Direct.Tx" "hydra-node-0.16.0-C0XGScKIquG5I6dPp21445" 'True) (C1 ('MetaCons "FanoutObservation" 'PrefixI 'True) (S1 ('MetaSel ('Just "headId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HeadId))) |
:: UTxO | A UTxO set to lookup tx inputs |
-> Tx | |
-> Maybe FanoutObservation |
Identify a fanout tx by lookup up the input spending the Head output and decoding its redeemer.
newtype AbortObservation Source #
Instances
Arbitrary AbortObservation Source # | |
Defined in Hydra.Chain.Direct.Tx arbitrary :: Gen AbortObservation shrink :: AbortObservation -> [AbortObservation] | |
Generic AbortObservation Source # | |
Defined in Hydra.Chain.Direct.Tx from :: AbortObservation -> Rep AbortObservation x Source # to :: Rep AbortObservation x -> AbortObservation Source # | |
Show AbortObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Eq AbortObservation Source # | |
Defined in Hydra.Chain.Direct.Tx (==) :: AbortObservation -> AbortObservation -> Bool Source # (/=) :: AbortObservation -> AbortObservation -> Bool Source # | |
type Rep AbortObservation Source # | |
Defined in Hydra.Chain.Direct.Tx type Rep AbortObservation = D1 ('MetaData "AbortObservation" "Hydra.Chain.Direct.Tx" "hydra-node-0.16.0-C0XGScKIquG5I6dPp21445" 'True) (C1 ('MetaCons "AbortObservation" 'PrefixI 'True) (S1 ('MetaSel ('Just "headId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HeadId))) |
:: UTxO | A UTxO set to lookup tx inputs |
-> Tx | |
-> Maybe AbortObservation |
Identify an abort tx by looking up the input spending the Head output and decoding its redeemer.
Cardano specific identifiers
headIdToCurrencySymbol :: HeadId -> CurrencySymbol Source #
currencySymbolToHeadId :: MonadFail m => CurrencySymbol -> m HeadId Source #
headIdToPolicyId :: MonadFail m => HeadId -> m PolicyId Source #
headSeedToTxIn :: MonadFail m => HeadSeed -> m TxIn Source #
txInToHeadSeed :: TxIn -> HeadSeed Source #
assetNameToOnChainId :: AssetName -> OnChainId Source #
onChainIdToAssetName :: OnChainId -> AssetName Source #
verificationKeyToOnChainId :: VerificationKey PaymentKey -> OnChainId Source #
Derive the OnChainId
from a Cardano PaymentKey
. The on-chain identifier
is the public key hash as it is also availble to plutus validators.
Helpers
headTokensFromValue :: PlutusScript -> Value -> [(AssetName, Quantity)] Source #
findFirst :: Foldable t => (a -> Maybe b) -> t a -> Maybe b Source #
Find first occurrence including a transformation.
findHeadAssetId :: TxOut ctx -> Maybe (PolicyId, AssetName) Source #
findStateToken :: TxOut ctx -> Maybe HeadId Source #
Find (if it exists) the head identifier contained in given TxOut
.