cooked-validators-4.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.Skeleton

Description

This module provides the description of a transaction skeleton. We have our own representation of a transaction for three main reasons:

  • our transaction skeletons are typed (datums, validators, outputs...)
  • with our own wrapper, we are less affected by plutus updates
  • we can have default or automated behavior for the parts of the transactions that are less relevant to testing, such as collaterals or fees
Synopsis

Documentation

type LabelConstrs x = (PrettyCooked x, Show x, Typeable x, Eq x, Ord x) Source #

data TxLabel where Source #

Constructors

TxLabel :: LabelConstrs x => x -> TxLabel 

Instances

Instances details
Show TxLabel Source # 
Instance details

Defined in Cooked.Skeleton

PrettyCooked TxLabel Source # 
Instance details

Defined in Cooked.Skeleton

Eq TxLabel Source # 
Instance details

Defined in Cooked.Skeleton

Methods

(==) :: TxLabel -> TxLabel -> Bool #

(/=) :: TxLabel -> TxLabel -> Bool #

Ord TxLabel Source # 
Instance details

Defined in Cooked.Skeleton

data BalanceOutputPolicy Source #

Whether to adjust a potentially existing output to the balancing wallet with the change during transaction balancing.

Constructors

AdjustExistingOutput

Try to adjust an existing public key output with the change. If no suitable output can be found, create a new change output.

DontAdjustExistingOutput

Do not change the existing outputs, always create a new change output.

data FeePolicy Source #

What fee policy to use in the transaction.

Constructors

AutoFeeComputation

Use automatic fee computation. If balancing is activated, an optimal fee will be computed based on the transaction and existing utxos in the balancing wallet. Otherwise, the maximum transaction fee will be applied.

ManualFee Integer

Provide a fee to the transaction. If the autobalancing is activated, it will be attempted around this fee, which might lead to failure if it is too low, otherwise, this fee will be given to transaction generation.

Instances

Instances details
Show FeePolicy Source # 
Instance details

Defined in Cooked.Skeleton

Default FeePolicy Source # 
Instance details

Defined in Cooked.Skeleton

Methods

def :: FeePolicy #

Eq FeePolicy Source # 
Instance details

Defined in Cooked.Skeleton

Ord FeePolicy Source # 
Instance details

Defined in Cooked.Skeleton

data BalancingPolicy Source #

Whether to balance the transaction or not, and which wallet to use to provide outputs for balancing. Either the first signer or an explicit wallet. In the second case, this wallet must be a signer of the transaction.

data BalancingUtxos Source #

Which UTxOs to use when balancing. Note that utxos that are already known by the skeleton being balanced (in the sense of txSkelKnownTxOutRefs, i.e. inputs and reference inputs) will be filtered out during balancing.

Constructors

BalancingUtxosFromBalancingWallet

Use all UTxOs containing only a Value (no datum, no staking credential, and no reference script) belonging to the balancing wallet.

BalancingUtxosFromSet (Set TxOutRef)

Use the provided UTxOs. UTxOs belonging to scripts will be filtered out

newtype RawModTx Source #

Wraps a function that will be applied to a transaction right before submission, and after balancing.

Instances

Instances details
Show RawModTx Source # 
Instance details

Defined in Cooked.Skeleton

Eq RawModTx Source # 
Instance details

Defined in Cooked.Skeleton

newtype EmulatorParamsModification Source #

Wraps a function that will temporarily change the emulator parameters for the transaction's balancing and submission.

data CollateralUtxos Source #

Describe which UTxOs to use as collaterals

Constructors

CollateralUtxosFromBalancingWallet

Rely on automated computation with only-value UTxOs from the balancing wallet. Return collaterals will be sent to this wallet.

CollateralUtxosFromWallet Wallet

Rely on automated computation with only-value UTxOs from a given wallet. Return collaterals will be sent to this wallet.

CollateralUtxosFromSet (Set TxOutRef) Wallet

Manually provide a set of candidate UTxOs to be used as collaterals alongside a wallet to send return collaterals back to.

Instances

Instances details
Show CollateralUtxos Source # 
Instance details

Defined in Cooked.Skeleton

Default CollateralUtxos Source # 
Instance details

Defined in Cooked.Skeleton

Eq CollateralUtxos Source # 
Instance details

Defined in Cooked.Skeleton

data AnchorResolution Source #

Describes how to resolve anchors in proposal procedures

Constructors

AnchorResolutionLocal (Map String ByteString)

Provide a map between urls and page content as Bytestring

AnchorResolutionHttp

Allow online fetch of pages from a given URL. Important note: using this option is unsafe, as it requires a web connection and inherently prevents guarantees of reproducibily. Use at your own discretion.

applyRawModOnBalancedTx :: [RawModTx] -> Tx ConwayEra -> Tx ConwayEra Source #

Applies a list of modifications right before the transaction is submitted. The leftmost function in the argument list is applied first.

data TxOpts Source #

Set of options to modify the behavior of generating and validating some transaction.

Constructors

TxOpts 

Fields

  • txOptEnsureMinAda :: Bool

    Performs an adjustment to unbalanced transactions, making sure every UTxO that is produced has the necessary minimum amount of Ada.

    Default is False.

  • txOptAutoSlotIncrease :: Bool

    Whether to increase the slot counter automatically on transaction submission. This is useful for modelling transactions that could be submitted in parallel in reality, so there should be no explicit ordering of what comes first.

    Default is True.

  • txOptUnsafeModTx :: [RawModTx]

    Applies an arbitrary modification to a transaction after it has been potentially adjusted (txOptEnsureMinAda) and balanced. The name of this option contains unsafe to draw attention to the fact that modifying a transaction at that stage might make it invalid. Still, this offers a hook for being able to alter a transaction in unforeseen ways. It is mostly used to test contracts that have been written for custom PABs.

    One interesting use of this function is to observe a transaction just before it is being sent for validation, with

    txOptUnsafeModTx = [RawModTxAfterBalancing Debug.Trace.traceShowId]

    The leftmost function in the list is applied first.

    Default is [].

  • txOptBalancingPolicy :: BalancingPolicy

    Whether to balance the transaction or not, and which wallet should provide/reclaim the missing and surplus value. Balancing ensures that

    input + mints == output + fees + burns

    If you decide to set txOptBalance = DoNotBalance you will have trouble satisfying that equation by hand unless you use ManualFee. You will likely see a error about value preservation.

    Default is BalanceWithFirstSigner

  • txOptFeePolicy :: FeePolicy

    The fee to use when balancing the transaction

    Default is AutomaticFeeComputation

  • txOptBalanceOutputPolicy :: BalanceOutputPolicy

    The BalanceOutputPolicy to apply when balancing the transaction.

    Default is AdjustExistingOutput.

  • txOptBalancingUtxos :: BalancingUtxos

    Which UTxOs to use during balancing. This can either be a precise list, or rely on automatic searches for utxos with values only belonging to the balancing wallet.

    Default is BalancingUtxosFromBalancingWallet.

  • txOptEmulatorParamsModification :: Maybe EmulatorParamsModification

    Apply an arbitrary modification to the protocol parameters that are used to balance and submit the transaction. This is obviously a very unsafe thing to do if you want to preserve compatibility with the actual chain. It is useful mainly for testing purposes, when you might want to use extremely big transactions or transactions that exhaust the maximum execution budget. Such a thing could be accomplished with

    txOptEmulatorParamsModification = Just $ EmulatorParamsModification increaseTransactionLimits

    for example.

    Default is Nothing.

  • txOptCollateralUtxos :: CollateralUtxos

    Which utxos to use as collaterals. They can be given manually, or computed automatically from a given, or the balancing, wallet.

    Default is CollateralUtxosFromBalancingWallet

  • txOptAnchorResolution :: AnchorResolution

    How to resolve anchor in proposal procedures

    Default is 'AnchorResolutionLocal Map.Empty'

  • txOptAutoReferenceScripts :: Bool

    Whether to automatically fill up reference inputs in redeemers when they contain the right reference script. This will imply going through all the known utxos with reference scripts and compare their hashes, thus will slightly reduce performance.

    Defaut is False.

Instances

Instances details
Show TxOpts Source # 
Instance details

Defined in Cooked.Skeleton

Default TxOpts Source # 
Instance details

Defined in Cooked.Skeleton

Methods

def :: TxOpts #

Eq TxOpts Source # 
Instance details

Defined in Cooked.Skeleton

Methods

(==) :: TxOpts -> TxOpts -> Bool #

(/=) :: TxOpts -> TxOpts -> Bool #

type TxSkelMints = Map (Versioned MintingPolicy) (TxSkelRedeemer, NEMap TokenName (NonZero Integer)) Source #

A description of what a transaction mints. For every policy, there can only be one TxSkelRedeemer, and if there is, there must be some token names, each with a non-zero amount of tokens.

You'll probably not construct this by hand, but use txSkelMintsFromList.

addToTxSkelMints :: (Versioned MintingPolicy, TxSkelRedeemer, TokenName, Integer) -> TxSkelMints -> TxSkelMints Source #

Add a new entry to a TxSkelMints. There are a few wrinkles:

  1. If for a given policy, redeemer, and token name, there are n tokens in the argument TxSkelMints, and you add -n tokens, the corresponding entry in the "inner map" of the policy will disappear (obviously, because all of its values have to be non-zero). If that also means that the inner map becomes empty, the policy will disappear from the TxSkelMints altogether.
  2. If a policy is already present on the argument TxSkelMints with a redeemer a, and you add a mint with a different redeemer b, the old redeemer is thrown away. The values associated with the token names of that policy are added as described above, though. This means that any pre-existing values will be minted with a new redeemer.

If, for some reason, you really want to generate a TxSkelMints that has both a negative and a positive entry of the same asset class and redeemer, you'll have to do so manually. Note, however, that even if you do so, NO VALIDATOR OR MINTING POLICY WILL EVER GET TO SEE A TRANSACTION WITH SUCH CONFLICTING INFORMATION. This is not a design decision/limitation of cooked-validators: The Cardano API TxBodyContent type, that we're translating everything into eventually, stores minting information as a minted value together with a map from policy IDs to witnesses (which represent the used redeemers). That means that we can only store _one_ redeemer per minting policy, and no conflicting mints of the same asset class, since they'll just cancel.

txSkelMintsToList :: TxSkelMints -> [(Versioned MintingPolicy, TxSkelRedeemer, TokenName, Integer)] Source #

Convert from TxSkelMints to a list of tuples describing eveything that's being minted.

txSkelMintsFromList :: [(Versioned MintingPolicy, TxSkelRedeemer, TokenName, Integer)] -> TxSkelMints Source #

Smart constructor for TxSkelMints. This function relies on addToTxSkelMints. So, some non-empty lists (where all amounts for a given asset class an redeemer add up to zero) might be translated into the empty TxSkelMints.

txSkelMintsFromList' :: [(Versioned MintingPolicy, TxSkelRedeemer, [(TokenName, Integer)])] -> TxSkelMints Source #

Another smart constructor for TxSkelMints, where the redeemer and minting policies are not duplicated.

txSkelMintsValue :: TxSkelMints -> Value Source #

The value described by a TxSkelMints

data TxSkelOutDatum where Source #

On transaction outputs, we have the options to use

  1. no datum
  2. only a datum hash
  3. a "normal" datum
  4. an inline datum

These four options are also what the type TxSkelOutDatum records. The following table explains their differences.

datum stored in in the simulated chain state datum resolved on the txInfoDataOutputDatum constructor seen by the validator
TxSkelOutNoDatumnonoNoOutputDatum
TxSkelOutDatumHashyesnoOutputDatumHash
TxSkelOutDatumyesyesOutputDatumHash
TxSkelOutInlineDatumyesnoOutputDatum

That is:

  • Whenever there is a datum, we'll store it in the state of our simulated chain. This will make it possible to retrieve it later, using functions such as datumFromHash.
  • Both of the TxSkelOutDatumHash and TxSkelOutDatum constructors will create an output that scripts see on the txInfo as having a datum hash. The difference is whether that hash will be resolvable using validator functions like findDatum.

Constructors

TxSkelOutNoDatum :: TxSkelOutDatum

use no datum

TxSkelOutDatumHash :: TxSkelOutDatumConstrs a => a -> TxSkelOutDatum

only include the hash on the transaction

TxSkelOutDatum :: TxSkelOutDatumConstrs a => a -> TxSkelOutDatum

use a OutputDatumHash on the transaction output, but generate the transaction in such a way that the complete datum is included in the txInfoData seen by validators

TxSkelOutInlineDatum :: TxSkelOutDatumConstrs a => a -> TxSkelOutDatum

use an inline datum

data TxSkelOut where Source #

Transaction outputs. The Pays constructor is really general, and you'll probably want to use one of the smart constructors like paysScript or paysPK in most cases.

paysPK :: ToPubKeyHash a => a -> Value -> TxSkelOut Source #

Pay a certain value to a public key.

paysScript :: (ToData (DatumType a), Show (DatumType a), Typeable (DatumType a), Eq (DatumType a), PrettyCooked (DatumType a), Typeable a) => TypedValidator a -> DatumType a -> Value -> TxSkelOut Source #

Pays a script a certain value with a certain datum hash, using the TxSkelOutDatum constructor. The resolved datum is provided in the body of the transaction that issues the payment.

paysScriptInlineDatum :: (ToData (DatumType a), Show (DatumType a), Typeable (DatumType a), Eq (DatumType a), PrettyCooked (DatumType a), Typeable a) => TypedValidator a -> DatumType a -> Value -> TxSkelOut Source #

Pays a script a certain value with a certain inlined datum.

paysScriptUnresolvedDatumHash :: (ToData (DatumType a), Show (DatumType a), Typeable (DatumType a), Eq (DatumType a), PrettyCooked (DatumType a), Typeable a) => TypedValidator a -> DatumType a -> Value -> TxSkelOut Source #

Pays a script a certain value with a certain hashed datum, whose resolved datum is not provided in the transaction body that issues the payment (as opposed to "paysScript").

paysScriptNoDatum :: Typeable a => TypedValidator a -> Value -> TxSkelOut Source #

Pays a script a certain value without any datum. Intended to be used with withDatum, withUnresolvedDatumHash, or withInlineDatum to try a datum whose type does not match the validator's.

withDatum :: (ToData a, Show a, Typeable a, Eq a, PrettyCooked a) => TxSkelOut -> a -> TxSkelOut Source #

Set the datum in a payment to the given datum (whose type may not fit the typed validator in case of a script).

withInlineDatum :: (ToData a, Show a, Typeable a, Eq a, PrettyCooked a) => TxSkelOut -> a -> TxSkelOut Source #

Set the datum in a payment to the given inlined datum (whose type may not fit the typed validator in case of a script).

withUnresolvedDatumHash :: (ToData a, Show a, Typeable a, Eq a, PrettyCooked a) => TxSkelOut -> a -> TxSkelOut Source #

Set the datum in a payment to the given hashed (not resolved in the transaction) datum (whose type may not fit the typed validator in case of a script).

withReferenceScript :: (Show script, ToVersionedScript script, Typeable script, ToScriptHash script) => TxSkelOut -> script -> TxSkelOut Source #

Add a reference script to a transaction output (or replace it if there is already one)

withStakingCredential :: TxSkelOut -> StakingCredential -> TxSkelOut Source #

Add a staking credential to a transaction output (or replace it if there is already one)

data TxSkelRedeemer Source #

Instances

Instances details
Monoid DoubleSatDelta Source # 
Instance details

Defined in Cooked.Attack.DoubleSat

Monoid TxSkelMints Source # 
Instance details

Defined in Cooked.Skeleton

Semigroup DoubleSatDelta Source # 
Instance details

Defined in Cooked.Attack.DoubleSat

Semigroup TxSkelMints Source #

Combining TxSkelMints in a sensible way. In particular, this means that

Map.fromList [(pol, (red, NEMap.fromList [(tName, 1)]))]

and

Map.fromList [(pol, (red', NEMap.fromList [(tName, -1)]))]

will combine to become the empty TxSkelMints (and similar examples, where the values add up to zero, see the comment at the definition of addToTxSkelMints).

In every case, if you add mints with a different redeemer for the same policy, the redeemer used in the right argument takes precedence.

Instance details

Defined in Cooked.Skeleton

Show TxSkelRedeemer Source # 
Instance details

Defined in Cooked.Skeleton

Eq TxSkelRedeemer Source # 
Instance details

Defined in Cooked.Skeleton

data Redeemer where Source #

Constructors

EmptyRedeemer :: Redeemer 
SomeRedeemer :: RedeemerConstrs redeemer => redeemer -> Redeemer 

Instances

Instances details
Show Redeemer Source # 
Instance details

Defined in Cooked.Skeleton

Eq Redeemer Source # 
Instance details

Defined in Cooked.Skeleton

data TxParameterChange where Source #

Constructors

FeePerByte :: Integer -> TxParameterChange

The linear factor for the minimum fee calculation

FeeFixed :: Integer -> TxParameterChange

The constant factor for the minimum fee calculation

MaxBlockBodySize :: Integer -> TxParameterChange

Maximal block body size

MaxTxSize :: Integer -> TxParameterChange

Maximal transaction size

MaxBlockHeaderSize :: Integer -> TxParameterChange

Maximal block header size

KeyDeposit :: Integer -> TxParameterChange

The amount of a key registration deposit

PoolDeposit :: Integer -> TxParameterChange

The amount of a pool registration deposit

PoolRetirementMaxEpoch :: Integer -> TxParameterChange

Maximum number of epochs in the future a pool retirement is allowed to be scheduled future for.

PoolNumber :: Integer -> TxParameterChange

Desired number of pools

PoolInfluence :: Rational -> TxParameterChange

Pool influence

MonetaryExpansion :: Rational -> TxParameterChange

Monetary expansion

TreasuryCut :: Rational -> TxParameterChange

Treasury expansion

MinPoolCost :: Integer -> TxParameterChange

Minimum Stake Pool Cost

CoinsPerUTxOByte :: Integer -> TxParameterChange

Cost in lovelace per byte of UTxO storage

CostModels

Cost models for non-native script languages

Fields

Prices

Prices of execution units

Fields

MaxTxExUnits

Max total script execution resources units allowed per tx

Fields

MaxBlockExUnits

Max total script execution resources units allowed per block

Fields

MaxValSize :: Integer -> TxParameterChange

Max size of a Value in an output

CollateralPercentage :: Integer -> TxParameterChange

Percentage of the txfee which must be provided as collateral when including non-native scripts.

MaxCollateralInputs :: Integer -> TxParameterChange

Maximum number of collateral inputs allowed in a transaction

PoolVotingThresholds

Thresholds for pool votes

DRepVotingThresholds

Thresholds for DRep votes

CommitteeMinSize :: Integer -> TxParameterChange

Minimum size of the Constitutional Committee

CommitteeMaxTermLength :: Integer -> TxParameterChange

The Constitutional Committee Term limit in number of Slots

GovActionLifetime :: Integer -> TxParameterChange

Gov action lifetime in number of Epochs

GovActionDeposit :: Integer -> TxParameterChange

The amount of the Gov Action deposit

DRepRegistrationDeposit :: Integer -> TxParameterChange

The amount of a DRep registration deposit

DRepActivity :: Integer -> TxParameterChange

The number of Epochs that a DRep can perform no activity without losing their Active status.

data TxSkelProposal where Source #

Constructors

TxSkelProposal 

Fields

Instances

Instances details
Show TxSkelProposal Source # 
Instance details

Defined in Cooked.Skeleton

Eq TxSkelProposal Source # 
Instance details

Defined in Cooked.Skeleton

type TxSkelWithdrawals = Map (Either (Versioned Script) PubKeyHash) (TxSkelRedeemer, Ada) Source #

Withdrawals associate either a script or a private key with a redeemer and a certain amount of ada. Note that the redeemer will be ignored in the case of a private key.

data TxSkel where Source #

Constructors

TxSkel 

Fields

  • :: { txSkelLabel :: Set TxLabel

    Labels do not influence the transaction generation at all; they are pretty-printed whenever cooked-validators prints a transaction, and can therefore make the output more informative (and greppable).

  •    , txSkelOpts :: TxOpts

    Some options that control transaction generation.

  •    , txSkelMints :: TxSkelMints

    Any value minted or burned by the transaction. You'll probably want to use txSkelMintsFromList to construct this.

  •    , txSkelSigners :: [Wallet]

    The wallets signing the transaction. This list must contain at least one element. By default, the first signer will pay for fees and balancing. You can change that with txOptBalanceWallet.

  •    , txSkelValidityRange :: SlotRange
     
  •    , txSkelIns :: Map TxOutRef TxSkelRedeemer

    To each TxOutRef the transaction should consume, add a redeemer specifying how to spend it. You must make sure that

    • On TxOutRefs referencing UTxOs belonging to public keys, you use the emptyTxSkelRedeemer smart constructor.
    • On TxOutRefs referencing UTxOs belonging to scripts, you must make sure that the type of the redeemer is appropriate for the script.
  •    , txSkelInsReference :: Set TxOutRef

    All outputs referenced by the transaction.

  •    , txSkelOuts :: [TxSkelOut]

    The outputs of the transaction. These will occur in exactly this order on the transaction.

  •    , txSkelProposals :: [TxSkelProposal]

    Possible proposals issued in this transaction to be voted on and possible enacted later on.

  •    , txSkelWithdrawals :: TxSkelWithdrawals

    Withdrawals performed by the transaction

  •    } -> TxSkel
     

Instances

Instances details
Show TxSkel Source # 
Instance details

Defined in Cooked.Skeleton

Eq TxSkel Source # 
Instance details

Defined in Cooked.Skeleton

Methods

(==) :: TxSkel -> TxSkel -> Bool #

(/=) :: TxSkel -> TxSkel -> Bool #

MonadBlockChainWithoutValidation m => MonadTweak (Tweak m) Source # 
Instance details

Defined in Cooked.Tweak.Common

txSkelTemplate :: TxSkel Source #

A convenience template of an empty transaction skeleton.

txSkelDataInOutputs :: TxSkel -> [(DatumHash, TxSkelOutDatum)] Source #

Return all data on transaction outputs. This can contain duplicates, which is intended.

txSkelValidatorsInOutputs :: TxSkel -> Map ValidatorHash (Versioned Validator) Source #

All validators which will receive transaction outputs

txSkelOutOwnerTypeP :: forall ownerType. (ToCredential ownerType, Show ownerType, IsTxSkelOutAllowedOwner ownerType, Typeable ownerType) => Prism' TxSkelOut (ConcreteOutput ownerType TxSkelOutDatum Value (Versioned Script)) Source #

Decide if a transaction output has a certain owner and datum type.

data SkelContext Source #

The missing information on a TxSkel that can only be resolved by querying the state of the blockchain.

txSkelKnownTxOutRefs :: TxSkel -> [TxOutRef] Source #

All TxOutRefs known by a given transaction skeleton. This includes TxOutRef`s used as inputs of the skeleton and TxOutRefs used as reference inputs of the skeleton. This does not include additional possible TxOutRefs used for balancing and additional TxOutRefs used as collateral inputs, as they are not part of the skeleton.

txSkelValueInOutputs :: TxSkel -> Value Source #

Returns the full value contained in the skeleton outputs

txSkelReferenceScripts :: TxSkel -> Map ValidatorHash (Versioned Validator) Source #

All validators in the reference script field of transaction outputs

txSkelReferenceTxOutRefs :: TxSkel -> [TxOutRef] Source #

All TxOutRefs in reference inputs

someTxSkelRedeemer :: RedeemerConstrs redeemer => redeemer -> TxSkelRedeemer Source #