types/token
A Token is a safe type for some asset on Cardano. A Token can be combined
with another Token to form Tokens, a list of Token. This should be a safe
and clean way to build out the assets type inside of datums and redeemers
instead of building out the Assets type directly which could be harmful.
Types
A token type for a safe single policy id and asset name assets.
Constructors
-
Token { pid: PolicyId, tkn: AssetName, amt: Int }
A tokens type for a safe value as a list of Tokens.
Alias
Tokens = List<Token>
Functions
Negate all the tokens in the list. The order of the list is preserved.
token.negate(these_tokens)
Divide a token by some integer. The divisor must be positive. This is integer division so the token amount will be rounded towards negative infinity.
token.divide(that_token, 2)
Multiply a token by some integer. This linearly scales the token amount on the token.
token.multiply(that_token, 4)
Check that each token is less than zero in a list tokens. An empty list returns True.
token.subtraction_only(redeemer.tokens)
Check that each token is greater than zero in a list tokens. An empty list returns True.
token.addition_only(redeemer.tokens)
Add a Token type to an Assets type. This should be a very safe way to
increment a value on a UTxO. The other option is having the redeemer be
the general Assets type and potentially allow badly formed values to be
used.
token.add_token_to_value(this_value, token)
Add a list of Token types to an Assets type. This should be a very safe
way to increment a value on a UTxO. The other option is having the redeemer
be the general Assets type and potentially allow badly formed values to
be used.
token.add_tokens_to_value(this_value, redeemer.tokens)
Convert an Assets into a list of tokens. The tokens are listed in
descending policy id and asset name order. This conversion is a fast way
to be able to do multiplication on a value.
token.from_value(this_value)
Check if a Token exists in a list of Tokens. The amount has to be greater than or equal to the target.
token.exists(total_tokens, target_token)