cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Safe Haskell None
Language Haskell2010

Cardano.Wallet.Primitive.Types.TokenQuantity

Synopsis

Type

newtype TokenQuantity Source #

Represents an integral quantity of tokens.

At present, we use Natural as our underlying type, as the only use case for these quantities is to be included in token bundles held within transaction outputs, and these must never be negative.

When we build support for minting and burning of tokens, we may wish to parameterize this type and allow it to be instantiated with Integer .

Instances

Instances details
Eq TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

Ord TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

Read TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

Show TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

Generic TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

Semigroup TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

Monoid TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

NFData TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

Hashable TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

ToJSON TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

FromJSON TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

Buildable TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

PersistFieldSql TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

PersistField TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

ToText TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

FromText TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

SymbolToField "txCollateralOutTokenQuantity" TxCollateralOutToken TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "txOutTokenQuantity" TxOutToken TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "utxoTokenQuantity" UTxOToken TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

type Rep TokenQuantity Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.TokenQuantity

type Rep TokenQuantity = D1 (' MetaData "TokenQuantity" "Cardano.Wallet.Primitive.Types.TokenQuantity" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "TokenQuantity" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "unTokenQuantity") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Natural )))

Values

Arithmetic operations

subtract :: TokenQuantity -> TokenQuantity -> Maybe TokenQuantity Source #

Subtracts the second token quantity from the first.

Returns Nothing if the first quantity is less than the second quantity.

pred :: TokenQuantity -> Maybe TokenQuantity Source #

Finds the predecessor of a given token quantity.

Returns Nothing if the given quantity is zero.

predZero :: TokenQuantity -> TokenQuantity Source #

Finds the predecessor of a given token quantity.

Returns zero if the given quantity is zero .

Satisfies the following property:

>>> predZero x == x `difference` 1

succ :: TokenQuantity -> TokenQuantity Source #

Finds the successor of a given token quantity.

difference :: TokenQuantity -> TokenQuantity -> TokenQuantity Source #

Subtracts the second token quantity from the first.

Returns zero if the first quantity is less than the second quantity.

Partitioning

equipartition Source #

Arguments

:: TokenQuantity

The token quantity to be partitioned.

-> NonEmpty a

Represents the number of portions in which to partition the quantity.

-> NonEmpty TokenQuantity

The partitioned quantities.

Computes the equipartition of a token quantity into n smaller quantities.

An equipartition of a token quantity is a partition of that quantity into n smaller quantities whose values differ by no more than 1.

The resultant list is sorted in ascending order.

partition Source #

Arguments

:: TokenQuantity

The token quantity to be partitioned.

-> NonEmpty TokenQuantity

The list of weights.

-> Maybe ( NonEmpty TokenQuantity )

The partitioned token quantities.

Partitions a token quantity into a number of parts, where the size of each part is proportional (modulo rounding) to the size of its corresponding element in the given list of weights, and the number of parts is equal to the number of weights.

Returns Nothing if the sum of weights is equal to zero.

partitionDefault Source #

Arguments

:: TokenQuantity

The token quantity to be partitioned.

-> NonEmpty TokenQuantity

The list of weights.

-> NonEmpty TokenQuantity

The partitioned token quantities.

Partitions a token quantity into a number of parts, where the size of each part is proportional (modulo rounding) to the size of its corresponding element in the given list of weights, and the number of parts is equal to the number of weights.

This function always satisfies the following properties:

fold   (partitionDefault q ws) == c
length (partitionDefault q ws) == length ws

If the sum of weights is equal to zero, then this function returns an equipartition satisfying the following property:

partitionDefault q ws == equipartition q ws

Tests

Unsafe operations

unsafeSubtract :: TokenQuantity -> TokenQuantity -> TokenQuantity Source #

Subtracts the second token quantity from the first.

Pre-condition: the first quantity is not less than the second quantity.

Throws a run-time exception if the pre-condition is violated.