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

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.

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.

token.subtraction_only(redeemer.tokens)

addition_only(tokens: Tokens) -> Bool

Check that each token is greater than zero in a list tokens.

token.addition_only(redeemer.tokens)

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

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

from_value(v: Value) -> Tokens

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)

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.

token.contains(total, target)
Search Document