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

negative(tkn: Token) -> Token

Give the negative of a token.

token.negative(this_token)

negate(tokens: Tokens) -> Tokens

Negate all the tokens in the list. The order of the list is preserved.

token.negate(these_tokens)

divide(token: Token, n: Int) -> Token

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(token: Token, n: Int) -> Token

Multiply a token by some integer. This linearly scales the token amount on the token.

token.multiply(that_token, 4)

subtraction_only(tokens: Tokens) -> Bool

Check that each token is less than zero in a list tokens. An empty list returns True.

token.subtraction_only(redeemer.tokens)

addition_only(tokens: Tokens) -> Bool

Check that each token is greater than zero in a list tokens. An empty list returns True.

token.addition_only(redeemer.tokens)

add_token_to_value(the_value: Assets, token: Token) -> Assets

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_tokens_to_value(the_value: Assets, tokens: Tokens) -> Assets

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)

from_value(v: Assets) -> 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)

exists(total: Tokens, target: Token) -> Bool

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)

contains(total: Tokens, target: Tokens) -> Bool

Check if a target list of tokens exist inside another list of tokens. The token amount must be greater than or equal to the target amount. If nothing is found then it returns False. An empty target returns True.

token.contains(total, target)
Search Document