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 value type inside of datums and redeemers instead of building out the value 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
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.
token.subtraction_only(redeemer.tokens)
Check that each token is greater than zero in a list tokens.
token.addition_only(redeemer.tokens)
Add a Token type to a Value 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 Value type and potentially allow badly formed values to be used.
add_token_to_value(token, this_value)
Add a list of Token types to a Value 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 Value type and potentially allow badly formed values to be used.
add_tokens_to_value(redeemer.tokens, this_value)
Convert a value into a list of tokens. This conversation is a fast way to be able to do multiplication on a assets.
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 )