| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusLedgerApi.V1.Value
Description
Functions for working with Value.
Synopsis
- newtype CurrencySymbol = CurrencySymbol {}
- currencySymbol :: ByteString -> CurrencySymbol
- adaSymbol :: CurrencySymbol
- newtype TokenName = TokenName {}
- tokenName :: ByteString -> TokenName
- toString :: TokenName -> String
- adaToken :: TokenName
- newtype AssetClass = AssetClass {}
- assetClass :: CurrencySymbol -> TokenName -> AssetClass
- assetClassValue :: AssetClass -> Integer -> Value
- assetClassValueOf :: Value -> AssetClass -> Integer
- newtype Value = Value {}
- singleton :: CurrencySymbol -> TokenName -> Integer -> Value
- valueOf :: Value -> CurrencySymbol -> TokenName -> Integer
- scale :: Module s v => s -> v -> v
- symbols :: Value -> [CurrencySymbol]
- geq :: Value -> Value -> Bool
- gt :: Value -> Value -> Bool
- leq :: Value -> Value -> Bool
- lt :: Value -> Value -> Bool
- isZero :: Value -> Bool
- split :: Value -> (Value, Value)
- unionWith :: (Integer -> Integer -> Integer) -> Value -> Value -> Value
- flattenValue :: Value -> [(CurrencySymbol, TokenName, Integer)]
Currency symbols
newtype CurrencySymbol Source #
ByteString representing the currency, hashed with BLAKE2b-224.
It is empty for Ada, 28 bytes for MintingPolicyHash.
Forms an AssetClass along with TokenName.
A Value is a map from CurrencySymbol's to a map from TokenName to an Integer.
This is a simple type without any validation, use with caution. You may want to add checks for its invariants. See the Shelley ledger specification.
Constructors
| CurrencySymbol | |
Fields | |
Instances
currencySymbol :: ByteString -> CurrencySymbol Source #
Creates CurrencySymbol from raw ByteString.
adaSymbol :: CurrencySymbol Source #
The CurrencySymbol of the Ada currency.
Token names
ByteString of a name of a token.
Shown as UTF-8 string when possible.
Should be no longer than 32 bytes, empty for Ada.
Forms an AssetClass along with a CurrencySymbol.
This is a simple type without any validation, use with caution. You may want to add checks for its invariants. See the Shelley ledger specification.
Constructors
| TokenName | |
Fields | |
Instances
tokenName :: ByteString -> TokenName Source #
Creates TokenName from raw ByteString.
Asset classes
newtype AssetClass Source #
An asset class, identified by a CurrencySymbol and a TokenName.
Constructors
| AssetClass | |
Fields | |
Instances
assetClass :: CurrencySymbol -> TokenName -> AssetClass Source #
assetClassValue :: AssetClass -> Integer -> Value Source #
A Value containing the given amount of the asset class.
assetClassValueOf :: Value -> AssetClass -> Integer Source #
Get the quantity of the given AssetClass class in the Value.
Value
The Value type represents a collection of amounts of different currencies.
We can think of Value as a vector space whose dimensions are currencies.
To create a value of Value, we need to specify a currency. This can be done
using adaValueOf. To get the ada dimension of Value we use
fromValue. Plutus contract authors will be able to define modules
similar to Ada for their own currencies.
Operations on currencies are usually implemented pointwise. That is,
we apply the operation to the quantities for each currency in turn. So
when we add two Values the resulting Value has, for each currency,
the sum of the quantities of that particular currency in the argument
Value. The effect of this is that the currencies in the Value are "independent",
and are operated on separately.
Whenever we need to get the quantity of a currency in a Value where there
is no explicit quantity of that currency in the Value, then the quantity is
taken to be zero.
There is no 'Ord Value' instance since Value is only a partial order, so compare can't
do the right thing in some cases.
Instances
singleton :: CurrencySymbol -> TokenName -> Integer -> Value Source #
Make a Value containing only the given quantity of the given currency.
valueOf :: Value -> CurrencySymbol -> TokenName -> Integer Source #
Get the quantity of the given currency in the Value.
symbols :: Value -> [CurrencySymbol] Source #
The list of CurrencySymbols of a Value.
Partial order operations
gt :: Value -> Value -> Bool Source #
Check whether one Value is strictly greater than another.
This is *not* a pointwise operation. gt l r means geq l r && not (eq l r).
lt :: Value -> Value -> Bool Source #
Check whether one Value is strictly less than another.
This is *not* a pointwise operation. lt l r means leq l r && not (eq l r).
Etc.
split :: Value -> (Value, Value) Source #
Split a value into its positive and negative parts. The first element of the tuple contains the negative parts of the value, the second element contains the positive parts.
negate (fst (split a)) plus (snd (split a)) == aflattenValue :: Value -> [(CurrencySymbol, TokenName, Integer)] Source #
Convert a value to a simple list, keeping only the non-zero amounts.