cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.Skeleton.Mint

Synopsis

Documentation

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

Orphan instances

Monoid TxSkelMints Source # 
Instance details

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