cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2018-2020 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Wallet.Primitive.Types.Coin

Description

This module provides the Coin data type, which represents a quantity of lovelace.

Synopsis

Type

newtype Coin Source #

A Coin represents a quantity of lovelace.

Reminder: 1 ada = 1,000,000 lovelace.

The Coin type has Semigroup and Monoid instances that correspond to ordinary addition and summation.

Constructors

Coin

Instances

Instances details
Eq Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

Ord Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

Read Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

Show Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

Generic Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

Associated Types

type Rep Coin :: Type -> Type Source #

Semigroup Coin Source #

The Semigroup instance for Coin corresponds to ordinary addition.

Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

Monoid Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

NFData Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

Hashable Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

Buildable Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

PersistFieldSql Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

PersistField Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

ToText Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

FromText Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

SymbolToField "protocolParametersKeyDeposit" ProtocolParameters Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "protocolParametersMinimumUtxoValue" ProtocolParameters Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "txCollateralOutAmount" TxCollateralOut Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "txCollateralSourceAmount" TxCollateral Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "txInputSourceAmount" TxIn Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "txMetaAmount" TxMeta Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "txOutputAmount" TxOut Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "txWithdrawalAmount" TxWithdrawal Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

SymbolToField "utxoOutputCoin" UTxO Coin Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

type Rep Coin Source #
Instance details

Defined in Cardano.Wallet.Primitive.Types.Coin

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

Conversions (Safe)

fromIntegral :: ( Bits i, Integral i) => i -> Maybe Coin Source #

Constructs a Coin from an Integral value.

Returns Nothing if the given value is negative.

toQuantity :: ( Bits i, Integral i) => Coin -> Maybe ( Quantity n i) Source #

Converts a Coin to a Quantity .

Returns Nothing if the given value does not fit within the bounds of the target type.

toWord64 :: Coin -> Maybe Word64 Source #

Converts a Coin to a Word64 value.

Returns Nothing if the given value does not fit within the bounds of a 64-bit word.

Conversions (Unsafe)

unsafeFromIntegral :: HasCallStack => ( Bits i, Integral i, Show i) => i -> Coin Source #

Constructs a Coin from an Integral value.

Callers of this function must take responsibility for checking that the given value is not negative.

Produces a run-time error if the given value is negative.

unsafeToQuantity :: HasCallStack => ( Bits i, Integral i) => Coin -> Quantity n i Source #

Converts a Coin to a Quantity .

Callers of this function must take responsibility for checking that the given value will fit within the bounds of the target type.

Produces a run-time error if the given value is out of bounds.

unsafeToWord64 :: HasCallStack => Coin -> Word64 Source #

Converts a Coin to a Word64 value.

Callers of this function must take responsibility for checking that the given value will fit within the bounds of a 64-bit word.

Produces a run-time error if the given value is out of bounds.

Arithmetic operations

add :: Coin -> Coin -> Coin Source #

Calculates the combined value of two coins.

subtract :: Coin -> Coin -> Maybe Coin Source #

Subtracts the second coin from the first.

Returns Nothing if the second coin is strictly greater than the first.

difference :: Coin -> Coin -> Coin Source #

Subtracts the second coin from the first.

Returns 'Coin 0' if the second coin is strictly greater than the first.

distance :: Coin -> Coin -> Coin Source #

Absolute difference between two coin amounts. The result is never negative.

Partitioning

equipartition Source #

Arguments

:: Coin

The coin to be partitioned.

-> NonEmpty a

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

-> NonEmpty Coin

The partitioned coins.

Computes the equipartition of a coin into n smaller coins.

An equipartition of a coin is a partition of that coin into n smaller coins whose values differ by no more than 1.

The resultant list is sorted in ascending order.

partition Source #

Arguments

:: Coin

The coin to be partitioned.

-> NonEmpty Coin

The list of weights.

-> Maybe ( NonEmpty Coin )

The partitioned coins.

Partitions a coin 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

:: Coin

The token quantity to be partitioned.

-> NonEmpty Coin

The list of weights.

-> NonEmpty Coin

The partitioned token quantities.

Partitions a coin 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 c ws) == c
length (partitionDefault c ws) == length ws

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

partitionDefault c ws == equipartition c ws

unsafePartition Source #

Arguments

:: HasCallStack
=> Coin

The coin to be partitioned.

-> NonEmpty Coin

The list of weights.

-> NonEmpty Coin

The partitioned coins.

Partitions a coin 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.

Throws a run-time error if the sum of weights is equal to zero.