Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Language.Marlowe.Runtime.Transaction.Constraints
Synopsis
- data ConstraintError
- = MintingUtxoNotFound TxOutRef
- | RoleTokenNotFound AssetId
- | ToCardanoError
- | MissingMarloweInput
- | PayoutNotFound TxOutRef
- | InvalidPayoutDatum TxOutRef (Maybe Datum)
- | InvalidPayoutScriptAddress TxOutRef Address
- | CalculateMinUtxoFailed String
- | CoinSelectionFailed String
- | BalancingError String
- | MarloweInputInWithdraw
- | MarloweOutputInWithdraw
- | PayoutOutputInWithdraw
- | PayoutInputInCreateOrApply
- | UnknownPayoutScript ScriptHash
- data MarloweContext v = MarloweContext {
- scriptOutput :: Maybe (TransactionScriptOutput v)
- marloweAddress :: Address
- payoutAddress :: Address
- marloweScriptUTxO :: ReferenceScriptUtxo
- payoutScriptUTxO :: ReferenceScriptUtxo
- marloweScriptHash :: ScriptHash
- payoutScriptHash :: ScriptHash
- data PayoutContext = PayoutContext {
- payoutOutputs :: Map TxOutRef TransactionOutput
- payoutScriptOutputs :: Map ScriptHash ReferenceScriptUtxo
- data MarloweInputConstraints v
- = MarloweInputConstraintsNone
- | MarloweInput SlotNo SlotNo (Inputs v)
- data MarloweOutputConstraints v
- = MarloweOutputConstraintsNone
- | MarloweOutput Assets (Datum v)
- data RoleTokenConstraints era
- = 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)
- data TxConstraints era v = TxConstraints {
- marloweInputConstraints :: MarloweInputConstraints v
- payoutInputConstraints :: Set TxOutRef
- roleTokenConstraints :: RoleTokenConstraints era
- payToAddresses :: Map Address Assets
- payToRoles :: Map (PayoutDatum v) Assets
- marloweOutputConstraints :: MarloweOutputConstraints v
- signatureConstraints :: Set PaymentKeyHash
- metadataConstraints :: MarloweTransactionMetadata
- data WalletContext = WalletContext {
- availableUtxos :: UTxOs
- collateralUtxos :: Set TxOutRef
- changeAddress :: Address
- adjustTxForMinUtxo :: forall era. IsShelleyBasedEra era => ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> Maybe Address -> TxBodyContent BuildTx era -> Either ConstraintError (TxBodyContent BuildTx era)
- 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)
- ensureMinUtxo :: forall era. IsShelleyBasedEra era => ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> (Address, Value) -> Either ConstraintError (Address, Value)
- findMinUtxo :: forall era. IsShelleyBasedEra era => ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> (Address, Maybe Datum, Value) -> Either ConstraintError Value
- mustConsumeMarloweOutput :: IsMarloweVersion v => SlotNo -> SlotNo -> Inputs v -> TxConstraints era v
- mustConsumePayout :: IsMarloweVersion v => TxOutRef -> TxConstraints era v
- mustMintRoleToken :: IsMarloweVersion v => TxOutRef -> ScriptWitness WitCtxMint era -> AssetId -> Address -> TxConstraints era v
- mustPayToAddress :: IsMarloweVersion v => Assets -> Address -> TxConstraints era v
- mustPayToRole :: IsMarloweVersion v => Assets -> PayoutDatum v -> TxConstraints era v
- mustSendMarloweOutput :: IsMarloweVersion v => Assets -> Datum v -> TxConstraints era v
- mustSpendRoleToken :: IsMarloweVersion v => AssetId -> TxConstraints era v
- requiresMetadata :: IsMarloweVersion v => MarloweTransactionMetadata -> TxConstraints era v
- requiresSignature :: IsMarloweVersion v => PaymentKeyHash -> TxConstraints era v
- selectCoins :: forall era v. IsShelleyBasedEra era => ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> MarloweVersion v -> Either (MarloweContext v) PayoutContext -> WalletContext -> TxBodyContent BuildTx era -> Either ConstraintError (TxBodyContent BuildTx era)
- solveConstraints :: SystemStart -> LedgerEpochInfo -> ProtocolParameters -> SolveConstraints
- solveInitialTxBodyContent :: forall era v. ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> ProtocolParameters -> MarloweVersion v -> Either (MarloweContext v) PayoutContext -> WalletContext -> TxConstraints era v -> Either ConstraintError (TxBodyContent BuildTx era)
Documentation
data ConstraintError #
Constructors
MintingUtxoNotFound TxOutRef | |
RoleTokenNotFound AssetId | |
ToCardanoError | |
MissingMarloweInput | |
PayoutNotFound TxOutRef | |
InvalidPayoutDatum TxOutRef (Maybe Datum) | |
InvalidPayoutScriptAddress TxOutRef Address | |
CalculateMinUtxoFailed String | |
CoinSelectionFailed String | |
BalancingError String | |
MarloweInputInWithdraw | |
MarloweOutputInWithdraw | |
PayoutOutputInWithdraw | |
PayoutInputInCreateOrApply | |
UnknownPayoutScript ScriptHash |
Instances
data MarloweContext v Source #
Data from Marlowe Script needed to solve the constraints.
Constructors
MarloweContext | |
Fields
|
Instances
data PayoutContext Source #
Data from Payout Scripts needed to solve the constraints.
Constructors
PayoutContext | |
Fields
|
Instances
data MarloweInputConstraints v Source #
Constructors
MarloweInputConstraintsNone | |
MarloweInput SlotNo SlotNo (Inputs v) |
Instances
data MarloweOutputConstraints v Source #
Constructors
MarloweOutputConstraintsNone | |
MarloweOutput Assets (Datum v) |
Instances
data RoleTokenConstraints era Source #
Constraints related to role tokens.
Constructors
RoleTokenConstraintsNone | |
MintRoleTokens TxOutRef (ScriptWitness WitCtxMint era) (Map AssetId Address) | |
SpendRoleTokens (Set AssetId) |
Instances
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
IsMarloweVersion v => Monoid (TxConstraints era v) Source # | |
Defined in Language.Marlowe.Runtime.Transaction.Constraints Methods mempty :: TxConstraints era v Source # mappend :: TxConstraints era v -> TxConstraints era v -> TxConstraints era v Source # mconcat :: [TxConstraints era v] -> TxConstraints era v Source # | |
IsMarloweVersion v => Semigroup (TxConstraints era v) Source # | |
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 # | |
Eq (TxConstraints era 'V1) Source # | |
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
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 #