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

Hydra.Chain.Direct.State

Description

Contains the a state-ful interface to transaction construction and observation.

It defines the 'ChainStateType tx' to be used in the Direct layer and it's constituents.

Synopsis

Documentation

class HasKnownUTxO a where Source #

A class for accessing the known UTxO' set in a type. This is useful to get all the relevant UTxO for resolving transaction inputs.

Methods

getKnownUTxO :: a -> UTxO Source #

Instances

Instances details
HasKnownUTxO ChainContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: ChainContext -> UTxO Source #

HasKnownUTxO ChainState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: ChainState -> UTxO Source #

HasKnownUTxO ClosedState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: ClosedState -> UTxO Source #

HasKnownUTxO InitialState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: InitialState -> UTxO Source #

HasKnownUTxO OpenState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: OpenState -> UTxO Source #

States & transitions

data ChainStateAt Source #

The chain state used by the Hydra.Chain.Direct implementation. It records the actual ChainState paired with a ChainSlot (used to know up to which point to rewind on rollbacks).

Constructors

ChainStateAt 

Instances

Instances details
Arbitrary ChainStateAt Source # 
Instance details

Defined in Hydra.Chain.Direct.State

FromJSON ChainStateAt Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

parseJSON :: Value -> Parser ChainStateAt

parseJSONList :: Value -> Parser [ChainStateAt]

ToJSON ChainStateAt Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

toJSON :: ChainStateAt -> Value

toEncoding :: ChainStateAt -> Encoding

toJSONList :: [ChainStateAt] -> Value

toEncodingList :: [ChainStateAt] -> Encoding

Generic ChainStateAt Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Associated Types

type Rep ChainStateAt :: Type -> Type Source #

Show ChainStateAt Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Eq ChainStateAt Source # 
Instance details

Defined in Hydra.Chain.Direct.State

type Rep ChainStateAt Source # 
Instance details

Defined in Hydra.Chain.Direct.State

type Rep ChainStateAt = D1 ('MetaData "ChainStateAt" "Hydra.Chain.Direct.State" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" 'False) (C1 ('MetaCons "ChainStateAt" 'PrefixI 'True) (S1 ('MetaSel ('Just "chainState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ChainState) :*: (S1 ('MetaSel ('Just "recordedAt") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ChainPoint)) :*: S1 ('MetaSel ('Just "previous") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ChainStateAt)))))

chainSlotFromPoint :: ChainPoint -> ChainSlot Source #

Get a generic ChainSlot from a Cardano ChainPoint. Slot 0 is used for the genesis point.

data ChainState Source #

An enumeration of all possible on-chain states of a Hydra Head, where each case stores the relevant information to construct & observe transactions to other states.

Constructors

Idle

The idle state does not contain any head-specific information and exists to be used as a starting and terminal state.

Initial InitialState 
Open OpenState 
Closed ClosedState 

Instances

Instances details
Arbitrary ChainState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

FromJSON ChainState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

parseJSON :: Value -> Parser ChainState

parseJSONList :: Value -> Parser [ChainState]

ToJSON ChainState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

toJSON :: ChainState -> Value

toEncoding :: ChainState -> Encoding

toJSONList :: [ChainState] -> Value

toEncodingList :: [ChainState] -> Encoding

Generic ChainState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Associated Types

type Rep ChainState :: Type -> Type Source #

Show ChainState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Eq ChainState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

HasKnownUTxO ChainState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: ChainState -> UTxO Source #

type Rep ChainState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

data ChainContext Source #

Read-only chain-specific data. This is different to HydraContext as it only contains data known to single peer.

Instances

Instances details
Arbitrary ChainContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

FromJSON ChainContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

parseJSON :: Value -> Parser ChainContext

parseJSONList :: Value -> Parser [ChainContext]

ToJSON ChainContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

toJSON :: ChainContext -> Value

toEncoding :: ChainContext -> Encoding

toJSONList :: [ChainContext] -> Value

toEncodingList :: [ChainContext] -> Encoding

Generic ChainContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Associated Types

type Rep ChainContext :: Type -> Type Source #

Show ChainContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Eq ChainContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

HasKnownUTxO ChainContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: ChainContext -> UTxO Source #

type Rep ChainContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

type Rep ChainContext = D1 ('MetaData "ChainContext" "Hydra.Chain.Direct.State" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" 'False) (C1 ('MetaCons "ChainContext" 'PrefixI 'True) ((S1 ('MetaSel ('Just "networkId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 NetworkId) :*: (S1 ('MetaSel ('Just "peerVerificationKeys") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [VerificationKey PaymentKey]) :*: S1 ('MetaSel ('Just "ownVerificationKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (VerificationKey PaymentKey)))) :*: ((S1 ('MetaSel ('Just "ownParty") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Party) :*: S1 ('MetaSel ('Just "otherParties") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Party])) :*: (S1 ('MetaSel ('Just "scriptRegistry") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ScriptRegistry) :*: S1 ('MetaSel ('Just "contestationPeriod") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ContestationPeriod)))))

allVerificationKeys :: ChainContext -> [VerificationKey PaymentKey] Source #

Get all cardano verification keys available in the chain context.

data InitialState Source #

Instances

Instances details
FromJSON InitialState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

parseJSON :: Value -> Parser InitialState

parseJSONList :: Value -> Parser [InitialState]

ToJSON InitialState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

toJSON :: InitialState -> Value

toEncoding :: InitialState -> Encoding

toJSONList :: [InitialState] -> Value

toEncodingList :: [InitialState] -> Encoding

Generic InitialState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Associated Types

type Rep InitialState :: Type -> Type Source #

Show InitialState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Eq InitialState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

HasKnownUTxO InitialState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: InitialState -> UTxO Source #

type Rep InitialState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

type Rep InitialState = D1 ('MetaData "InitialState" "Hydra.Chain.Direct.State" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" 'False) (C1 ('MetaCons "InitialState" 'PrefixI 'True) ((S1 ('MetaSel ('Just "initialThreadOutput") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 InitialThreadOutput) :*: S1 ('MetaSel ('Just "initialInitials") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [UTxOWithScript])) :*: (S1 ('MetaSel ('Just "initialCommits") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [UTxOWithScript]) :*: (S1 ('MetaSel ('Just "headId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HeadId) :*: S1 ('MetaSel ('Just "seedTxIn") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TxIn)))))

data OpenState Source #

Instances

Instances details
FromJSON OpenState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

parseJSON :: Value -> Parser OpenState

parseJSONList :: Value -> Parser [OpenState]

ToJSON OpenState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

toJSON :: OpenState -> Value

toEncoding :: OpenState -> Encoding

toJSONList :: [OpenState] -> Value

toEncodingList :: [OpenState] -> Encoding

Generic OpenState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Associated Types

type Rep OpenState :: Type -> Type Source #

Show OpenState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Eq OpenState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

HasKnownUTxO OpenState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: OpenState -> UTxO Source #

type Rep OpenState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

type Rep OpenState = D1 ('MetaData "OpenState" "Hydra.Chain.Direct.State" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" 'False) (C1 ('MetaCons "OpenState" 'PrefixI 'True) ((S1 ('MetaSel ('Just "openThreadOutput") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OpenThreadOutput) :*: S1 ('MetaSel ('Just "headId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HeadId)) :*: (S1 ('MetaSel ('Just "seedTxIn") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TxIn) :*: S1 ('MetaSel ('Just "openUtxoHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UTxOHash))))

data ClosedState Source #

Instances

Instances details
FromJSON ClosedState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

parseJSON :: Value -> Parser ClosedState

parseJSONList :: Value -> Parser [ClosedState]

ToJSON ClosedState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

toJSON :: ClosedState -> Value

toEncoding :: ClosedState -> Encoding

toJSONList :: [ClosedState] -> Value

toEncodingList :: [ClosedState] -> Encoding

Generic ClosedState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Associated Types

type Rep ClosedState :: Type -> Type Source #

Show ClosedState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Eq ClosedState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

HasKnownUTxO ClosedState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

Methods

getKnownUTxO :: ClosedState -> UTxO Source #

type Rep ClosedState Source # 
Instance details

Defined in Hydra.Chain.Direct.State

type Rep ClosedState = D1 ('MetaData "ClosedState" "Hydra.Chain.Direct.State" "hydra-node-0.13.0-HKlbaPrFKjs2dhEMwn7ono" 'False) (C1 ('MetaCons "ClosedState" 'PrefixI 'True) (S1 ('MetaSel ('Just "closedThreadOutput") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ClosedThreadOutput) :*: (S1 ('MetaSel ('Just "headId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HeadId) :*: S1 ('MetaSel ('Just "seedTxIn") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TxIn))))

Constructing transactions

initialize Source #

Arguments

:: ChainContext 
-> HeadParameters 
-> TxIn

Seed input.

-> Tx 

Construct an init transaction given some general ChainContext, the HeadParameters and a seed TxIn which will be spent.

commit :: ChainContext -> InitialState -> UTxO' (TxOut CtxUTxO) -> Either (PostTxError Tx) Tx Source #

Construct a commit transaction based on the InitialState. This does look for "our initial output" to spend and check the given UTxO' to be compatible. Hence, this function does fail if already committed.

NOTE: This version of commit does only commit outputs which are held by payment keys. For a variant which supports committing scripts, see commit`.

commit' :: ChainContext -> InitialState -> UTxO' (TxOut CtxUTxO, Witness WitCtxTxIn) -> Either (PostTxError Tx) Tx Source #

Construct a commit transaction base on the InitialState and some arbitrary UTxOs to commit.

NOTE: A simpler variant only supporting pubkey outputs is commit.

ownInitial :: ChainContext -> InitialState -> Maybe (TxIn, TxOut CtxUTxO, Hash PaymentKey) Source #

hasMatchingPT :: InitialState -> Hash PaymentKey -> Value -> Bool Source #

abort Source #

Arguments

:: HasCallStack 
=> ChainContext 
-> InitialState 
-> UTxO

Committed UTxOs to reimburse.

-> Tx 

Construct a collect transaction based on the InitialState. This will reimburse all the already committed outputs.

collect :: ChainContext -> InitialState -> Tx Source #

Construct a collect transaction based on the InitialState. This will know collect all the committed outputs.

close Source #

Arguments

:: ChainContext 
-> OpenState 
-> ConfirmedSnapshot Tx 
-> SlotNo

Tx validity lower bound

-> PointInTime

Tx validity upper bound

-> Tx 

Construct a close transaction based on the OpenState and a confirmed snapshot. - SlotNo parameter will be used as the Tx lower bound. - PointInTime parameter will be used as an upper validity bound and will define the start of the contestation period. NB: lower and upper bound slot difference should not exceed contestation period

contest :: ChainContext -> ClosedState -> ConfirmedSnapshot Tx -> PointInTime -> Tx Source #

Construct a contest transaction based on the ClosedState and a confirmed snapshot. The given PointInTime will be used as an upper validity bound and needs to be before the deadline.

fanout Source #

Arguments

:: ChainContext 
-> ClosedState 
-> UTxO 
-> SlotNo

Contestation deadline as SlotNo, used to set lower tx validity bound.

-> Tx 

Construct a fanout transaction based on the ClosedState and off-chain agreed UTxO' set to fan out.

Observing Transitions

observeSomeTx :: ChainContext -> ChainState -> Tx -> Maybe (OnChainTx Tx, ChainState) Source #

Observe a transition without knowing the starting or ending state. This function should try to observe all relevant transitions given some ChainState.

IdleState transitions

InitialState transitions

observeCollect :: InitialState -> Tx -> Maybe (OnChainTx Tx, OpenState) Source #

Observe an collect transition using a InitialState and observeCollectComTx. This function checks the head id and ignores if not relevant.

observeAbort :: InitialState -> Tx -> Maybe (OnChainTx Tx) Source #

Observe an abort transition using a InitialState and observeAbortTx.

OpenState transitions

observeClose :: OpenState -> Tx -> Maybe (OnChainTx Tx, ClosedState) Source #

Observe a close transition using a OpenState and observeCloseTx. This function checks the head id and ignores if not relevant.

ClosedState transitions

observeContest :: ClosedState -> Tx -> Maybe (OnChainTx Tx, ClosedState) Source #

Observe a fanout transition using a ClosedState and observeContestTx. This function checks the head id and ignores if not relevant.

observeFanout :: ClosedState -> Tx -> Maybe (OnChainTx Tx) Source #

Observe a fanout transition using a ClosedState and observeFanoutTx.

Generators

maxGenParties :: Int Source #

Maximum number of parties used in the generators.

maxGenAssets :: Int Source #

Maximum number of assets (ADA or other tokens) used in the generators.

genChainState :: Gen ChainState Source #

Generate a ChainState within known limits above.

genChainStateWithTx :: Gen (ChainContext, ChainState, Tx, ChainTransition) Source #

Generate a ChainContext and ChainState within the known limits above, along with a transaction that results in a transition away from it.

Warning zone

data HydraContext Source #

Define some global context from which generators can pick values for generation. This allows to write fairly independent generators which however still make sense with one another within the context of a head.

For example, one can generate a head's _party_ from that global list, whereas other functions may rely on all parties and thus, we need both generation to be coherent.

Do not use this in production code, but only for generating test data.

Instances

Instances details
Show HydraContext Source # 
Instance details

Defined in Hydra.Chain.Direct.State

genHydraContext :: Int -> Gen HydraContext Source #

Generate a HydraContext for a arbitrary number of parties, bounded by given maximum.

genHydraContextFor :: Int -> Gen HydraContext Source #

Generate a HydraContext for a given number of parties.

deriveChainContexts :: HydraContext -> Gen [ChainContext] Source #

Get all peer-specific ChainContexts from a HydraContext. NOTE: This assumes that HydraContext has same length $sel:ctxVerificationKeys:HydraContext and $sel:ctxHydraSigningKeys:HydraContext. XXX: This is actually a non-monadic function.

pickChainContext :: HydraContext -> Gen ChainContext Source #

Pick one of the participants and derive the peer-specific ChainContext from a HydraContext. NOTE: This assumes that HydraContext has same length $sel:ctxVerificationKeys:HydraContext and $sel:ctxHydraSigningKeys:HydraContext.

genCommits' :: Gen UTxO -> HydraContext -> Tx -> Gen [Tx] Source #

genCommit :: Gen UTxO Source #

Danger zone

Orphan instances

IsChainState Tx Source # 
Instance details

Associated Types

type ChainStateType Tx = (c :: Type) Source #