Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- withCurrencySymbol ∷ CurrencySymbol → Value → a → (Map TokenName Integer → a) → a
- currencySymbolValueOf ∷ Value → CurrencySymbol → Integer
- lovelaceValue ∷ Lovelace → Value
- lovelaceValueOf ∷ Value → Lovelace
- scale ∷ Module s v ⇒ s → v → v
- symbols ∷ Value → BuiltinList BuiltinData
- 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)]
- newtype Lovelace = Lovelace {}
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.
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.
Instances
tokenName ∷ ByteString → TokenName Source #
Creates TokenName
from raw ByteString
.
toString ∷ TokenName → String Source #
Turn a TokenName to a hex-encoded String
Compared to show
, it will not surround the string with double-quotes.
Asset classes
newtype AssetClass Source #
An asset class, identified by a CurrencySymbol
and a TokenName
.
Instances
assetClass ∷ CurrencySymbol → TokenName → AssetClass Source #
The curried version of AssetClass
constructor
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.
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 Value
s 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
.
Assumes that the underlying map doesn't contain duplicate keys.
withCurrencySymbol ∷ CurrencySymbol → Value → a → (Map TokenName Integer → a) → a Source #
Apply a continuation function to the token quantities of the given currency symbol in the value or return a default value if the currency symbol is not present in the value.
currencySymbolValueOf ∷ Value → CurrencySymbol → Integer Source #
Get the total value of the currency symbol in the Value
map.
Assumes that the underlying map doesn't contain duplicate keys.
Note that each token of the currency symbol may have a value that is positive, zero or negative.
symbols ∷ Value → BuiltinList BuiltinData Source #
The list of CurrencySymbol
s 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.
unionWith ∷ (Integer → Integer → Integer) → Value → Value → Value Source #
Combine two Value
maps with the argument function.
Assumes the well-definedness of the two maps.
flattenValue ∷ Value → [(CurrencySymbol, TokenName, Integer)] Source #