hydra-node-0.13.0: The Hydra node
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Documentation

type UTxOWithScript = (TxIn, TxOut CtxUTxO, HashableScriptData) Source #

Needed on-chain data to create Head transactions.

newtype UTxOHash Source #

Constructors

UTxOHash ByteString 

Instances

Instances details
FromJSON UTxOHash Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Methods

parseJSON :: Value -> Parser UTxOHash

parseJSONList :: Value -> Parser [UTxOHash]

ToJSON UTxOHash Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Methods

toJSON :: UTxOHash -> Value

toEncoding :: UTxOHash -> Encoding

toJSONList :: [UTxOHash] -> Value

toEncodingList :: [UTxOHash] -> Encoding

Generic UTxOHash Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Associated Types

type Rep UTxOHash :: Type -> Type Source #

Show UTxOHash Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Eq UTxOHash Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

type Rep UTxOHash Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

type Rep UTxOHash = D1 ('MetaData "UTxOHash" "Hydra.Chain.Direct.Tx" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" '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.

Constructors

InitialThreadOutput 

Fields

Instances

Instances details
FromJSON InitialThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Methods

parseJSON :: Value -> Parser InitialThreadOutput

parseJSONList :: Value -> Parser [InitialThreadOutput]

ToJSON InitialThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Generic InitialThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Associated Types

type Rep InitialThreadOutput :: Type -> Type Source #

Show InitialThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Eq InitialThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

type Rep InitialThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

type Rep InitialThreadOutput = D1 ('MetaData "InitialThreadOutput" "Hydra.Chain.Direct.Tx" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" 'False) (C1 ('MetaCons "InitialThreadOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "initialThreadUTxO") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UTxOWithScript) :*: (S1 ('MetaSel ('Just "initialContestationPeriod") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ContestationPeriod) :*: S1 ('MetaSel ('Just "initialParties") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Party]))))

data OpenThreadOutput Source #

Representation of the Head output after a CollectCom transaction.

Constructors

OpenThreadOutput 

Fields

Instances

Instances details
FromJSON OpenThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Methods

parseJSON :: Value -> Parser OpenThreadOutput

parseJSONList :: Value -> Parser [OpenThreadOutput]

ToJSON OpenThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Generic OpenThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Associated Types

type Rep OpenThreadOutput :: Type -> Type Source #

Show OpenThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Eq OpenThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

type Rep OpenThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

type Rep OpenThreadOutput = D1 ('MetaData "OpenThreadOutput" "Hydra.Chain.Direct.Tx" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" 'False) (C1 ('MetaCons "OpenThreadOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "openThreadUTxO") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UTxOWithScript) :*: (S1 ('MetaSel ('Just "openContestationPeriod") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ContestationPeriod) :*: S1 ('MetaSel ('Just "openParties") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Party]))))

data ClosedThreadOutput Source #

Constructors

ClosedThreadOutput 

Fields

Instances

Instances details
FromJSON ClosedThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Methods

parseJSON :: Value -> Parser ClosedThreadOutput

parseJSONList :: Value -> Parser [ClosedThreadOutput]

ToJSON ClosedThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Generic ClosedThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Associated Types

type Rep ClosedThreadOutput :: Type -> Type Source #

Show ClosedThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

Eq ClosedThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

type Rep ClosedThreadOutput Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

type Rep ClosedThreadOutput = D1 ('MetaData "ClosedThreadOutput" "Hydra.Chain.Direct.Tx" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" 'False) (C1 ('MetaCons "ClosedThreadOutput" 'PrefixI 'True) ((S1 ('MetaSel ('Just "closedThreadUTxO") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UTxOWithScript) :*: S1 ('MetaSel ('Just "closedParties") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Party])) :*: (S1 ('MetaSel ('Just "closedContestationDeadline") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 POSIXTime) :*: S1 ('MetaSel ('Just "closedContesters") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [PubKeyHash]))))

headValue :: Value Source #

Create Hydra Head transactions

initTx Source #

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 #

commitTx 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 #

collectComTx 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 ν_commit script.

-> 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.

closeTx Source #

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.

contestTx Source #

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 

fanoutTx Source #

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

Instances details
Show AbortTxError Source # 
Instance details

Defined in Hydra.Chain.Direct.Tx

abortTx Source #

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

observeInitTx Source #

Arguments

:: NetworkId 
-> [VerificationKey PaymentKey] 
-> ContestationPeriod

Our node's contestation period

-> Party 
-> [Party] 
-> Tx 
-> Either NotAnInitReason InitObservation 

observeCommitTx Source #

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).

observeCollectComTx 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.

observeCloseTx 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.

observeContestTx 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.

observeFanoutTx Source #

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.

observeAbortTx Source #

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

mkHeadId :: PolicyId -> HeadId Source #

headIdToCurrencySymbol :: HeadId -> CurrencySymbol Source #

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.