marlowe-runtime-0.0.5: Runtime system for running Marlowe financial contracts on the Cardano Computation Layer
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.Marlowe.Runtime.Transaction.Constraints

Synopsis

Documentation

data ConstraintError #

Instances

Instances details
ToJSON ConstraintError 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Api

Methods

toJSON :: ConstraintError -> Value

toEncoding :: ConstraintError -> Encoding

toJSONList :: [ConstraintError] -> Value

toEncodingList :: [ConstraintError] -> Encoding

Generic ConstraintError 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Api

Associated Types

type Rep ConstraintError :: Type -> Type Source #

Show ConstraintError 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Api

Binary ConstraintError 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Api

Methods

put :: ConstraintError -> Put

get :: Get ConstraintError

putList :: [ConstraintError] -> Put

Eq ConstraintError 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Api

Ord ConstraintError 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Api

Variations ConstraintError 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Api

type Rep ConstraintError 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Api

type Rep ConstraintError = D1 ('MetaData "ConstraintError" "Language.Marlowe.Runtime.Transaction.Api" "marlowe-runtime-0.0.5-ChFVSHN4E987Ueq8VfwI0T-tx-api" 'False) (((C1 ('MetaCons "MintingUtxoNotFound" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TxOutRef)) :+: (C1 ('MetaCons "RoleTokenNotFound" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 AssetId)) :+: C1 ('MetaCons "ToCardanoError" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "MissingMarloweInput" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PayoutNotFound" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TxOutRef))) :+: (C1 ('MetaCons "InvalidPayoutDatum" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TxOutRef) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Datum))) :+: C1 ('MetaCons "InvalidPayoutScriptAddress" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TxOutRef) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Address))))) :+: (((C1 ('MetaCons "CalculateMinUtxoFailed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :+: C1 ('MetaCons "CoinSelectionFailed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))) :+: (C1 ('MetaCons "BalancingError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :+: C1 ('MetaCons "MarloweInputInWithdraw" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "MarloweOutputInWithdraw" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PayoutOutputInWithdraw" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "PayoutInputInCreateOrApply" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "UnknownPayoutScript" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ScriptHash))))))

data MarloweContext v Source #

Data from Marlowe Script needed to solve the constraints.

Constructors

MarloweContext 

Fields

Instances

Instances details
ToJSON (MarloweContext 'V1) Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

Methods

toJSON :: MarloweContext 'V1 -> Value

toEncoding :: MarloweContext 'V1 -> Encoding

toJSONList :: [MarloweContext 'V1] -> Value

toEncodingList :: [MarloweContext 'V1] -> Encoding

Generic (MarloweContext v) Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

Associated Types

type Rep (MarloweContext v) :: Type -> Type Source #

Show (MarloweContext 'V1) Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

type Rep (MarloweContext v) Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

type Rep (MarloweContext v) = D1 ('MetaData "MarloweContext" "Language.Marlowe.Runtime.Transaction.Constraints" "marlowe-runtime-0.0.5-5d7ugYcKzwV3vF5bHET8YQ-tx" 'False) (C1 ('MetaCons "MarloweContext" 'PrefixI 'True) ((S1 ('MetaSel ('Just "scriptOutput") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (TransactionScriptOutput v))) :*: (S1 ('MetaSel ('Just "marloweAddress") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Address) :*: S1 ('MetaSel ('Just "payoutAddress") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Address))) :*: ((S1 ('MetaSel ('Just "marloweScriptUTxO") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReferenceScriptUtxo) :*: S1 ('MetaSel ('Just "payoutScriptUTxO") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReferenceScriptUtxo)) :*: (S1 ('MetaSel ('Just "marloweScriptHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ScriptHash) :*: S1 ('MetaSel ('Just "payoutScriptHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ScriptHash)))))

data PayoutContext Source #

Data from Payout Scripts needed to solve the constraints.

Constructors

PayoutContext 

Fields

  • payoutOutputs :: Map TxOutRef TransactionOutput

    The unspent payout outputs.

  • payoutScriptOutputs :: Map ScriptHash ReferenceScriptUtxo

    The unspent payout reference script outputs indexed by script hash.

Instances

Instances details
Generic PayoutContext Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

Associated Types

type Rep PayoutContext :: Type -> Type Source #

Show PayoutContext Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

Eq PayoutContext Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

type Rep PayoutContext Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

type Rep PayoutContext = D1 ('MetaData "PayoutContext" "Language.Marlowe.Runtime.Transaction.Constraints" "marlowe-runtime-0.0.5-5d7ugYcKzwV3vF5bHET8YQ-tx" 'False) (C1 ('MetaCons "PayoutContext" 'PrefixI 'True) (S1 ('MetaSel ('Just "payoutOutputs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map TxOutRef TransactionOutput)) :*: S1 ('MetaSel ('Just "payoutScriptOutputs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map ScriptHash ReferenceScriptUtxo))))

data MarloweInputConstraints v Source #

Constructors

MarloweInputConstraintsNone 
MarloweInput SlotNo SlotNo (Inputs v) 

data MarloweOutputConstraints v Source #

Constructors

MarloweOutputConstraintsNone 
MarloweOutput Assets (Datum v) 

data RoleTokenConstraints era Source #

Constraints related to role tokens.

Constructors

RoleTokenConstraintsNone 
MintRoleTokens TxOutRef (ScriptWitness WitCtxMint era) (Map AssetId Address) 
SpendRoleTokens (Set AssetId) 

type SolveConstraints = forall era v. ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> MarloweVersion v -> Either (MarloweContext v) PayoutContext -> WalletContext -> TxConstraints era v -> Either ConstraintError (TxBody era) Source #

data TxConstraints era v Source #

Describes a set of Marlowe-specific conditions that a transaction must satisfy.

Constructors

TxConstraints 

Fields

Instances

Instances details
IsMarloweVersion v => Monoid (TxConstraints era v) Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

IsMarloweVersion v => Semigroup (TxConstraints era v) Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

Methods

(<>) :: TxConstraints era v -> TxConstraints era v -> TxConstraints era v Source #

sconcat :: NonEmpty (TxConstraints era v) -> TxConstraints era v Source #

stimes :: Integral b => b -> TxConstraints era v -> TxConstraints era v Source #

Show (TxConstraints era 'V1) Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

Methods

showsPrec :: Int -> TxConstraints era 'V1 -> ShowS Source #

show :: TxConstraints era 'V1 -> String Source #

showList :: [TxConstraints era 'V1] -> ShowS Source #

Eq (TxConstraints era 'V1) Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

Methods

(==) :: TxConstraints era 'V1 -> TxConstraints era 'V1 -> Bool Source #

(/=) :: TxConstraints era 'V1 -> TxConstraints era 'V1 -> Bool Source #

data WalletContext Source #

Data from a wallet needed to solve the constraints.

Constructors

WalletContext 

Fields

Instances

Instances details
ToJSON WalletContext Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

Methods

toJSON :: WalletContext -> Value

toEncoding :: WalletContext -> Encoding

toJSONList :: [WalletContext] -> Value

toEncodingList :: [WalletContext] -> Encoding

Generic WalletContext Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

Associated Types

type Rep WalletContext :: Type -> Type Source #

Show WalletContext Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

type Rep WalletContext Source # 
Instance details

Defined in Language.Marlowe.Runtime.Transaction.Constraints

type Rep WalletContext = D1 ('MetaData "WalletContext" "Language.Marlowe.Runtime.Transaction.Constraints" "marlowe-runtime-0.0.5-5d7ugYcKzwV3vF5bHET8YQ-tx" 'False) (C1 ('MetaCons "WalletContext" 'PrefixI 'True) (S1 ('MetaSel ('Just "availableUtxos") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UTxOs) :*: (S1 ('MetaSel ('Just "collateralUtxos") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set TxOutRef)) :*: S1 ('MetaSel ('Just "changeAddress") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Address))))

adjustTxForMinUtxo :: forall era. IsShelleyBasedEra era => ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> Maybe Address -> TxBodyContent BuildTx era -> Either ConstraintError (TxBodyContent BuildTx era) Source #

balanceTx :: forall era v. IsShelleyBasedEra era => ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> SystemStart -> LedgerEpochInfo -> ProtocolParameters -> MarloweVersion v -> Either (MarloweContext v) PayoutContext -> WalletContext -> TxBodyContent BuildTx era -> Either ConstraintError (TxBody era) Source #

ensureMinUtxo :: forall era. IsShelleyBasedEra era => ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> (Address, Value) -> Either ConstraintError (Address, Value) Source #

Ensure that the minimum UTxO requirement is satisfied for outputs.

findMinUtxo :: forall era. IsShelleyBasedEra era => ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> (Address, Maybe Datum, Value) -> Either ConstraintError Value Source #

Calculate the minimum UTxO requirement for a value. We must pack the address, datum and value into a dummy TxOut along with the "none" reference script in order to use it with C.calculateMinimumUTxO in a subsequent call

mustConsumeMarloweOutput :: IsMarloweVersion v => SlotNo -> SlotNo -> Inputs v -> TxConstraints era v Source #

Require the transaction to consume the UTXO for the current contract from the Marlowe script with the given validity interval and redeemer (input). Used for apply-inputs.

Requires that: 1. The input at the Marlowe Script Address for the contract is consumed. 2. The input in rule 1 includes the given redeemer. 3. The validity range of the transaction matches the given min and max validity bounds. 4. All other inputs do not come from a script address.

mustConsumePayout :: IsMarloweVersion v => TxOutRef -> TxConstraints era v Source #

Require the transaction to consume the given payout transaction output.

Requires that: 1. The output is consumed. 2. The witness for the output is a script witness 3. The script witness specifies a valid payout datum for the correct version 4. The script witness specifies a reference script

mustMintRoleToken :: IsMarloweVersion v => TxOutRef -> ScriptWitness WitCtxMint era -> AssetId -> Address -> TxConstraints era v Source #

Require the transaction to mint 1 role token with the specified assetId and send it to the given address. Additionally, require that the given UTXO is consumed.

Requires that: 1. The transaction mints one token with the given assetId. 2. The transaction sends one token with the given assetId to the given address. 3. The output in rule 2 does not contain any other tokens aside from ADA. 4. The transaction consumes the given TxOutRef.

mustPayToAddress :: IsMarloweVersion v => Assets -> Address -> TxConstraints era v Source #

Require the transaction to send the specified assets to the address.

Requires that: postulate: total :: Address -> TxBody era -> TxOutValue era subValue :: TxOutValue era -> TxOutValue era -> TxOutValue era given: constraints :: TxConstraints v assets :: Assets address :: Address define: payConstraint = mustPayToAddress assets address Right txBody = solveConstraints $ constraints <> payConstraint Right txBody' = solveConstraints constraints 1. fromCardano (total address txBody subValue total address txBody') == assets

mustPayToRole :: IsMarloweVersion v => Assets -> PayoutDatum v -> TxConstraints era v Source #

Require the transaction to send an output to the payout script address with the given assets and the given datum.

Requires that: postulate: total :: PayoutDatum v -> TxBody era -> TxOutValue era subValue :: TxOutValue era -> TxOutValue era -> TxOutValue era given: constraints :: TxConstraints v assets :: Assets role :: PayoutDatum v define: payConstraint = mustPayToRole assets role Right txBody = solveConstraints $ constraints <> payConstraint Right txBody' = solveConstraints constraints 1. fromCardano (total role txBody subValue total role txBody') == assets 2. The transaction sends an output to a script address. 3. The datum of the output in rule 2 is equal to the role.

mustSendMarloweOutput :: IsMarloweVersion v => Assets -> Datum v -> TxConstraints era v Source #

Require the transaction to send an output to the marlowe script address with the given assets and the given datum.

Requires that: 1. The transaction sends an output with the given assets and datum to a script address. 2. The script address in rule 1 is in the script address set for the corresponding Marlowe version.

mustSpendRoleToken :: IsMarloweVersion v => AssetId -> TxConstraints era v Source #

Require the transaction to spend a UTXO with 1 role token of the specified assetID. It also needs to send an identical output (same assets) to the address that held the spent UTXO.

Requires that: 1. The transaction consumes a UTXO that contains the necessary role token. 2. The transaction produces an output that is identical to the output from rule 1.

requiresMetadata :: IsMarloweVersion v => MarloweTransactionMetadata -> TxConstraints era v Source #

Require the transaction include the given metadata.

Requires that: 1. The given metadata map is present in the transaction.

requiresSignature :: IsMarloweVersion v => PaymentKeyHash -> TxConstraints era v Source #

Require the transaction to hold a signature for the given payment key hash.

Requires that: 1. If none of the inputs are from an address withe a matching payment key, then the txExtraKeyWits of the body content contain the given hash. 2. If theExtraKeyWits of the body content does not contain the given hash, then at least one input must be from an address with a matching payment key.

selectCoins :: forall era v. IsShelleyBasedEra era => ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> MarloweVersion v -> Either (MarloweContext v) PayoutContext -> WalletContext -> TxBodyContent BuildTx era -> Either ConstraintError (TxBodyContent BuildTx era) Source #

solveConstraints :: SystemStart -> LedgerEpochInfo -> ProtocolParameters -> SolveConstraints Source #

Given a set of constraints and the context of a wallet, produces a balanced, unsigned transaction that satisfies the constraints.

solveInitialTxBodyContent :: forall era v. ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> MarloweVersion v -> Either (MarloweContext v) PayoutContext -> WalletContext -> TxConstraints era v -> Either ConstraintError (TxBodyContent BuildTx era) Source #