singular-registry
LicenseApache-2.0
Safe HaskellNone
LanguageGHC2021

Singular.State.Assemble

Description

A state transaction is built from facts read before it is built: the payer's funding output, the outputs it spends or reads, and the slot the chain has reached. This module reads the payer, answers an output query without losing the difference between an absent output and a failed read, picks a validity interval that starts at the tip, and hands a transaction program to the transaction builder with the session's own script evaluator, so a script the validator refuses stops the build.

Synopsis

Programs

data NoQuery (a :: k) Source #

No queries. A state transaction reads the chain before it is built, never while it is.

type Program = TxBuild (NoQuery :: Type -> Type) Void Source #

A transaction program as the state builders write it.

The payer

data Payer Source #

The payer of a transaction: the key that signs it, and the ADA-only output that funds it and secures it as collateral.

Constructors

Payer 

Fields

data PayerFault Source #

Why an address cannot pay for a transaction.

Constructors

NoFunding

It holds no ADA-only output to fund and secure a transaction.

NotAKey

Its payment credential is a script, which cannot sign.

Instances

Instances details
Show PayerFault Source # 
Instance details

Defined in Singular.State.Assemble

Methods

showsPrec :: Int -> PayerFault -> ShowS Source #

show :: PayerFault -> String Source #

showList :: [PayerFault] -> ShowS Source #

Eq PayerFault Source # 
Instance details

Defined in Singular.State.Assemble

Methods

(==) :: PayerFault -> PayerFault -> Bool Source #

(/=) :: PayerFault -> PayerFault -> Bool Source #

findPayer :: Session NoWitness IO -> Addr -> IO (Either PayerFault Payer) Source #

The payer at an address: refused when the address is not a key's, or when it holds no ADA-only output to fund and secure a transaction.

resolvePayer :: Session NoWitness IO -> Addr -> IO (Either Refusal Payer) Source #

The payer at an address, with the refusal of the state builders.

resolvePayerReserving :: [TxIn] -> Session NoWitness IO -> Addr -> IO (Either Refusal Payer) Source #

The payer of a publication that must leave the reserved outputs unspent for a later transaction. Selection still uses the session's actual wallet outputs and the ordinary ADA-only funding rule.

Reading the chain

readOutputs :: Session NoWitness IO -> OutputQuery -> IO (Either ReadFailure Outputs) Source #

The outputs the session answers a query with. An absent exact reference comes back as a ReadFailure for the caller to name; any other failure is for the caller to throw.

inlineDatumOf :: TxOut ConwayEra -> Maybe Data Source #

The inline datum of an output.

holdsOnly :: PolicyID -> AssetName -> TxOut ConwayEra -> Bool Source #

The output holds this token once and nothing but ADA besides.

tipSlot :: Session NoWitness IO -> IO SlotNo Source #

The slot the chain has reached.

validityFromTip :: Session NoWitness IO -> SlotNo -> SlotNo -> IO (Maybe SlotNo) Source #

The last slot a transaction that starts at the tip can end before, when it must end no later than wanted: nothing when the interval from the tip is too short to be usable, and the nearer slot when the ledger's horizon is nearer. The bound is exclusive, as a validity interval's end is.

windowFromTip :: Session NoWitness IO -> Integer -> IO (Maybe (SlotNo, SlotNo)) Source #

The window of a transaction built now: from the tip to the end of a span of the given milliseconds, cut where the ledger's horizon is nearer. Nothing when the interval from the tip is too short to use. The one place a builder turns a span of time into slots, so that no builder reads time another way.

usualSpan :: Integer Source #

How long a transaction stays valid when its protocol gives it no window of its own, in milliseconds: an hour from the tip.

noUsableWindow :: Text Source #

Why a build stops when the interval from the tip is too short to use.

Assembly

assemble Source #

Arguments

:: Session NoWitness IO 
-> [(TxIn, TxOut ConwayEra)]

The outputs the transaction spends

-> [(TxIn, TxOut ConwayEra)]

The outputs it reads by reference

-> Addr

Where the change goes

-> Program () 
-> IO (Either Text ConwayTx) 

Build a transaction from a program. The session's own evaluator runs every script, so a script the validator refuses stops the build with its message.

assembleTransaction :: Session NoWitness IO -> [(TxIn, TxOut ConwayEra)] -> [(TxIn, TxOut ConwayEra)] -> Addr -> Program () -> IO (Either Refusal ConwayTx) Source #

The transaction of a program, with the refusal of the state builders.