Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Hydra.Chain.Direct.Tx
Description
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 :: UTxOWithScript
- initialContestationPeriod :: ContestationPeriod
- initialParties :: [Party]
- data OpenThreadOutput = OpenThreadOutput {
- openThreadUTxO :: UTxOWithScript
- openContestationPeriod :: ContestationPeriod
- openParties :: [Party]
- data ClosedThreadOutput = ClosedThreadOutput {
- closedThreadUTxO :: UTxOWithScript
- closedParties :: [Party]
- closedContestationDeadline :: POSIXTime
- closedContesters :: [PubKeyHash]
- hydraHeadV1AssetName :: AssetName
- headValue :: Value
- initTx :: NetworkId -> [VerificationKey PaymentKey] -> HeadParameters -> TxIn -> Tx
- mkHeadOutput :: NetworkId -> PolicyId -> TxOutDatum ctx -> TxOut ctx
- mkHeadOutputInitial :: NetworkId -> TxIn -> HeadParameters -> TxOut CtxTx
- mkInitialOutput :: NetworkId -> TxIn -> VerificationKey PaymentKey -> 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 -> InitialThreadOutput -> Map TxIn (TxOut CtxUTxO, HashableScriptData) -> HeadId -> Tx
- data ClosingSnapshot
- closeTx :: ScriptRegistry -> VerificationKey PaymentKey -> ClosingSnapshot -> SlotNo -> PointInTime -> OpenThreadOutput -> HeadId -> Tx
- contestTx :: ScriptRegistry -> VerificationKey PaymentKey -> Snapshot Tx -> MultiSignature (Snapshot Tx) -> PointInTime -> ClosedThreadOutput -> HeadId -> ContestationPeriod -> Tx
- fanoutTx :: ScriptRegistry -> UTxO -> UTxOWithScript -> SlotNo -> PlutusScript -> Tx
- data AbortTxError = OverlappingInputs
- abortTx :: UTxO -> ScriptRegistry -> VerificationKey PaymentKey -> (TxIn, TxOut CtxUTxO, HashableScriptData) -> PlutusScript -> Map TxIn (TxOut CtxUTxO, HashableScriptData) -> Map TxIn (TxOut CtxUTxO, HashableScriptData) -> Either AbortTxError Tx
- data InitObservation = InitObservation {
- threadOutput :: InitialThreadOutput
- initials :: [UTxOWithScript]
- commits :: [UTxOWithScript]
- headId :: HeadId
- seedTxIn :: TxIn
- contestationPeriod :: ContestationPeriod
- parties :: [Party]
- data NotAnInitReason
- observeInitTx :: NetworkId -> [VerificationKey PaymentKey] -> ContestationPeriod -> Party -> [Party] -> Tx -> Either NotAnInitReason InitObservation
- data CommitObservation = CommitObservation {
- commitOutput :: UTxOWithScript
- party :: Party
- committed :: UTxO
- observeCommitTx :: NetworkId -> [TxIn] -> 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, HashableScriptData)
- headId :: HeadId
- snapshotNumber :: SnapshotNumber
- contesters :: [PubKeyHash]
- observeContestTx :: UTxO -> Tx -> Maybe ContestObservation
- data FanoutObservation = FanoutObservation
- observeFanoutTx :: UTxO -> Tx -> Maybe FanoutObservation
- data AbortObservation = AbortObservation
- observeAbortTx :: UTxO -> Tx -> Maybe AbortObservation
- mkHeadId :: PolicyId -> HeadId
- headIdToCurrencySymbol :: HeadId -> CurrencySymbol
- headTokensFromValue :: PlutusScript -> Value -> [(AssetName, Quantity)]
- assetNameFromVerificationKey :: VerificationKey PaymentKey -> AssetName
- 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.
Constructors
UTxOHash ByteString |
Instances
FromJSON UTxOHash Source # | |
Defined in Hydra.Chain.Direct.Tx | |
ToJSON UTxOHash Source # | |
Defined in Hydra.Chain.Direct.Tx Methods 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 |
data InitialThreadOutput Source #
Representation of the Head output after an Init transaction.
Constructors
InitialThreadOutput | |
Fields
|
Instances
data OpenThreadOutput Source #
Representation of the Head output after a CollectCom transaction.
Constructors
OpenThreadOutput | |
Fields
|
Instances
data ClosedThreadOutput Source #
Constructors
ClosedThreadOutput | |
Fields
|
Instances
hydraHeadV1AssetName :: AssetName Source #
Create Hydra Head transactions
Arguments
:: NetworkId | |
-> [VerificationKey PaymentKey] | All participants cardano keys. |
-> HeadParameters | |
-> TxIn | |
-> 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 -> VerificationKey PaymentKey -> TxOut CtxTx Source #
Arguments
:: 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 #
Arguments
:: NetworkId | |
-> ScriptRegistry | Published Hydra scripts to reference. |
-> VerificationKey PaymentKey | Party who's authorizing this transaction |
-> InitialThreadOutput | Everything needed to spend the Head state-machine output. |
-> Map TxIn (TxOut CtxUTxO, HashableScriptData) | Data needed to spend the commit output produced by each party.
Should contain the PT and is locked by |
-> HeadId | Head id |
-> 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
.
Constructors
CloseWithInitialSnapshot | |
Fields | |
CloseWithConfirmedSnapshot | |
Fields |
Arguments
:: 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.
Arguments
:: 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 |
Arguments
:: ScriptRegistry | Published Hydra scripts to reference. |
-> UTxO | Snapshotted UTxO to fanout on layer 1 |
-> UTxOWithScript | 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 #
Constructors
OverlappingInputs |
Instances
Show AbortTxError Source # | |
Defined in Hydra.Chain.Direct.Tx |
Arguments
:: UTxO | Committed UTxOs to reimburse. |
-> ScriptRegistry | Published Hydra scripts to reference. |
-> VerificationKey PaymentKey | Party who's authorizing this transaction |
-> (TxIn, TxOut CtxUTxO, HashableScriptData) | Everything needed to spend the Head state-machine output. |
-> PlutusScript | Script for monetary policy to burn tokens |
-> Map TxIn (TxOut CtxUTxO, HashableScriptData) | 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, HashableScriptData) | 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 InitObservation Source #
Constructors
InitObservation | |
Fields
|
Instances
Show InitObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Eq InitObservation Source # | |
Defined in Hydra.Chain.Direct.Tx Methods (==) :: InitObservation -> InitObservation -> Bool Source # (/=) :: InitObservation -> InitObservation -> Bool Source # |
data NotAnInitReason Source #
Constructors
NotAHeadPolicy | |
NoHeadOutput | |
NotAHeadDatum | |
NoSTFound | |
PartiesMismatch | |
OwnPartyMissing | |
CPMismatch | |
PTsNotMintedCorrectly |
Instances
Show NotAnInitReason Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Eq NotAnInitReason Source # | |
Defined in Hydra.Chain.Direct.Tx Methods (==) :: NotAnInitReason -> NotAnInitReason -> Bool Source # (/=) :: NotAnInitReason -> NotAnInitReason -> Bool Source # |
Arguments
:: NetworkId | |
-> [VerificationKey PaymentKey] | |
-> ContestationPeriod | Our node's contestation period |
-> Party | |
-> [Party] | |
-> Tx | |
-> Either NotAnInitReason InitObservation |
data CommitObservation Source #
Constructors
CommitObservation | |
Fields
|
Arguments
:: NetworkId | |
-> [TxIn] | Known (remaining) initial tx inputs. |
-> Tx | |
-> Maybe CommitObservation |
Identify a commit tx by:
- Find which
initial
tx input is being consumed, - Find the redeemer corresponding to that
initial
, which contains the tx input of the committed utxo, - 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 #
Constructors
CollectComObservation | |
Fields
|
Instances
Show CollectComObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Eq CollectComObservation Source # | |
Defined in Hydra.Chain.Direct.Tx Methods (==) :: CollectComObservation -> CollectComObservation -> Bool Source # (/=) :: CollectComObservation -> CollectComObservation -> Bool Source # |
Arguments
:: 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 #
Constructors
CloseObservation | |
Fields |
Instances
Show CloseObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Eq CloseObservation Source # | |
Defined in Hydra.Chain.Direct.Tx Methods (==) :: CloseObservation -> CloseObservation -> Bool Source # (/=) :: CloseObservation -> CloseObservation -> Bool Source # |
Arguments
:: 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 #
Constructors
ContestObservation | |
Fields
|
Instances
Show ContestObservation Source # | |
Defined in Hydra.Chain.Direct.Tx | |
Eq ContestObservation Source # | |
Defined in Hydra.Chain.Direct.Tx Methods (==) :: ContestObservation -> ContestObservation -> Bool Source # (/=) :: ContestObservation -> ContestObservation -> Bool Source # |
Arguments
:: 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.
data FanoutObservation Source #
Constructors
FanoutObservation |
Arguments
:: 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.
data AbortObservation Source #
Constructors
AbortObservation |
Arguments
:: 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. FIXME: Add headId to AbortObservation to allow "upper layers" to determine we are seeing an abort of "our head"
Helpers
headIdToCurrencySymbol :: HeadId -> CurrencySymbol Source #
headTokensFromValue :: PlutusScript -> Value -> [(AssetName, Quantity)] Source #
assetNameFromVerificationKey :: VerificationKey PaymentKey -> AssetName 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
.