cardano/values
This module contains code that aids in various value manipulations and comparisons.
Everything here operates on the stdlib Assets type, which is the
multi-asset map found on transaction inputs, outputs, and the mint field.
stdlib v4 renamed the old Value type to Assets; the name Value now
refers to the builtin UPLC value handled by stdlib’s cardano/value.
This module used to be called cardano/value. It was renamed to
cardano/values because stdlib v4 now ships its own cardano/value.
Functions
Creates an Assets from a list of tokens. Quantities of tokens that share
a policy id and asset name are summed.
values.from_tokens(redeemer.tokens)
Multiply some value by n. This is a linear scaling of the quantity of
each token. Multiplying by zero returns assets.zero.
For the builtin
Valuetype, stdlib providescardano/value.{scale}.
values.multiply(bundle_value, bundle_size)
Prove that the target value is contained inside another value. Each token inside the target must exist inside the total value. The quantity of each token must be at least the target amount or greater. A negative target quantity is always satisfied.
For the builtin
Valuetype, stdlib providescardano/value.{contains}. That version fails on negative quantities.
values.contains(total_value, target_value)
Compute the blake2b_256 hash of a value by merklizing the policy id, asset name, and quantity. Empty values return the empty bytearray.
The assets are folded in ascending policy id and asset name order. Each
step computes blake2b_256(pid ++ tkn ++ blake2b_256(string(amt)) ++ acc).
values.compute_hash(validating_value)
unique_token_name(
txid: TransactionId,
idx: Int,
prefix: ByteArray,
personal: ByteArray,
) -> AssetName
Calculate a unique token name from a TxId#Idx, a prefix, and a personal
tag. Can be combined with the find module to create unique token names
from the first input utxo inside the transaction.
The name is prefix ++ personal[0..15] ++ index ++ txid, truncated to 32
bytes. An index below 256 is encoded as one byte. A larger index is encoded
as its minimal big-endian bytes. A negative index fails.
values.unique_token_name(tx_id, tx_idx, cip68.prefix_333, personal_tag)
Proves that inside some value there is a policy id with a single token name that has a quantity of 1. Other policies are tolerated. This will show that a value contains an NFT or something that is nft-like. Should be useful to prove that something is holding a token inside a transaction when the token name is assumed to be unique.
This sits between stdlib’s
assets.has_any_nft(tolerates other names under the policy) andassets.has_any_nft_strict(tolerates nothing besides Ada).
values.prove_nft(this_value, pid)