| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Plutarch.Extra.Value
Synopsis
- passetClassDataValue :: forall (s :: S). Term s (PAssetClassData :--> (PInteger :--> PValue 'Sorted 'NonZero))
- passetClassDataValueT :: forall {k :: Type} (unit :: k) (s :: S). Term s (PTagged unit PAssetClassData :--> (PTagged unit PInteger :--> PValue 'Sorted 'NonZero))
- psingleValue :: forall (key :: KeyGuarantees) (s :: S). Term s (PAsData PCurrencySymbol :--> (PAsData PTokenName :--> (PInteger :--> PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap key PTokenName PInteger)))))
- psingleValue' :: forall (keys :: KeyGuarantees) (a :: Type) (k :: Type) (s :: S). (Is k A_Getter, LabelOptic' "symbol" k a CurrencySymbol, LabelOptic' "name" k a TokenName) => a -> Term s (PInteger :--> PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap keys PTokenName PInteger)))
- psingleValueT' :: forall {k :: Type} (keys :: KeyGuarantees) (unit :: k) (s :: S). Tagged unit AssetClass -> Term s (PTagged unit PInteger :--> PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap keys PTokenName PInteger)))
- pvalue :: forall (k :: KeyGuarantees) (s :: S). Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> PAsData (PValue k 'NoGuarantees))
- pvaluePositive :: forall (k :: KeyGuarantees) (s :: S). Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> PAsData (PValue k 'Positive))
- padaOf :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PValue keys amounts :--> PInteger)
- passetClassValueOf' :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (a :: Type) (k :: Type) (s :: S). (Is k A_Getter, LabelOptic' "symbol" k a CurrencySymbol, LabelOptic' "name" k a TokenName) => a -> Term s (PValue keys amounts :--> PInteger)
- passetClassValueOf :: forall (key :: KeyGuarantees) (amount :: AmountGuarantees) (s :: S). Term s (PAssetClass :--> (PValue key amount :--> PInteger))
- passetClassValueOfT' :: forall {k :: Type} (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (unit :: k) (s :: S). Tagged unit AssetClass -> Term s (PValue keys amounts :--> PTagged unit PInteger)
- passetClassValueOfT :: forall {k :: Type} (key :: KeyGuarantees) (amount :: AmountGuarantees) (unit :: k) (s :: S). Term s (PTagged unit PAssetClass :--> (PValue key amount :--> PTagged unit PInteger))
- passetClassDataValueOf :: forall (key :: KeyGuarantees) (amount :: AmountGuarantees) (s :: S). Term s (PAssetClassData :--> (PValue key amount :--> PInteger))
- passetClassDataValueOfT :: forall {k :: Type} (key :: KeyGuarantees) (amount :: AmountGuarantees) (unit :: k) (s :: S). Term s (PTagged unit PAssetClassData :--> (PValue key amount :--> PTagged unit PInteger))
- pmatchValueAssets :: forall (input :: [(Symbol, Type)]) (s :: S). (MatchValueAssetReferences input s, HRecToList input AssetClass) => Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap 'Sorted PTokenName PInteger)))) -> HRec input -> TermCont s (HRec (OutputMatchValueAssets input s))
- psplitValue :: forall (v :: AmountGuarantees) (s :: S). Term s (PValue 'Sorted v :--> PPair (PAsData PInteger) (PValue 'Sorted v))
- psymbolValueOf :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PValue keys amounts :--> PInteger))
- psymbolValueOf' :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PValue keys amounts :--> PMaybe (PPair PInteger PInteger)))
- precValue :: forall r (k :: KeyGuarantees) s. (Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> r) -> Term s (PAsData PCurrencySymbol) -> Term s (PAsData PTokenName) -> Term s (PAsData PInteger) -> Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger)))) -> Term s r) -> (Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> r) -> Term s r) -> Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> r)
- pelimValue :: forall (amounts :: AmountGuarantees) (r :: S -> Type) (s :: S). (Term s PCurrencySymbol -> Term s PTokenName -> Term s PInteger -> Term s (PValue 'Sorted amounts) -> Term s r) -> Term s r -> Term s (PValue 'Sorted amounts) -> Term s r
- pbyClassComparator :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PTokenName :--> PComparator (PValue keys amounts)))
- pbySymbolComparator :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> PComparator (PValue keys amounts))
- pbyClassComparator' :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). AssetClass -> Term s (PComparator (PValue keys amounts))
- type family AddGuarantees (a :: AmountGuarantees) (b :: AmountGuarantees) where ...
- phasOnlyOneTokenOfCurrencySymbol :: forall (kg :: KeyGuarantees) (ag :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PValue kg ag :--> PBool))
- phasOneTokenOfCurrencySymbol :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PValue keys amounts :--> PBool))
- phasOneTokenOfAssetClass :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PAssetClass :--> (PValue keys amounts :--> PBool))
- phasOneTokenOfAssetClassData :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PAssetClassData :--> (PValue keys amounts :--> PBool))
- pcountNonZeroes :: forall (kg :: KeyGuarantees) (ag :: AmountGuarantees) (s :: S). Term s (PValue kg ag :--> PInteger)
Creation
passetClassDataValue :: forall (s :: S). Term s (PAssetClassData :--> (PInteger :--> PValue 'Sorted 'NonZero)) Source #
Create a PValue that only contains a specific amount of tokens, described
by a PAssetClassData.
Since: 3.10.0
passetClassDataValueT :: forall {k :: Type} (unit :: k) (s :: S). Term s (PTagged unit PAssetClassData :--> (PTagged unit PInteger :--> PValue 'Sorted 'NonZero)) Source #
Tagged version of passetClassDataValue.
Since: 3.14.1
psingleValue :: forall (key :: KeyGuarantees) (s :: S). Term s (PAsData PCurrencySymbol :--> (PAsData PTokenName :--> (PInteger :--> PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap key PTokenName PInteger))))) Source #
Helper to construct the 'inner mapping' of a PValue.
Since: 3.9.0
psingleValue' :: forall (keys :: KeyGuarantees) (a :: Type) (k :: Type) (s :: S). (Is k A_Getter, LabelOptic' "symbol" k a CurrencySymbol, LabelOptic' "name" k a TokenName) => a -> Term s (PInteger :--> PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap keys PTokenName PInteger))) Source #
As psingleValue, but using a Haskell-level AssetClass.
Since: 3.10.0
psingleValueT' :: forall {k :: Type} (keys :: KeyGuarantees) (unit :: k) (s :: S). Tagged unit AssetClass -> Term s (PTagged unit PInteger :--> PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap keys PTokenName PInteger))) Source #
Tagged version of psingleValue`.
Since: 3.14.1
pvalue :: forall (k :: KeyGuarantees) (s :: S). Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> PAsData (PValue k 'NoGuarantees)) Source #
Construct a PValue from its underlying representation.
There are NoGuarantees on the amounts.
Since: 3.10.0
pvaluePositive :: forall (k :: KeyGuarantees) (s :: S). Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> PAsData (PValue k 'Positive)) Source #
Queries
padaOf :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PValue keys amounts :--> PInteger) Source #
Get the amount of ada of a PValue.
Since: 3.9.0
passetClassValueOf' :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (a :: Type) (k :: Type) (s :: S). (Is k A_Getter, LabelOptic' "symbol" k a CurrencySymbol, LabelOptic' "name" k a TokenName) => a -> Term s (PValue keys amounts :--> PInteger) Source #
As passetClassValueOf, but using a Haskell-level AssetClass.
Since: 3.9.0
passetClassValueOf :: forall (key :: KeyGuarantees) (amount :: AmountGuarantees) (s :: S). Term s (PAssetClass :--> (PValue key amount :--> PInteger)) Source #
Given a PAssetClass and a PValue, look up the amount corresponding to
that PAssetClass.
Since: 3.9.0
passetClassValueOfT' :: forall {k :: Type} (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (unit :: k) (s :: S). Tagged unit AssetClass -> Term s (PValue keys amounts :--> PTagged unit PInteger) Source #
Tagged version of passetClassValueOf`.
Since: 3.14.1
passetClassValueOfT :: forall {k :: Type} (key :: KeyGuarantees) (amount :: AmountGuarantees) (unit :: k) (s :: S). Term s (PTagged unit PAssetClass :--> (PValue key amount :--> PTagged unit PInteger)) Source #
Tagged version of passetClassValueOf.
Since: 3.9.0
passetClassDataValueOf :: forall (key :: KeyGuarantees) (amount :: AmountGuarantees) (s :: S). Term s (PAssetClassData :--> (PValue key amount :--> PInteger)) Source #
Given a PAssetClassData and a PValue, look up the amount corresponding
to that PAssetClassData.
Since: 3.21.4
passetClassDataValueOfT :: forall {k :: Type} (key :: KeyGuarantees) (amount :: AmountGuarantees) (unit :: k) (s :: S). Term s (PTagged unit PAssetClassData :--> (PValue key amount :--> PTagged unit PInteger)) Source #
Tagged version of passetClassDataValueOf.
Since: 3.21.4
pmatchValueAssets :: forall (input :: [(Symbol, Type)]) (s :: S). (MatchValueAssetReferences input s, HRecToList input AssetClass) => Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap 'Sorted PTokenName PInteger)))) -> HRec input -> TermCont s (HRec (OutputMatchValueAssets input s)) Source #
Extracts the amount given by the PAssetClass from (the internal
representation of) a PValue.
Intuitively, this acts as a 'pattern match' on PValue. You don't have to
provide every asset class, only the ones you are interested in.
Example
example :: forall (s :: S) .
Term s (PBuiltinList (
PBuiltinPair (PAsData PCurrencySymbol)
(PAsData (PMap 'Sorted PTokenName PInteger))
) -> TermConst s ()
example rep = do
rec <- matchValueAssets @'['("ada", AssetClass "Ada")]
rep
(HCons (Labeled adaClass) HNil)
-- Or using operators
rec2 <- matchValueAssets rep $ (Proxy @"ada" .|== adaClass) HNIl
let adaFromRep = rec.adaSince: 3.9.0
psplitValue :: forall (v :: AmountGuarantees) (s :: S). Term s (PValue 'Sorted v :--> PPair (PAsData PInteger) (PValue 'Sorted v)) Source #
Gets the first entry in the first item of the PValue mapping & returns the
rest of the PValue.
Fails if the PValue is empty. In cases where we know that a PValue contains
Ada, such as in a PScriptContext, then this will function will split the
Ada value - since the Ada entry comes first.
NOTE: All properly normalized values will contain an Ada entry, even if that entry is 0.
Since: 3.9.0
Aggregation and elimination
psymbolValueOf :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PValue keys amounts :--> PInteger)) Source #
Get the sum of all values belonging to a particular CurrencySymbol.
Since: 1.1.0
psymbolValueOf' :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PValue keys amounts :--> PMaybe (PPair PInteger PInteger))) Source #
Get the negative and positive amount of a particular CurrencySymbol, and
return nothing if it doesn't exist in the value.
Since: 3.14.1
precValue :: forall r (k :: KeyGuarantees) s. (Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> r) -> Term s (PAsData PCurrencySymbol) -> Term s (PAsData PTokenName) -> Term s (PAsData PInteger) -> Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger)))) -> Term s r) -> (Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> r) -> Term s r) -> Term s (PBuiltinList (PBuiltinPair (PAsData PCurrencySymbol) (PAsData (PMap k PTokenName PInteger))) :--> r) Source #
Eliminator for the inner type of a PValue.
Since: 3.9.0
pelimValue :: forall (amounts :: AmountGuarantees) (r :: S -> Type) (s :: S). (Term s PCurrencySymbol -> Term s PTokenName -> Term s PInteger -> Term s (PValue 'Sorted amounts) -> Term s r) -> Term s r -> Term s (PValue 'Sorted amounts) -> Term s r Source #
Eliminator for a sorted PValue. The function argument will receive:
- The smallest
PCurrencySymbolfor which we have a mapping; - The smallest
PTokenNamefor which the corresponding 'inner map' has a mapping; - The
PIntegerassociated with the abovePTokenName; and - The 'rest'.
If the 'inner map' corresponding to the PCurrencySymbol above contains
only a single mapping, the 'rest' will not contain a mapping for that
PCurrencySymbol; otherwise, it will contain the rest of the 'inner map'.
Note
The 'nil case' will be invoked in two situations:
- When the
PValuehas no entries; and - When the 'inner map' corresponding to the first
PCurrencySymbolkey has no entries.
Since: 3.9.0
Comparison
pbyClassComparator :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PTokenName :--> PComparator (PValue keys amounts))) Source #
Compare only on the basis of a particular PCurrencySymbol and
PTokenName entry.
Since: 3.9.0
pbySymbolComparator :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> PComparator (PValue keys amounts)) Source #
Compare only the entries corresponding to a particular PCurrencySymbol.
Since: 3.9.0
pbyClassComparator' :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). AssetClass -> Term s (PComparator (PValue keys amounts)) Source #
As pbyClassComparator, but using a Haskell-level AssetClass instead.
Since: 3.9.0
Miscellaneous
type family AddGuarantees (a :: AmountGuarantees) (b :: AmountGuarantees) where ... Source #
Compute the guarantees known after adding two PValues.
Since: 1.1.0
Equations
| AddGuarantees 'Positive 'Positive = 'Positive | |
| AddGuarantees _ _ = 'NoGuarantees |
phasOnlyOneTokenOfCurrencySymbol :: forall (kg :: KeyGuarantees) (ag :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PValue kg ag :--> PBool)) Source #
Returns PTrue if the entire argument PValue contains exactly one
token of the argument PCurrencySymbol (and contains no other assets).
This implementation makes a special case for ADA, where it allows
zero-ada entries in the given PValue.
Since: 3.21.0
phasOneTokenOfCurrencySymbol :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PCurrencySymbol :--> (PValue keys amounts :--> PBool)) Source #
Returns PTrue if the argument PValue contains exactly one
token of the argument PCurrencySymbol.
Note: unlike phasOnlyOneTokenOfCurrencySymbol this may
still return PTrue if there are other assets in the PValue.
Since: 3.9.1
phasOneTokenOfAssetClass :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PAssetClass :--> (PValue keys amounts :--> PBool)) Source #
Returns PTrue if the argument PValue contains exactly
one token of the argument PAssetClass.
Note: unlike phasOnlyOneTokenOfCurrencySymbol this may
still return PTrue if there are other assets in the PValue.
Since: 3.9.1
phasOneTokenOfAssetClassData :: forall (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S). Term s (PAssetClassData :--> (PValue keys amounts :--> PBool)) Source #
Returns PTrue if the argument PValue contains exactly
one token of the argument PAssetClassData.
Note: unlike phasOnlyOneTokenOfCurrencySymbol this may
still return PTrue if there are other assets in the PValue.
Since: 3.21.4
pcountNonZeroes :: forall (kg :: KeyGuarantees) (ag :: AmountGuarantees) (s :: S). Term s (PValue kg ag :--> PInteger) Source #
Returns the count of non-zero currency symbols in a PValue.
So, for a value of the following shape:
[("", [("", 0)]), ("feed", [("foo", 7)]), ("deed", [("bar", 1)])]
We get the result 2.
Since: 3.21.0