Copyright | (c) 2023 GYELD GMBH |
---|---|
License | Apache 2.0 |
Maintainer | [email protected] |
Stability | develop |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Synopsis
- data GYValue
- valueMake ∷ Map GYAssetClass Integer → GYValue
- valueToPlutus ∷ GYValue → Value
- valueFromPlutus ∷ Value → Either GYFromPlutusValueError GYValue
- valueToApi ∷ GYValue → Value
- valueFromApi ∷ Value → GYValue
- valueSingleton ∷ GYAssetClass → Integer → GYValue
- valueFromList ∷ [(GYAssetClass, Integer)] → GYValue
- valueToList ∷ GYValue → [(GYAssetClass, Integer)]
- valueToMap ∷ GYValue → Map GYAssetClass Integer
- valueMap ∷ (GYAssetClass → Integer → Integer) → GYValue → GYValue
- valueTotalAssets ∷ GYValue → Int
- valueInsert ∷ GYAssetClass → Integer → GYValue → GYValue
- valueAdjust ∷ (Integer → Integer) → GYAssetClass → GYValue → GYValue
- valueAlter ∷ (Maybe Integer → Maybe Integer) → GYAssetClass → GYValue → GYValue
- valueFromLovelace ∷ Integer → GYValue
- valueFromApiTxOutValue ∷ TxOutValue era → GYValue
- valueToApiTxOutValue ∷ GYValue → TxOutValue ApiEra
- valueAssets ∷ GYValue → Set GYAssetClass
- parseValueKM ∷ Bool → KeyMap Value → Parser GYValue
- valueMinus ∷ GYValue → GYValue → GYValue
- valueNegate ∷ GYValue → GYValue
- valuePositive ∷ GYValue → Bool
- valueNonNegative ∷ GYValue → Bool
- valueGreaterOrEqual ∷ GYValue → GYValue → Bool
- valueGreater ∷ GYValue → GYValue → Bool
- valueUnionWith ∷ (Integer → Integer → Integer) → GYValue → GYValue → GYValue
- valueIntersection ∷ GYValue → GYValue → GYValue
- valueIntersectionWith ∷ (Integer → Integer → Integer) → GYValue → GYValue → GYValue
- valueAssetClass ∷ GYValue → GYAssetClass → Integer
- valueSplitAda ∷ GYValue → (Integer, GYValue)
- valueSplitSign ∷ GYValue → (GYValue, GYValue)
- isEmptyValue ∷ GYValue → Bool
- valueVerifyNonNegative ∷ GYValue → Maybe (Map GYAssetClass Natural)
- valueValid ∷ GYValue → Bool
- data GYFromPlutusValueError
- data GYAssetClass
- assetClassToPlutus ∷ GYAssetClass → AssetClass
- assetClassFromPlutus ∷ AssetClass → Either GYFromPlutusValueError GYAssetClass
- parseAssetClassWithSep ∷ Char → Text → Either String GYAssetClass
- parseAssetClassWithoutSep ∷ Text → Either String GYAssetClass
- parseAssetClassCore ∷ Char → (ByteString → Parser GYTokenName) → Text → Either String GYAssetClass
- newtype GYTokenName = GYTokenName ByteString
- tokenNameToHex ∷ GYTokenName → Text
- tokenNameFromBS ∷ ByteString → Maybe GYTokenName
- tokenNameToPlutus ∷ GYTokenName → TokenName
- tokenNameFromPlutus ∷ HasCallStack ⇒ TokenName → Maybe GYTokenName
- tokenNameFromHex ∷ Text → Either Text GYTokenName
- unsafeTokenNameFromHex ∷ Text → GYTokenName
- makeAssetClass ∷ Text → Text → Either String GYAssetClass
Value
Value: a (total) map from asset classes (GYAssetClass
) to amount (Integer
).
Instances
FromJSON GYValue # |
|
Defined in GeniusYield.Types.Value | |
ToJSON GYValue # |
|
Monoid GYValue # | |
Semigroup GYValue # | |
Show GYValue # | |
PrintfArg GYValue # |
|
Defined in GeniusYield.Types.Value | |
FromField GYValue # | |
Defined in GeniusYield.Types.Value parseField ∷ Field → Parser GYValue # | |
ToField GYValue # | |
Defined in GeniusYield.Types.Value | |
Eq GYValue # | |
Ord GYValue # | |
ToSchema GYValue # | |
Defined in GeniusYield.Types.Value |
valueFromPlutus ∷ Value → Either GYFromPlutusValueError GYValue #
Converts a Plutus Value
to a GYValue
.
Returns Left GYFromPlutusValueError
if it fails.
valueSingleton ∷ GYAssetClass → Integer → GYValue #
Returns a GYValue
containing only the given GYAssetClass
with the given amount.
>>>
valueSingleton (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "GOLD") 100
valueFromList [(GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "GOLD",100)]
valueFromList ∷ [(GYAssetClass, Integer)] → GYValue #
Create GYValue
from a list of asset class and amount.
Duplicates are merged.
valueToList ∷ GYValue → [(GYAssetClass, Integer)] #
Returns a list of all GYAssetClass
and amount pairs contained in a given GYValue
.
valueToMap ∷ GYValue → Map GYAssetClass Integer #
Returns a map from GYAssetClass
to their amount contained in a given GYValue
.
valueMap ∷ (GYAssetClass → Integer → Integer) → GYValue → GYValue #
Map operation over the GYValue
s amounts.
valueTotalAssets ∷ GYValue → Int #
Returns the total count of assets in a given GYValue
valueInsert ∷ GYAssetClass → Integer → GYValue → GYValue #
Insert an asset with its quantity.
valueAdjust ∷ (Integer → Integer) → GYAssetClass → GYValue → GYValue #
Adjust the amount of a given GYAssetClass
in the given GYValue
.
If the asset is not present in the value, original value is returned instead.
valueAlter ∷ (Maybe Integer → Maybe Integer) → GYAssetClass → GYValue → GYValue #
The expression (
) alters the value valueAlter
f asc valx
at asc
, or absence thereof.
valueAlter
can be used to insert, delete, or update a value in a GYValue
.
>>>
valueAlter (Just . maybe 1 (+ 1)) GYLovelace $ mempty
valueFromList [(GYLovelace,1)]
>>>
valueAlter (Just . maybe 1 (+ 1)) GYLovelace $ valueFromList [(GYLovelace, 1)]
valueFromList [(GYLovelace,2)]
valueFromLovelace ∷ Integer → GYValue #
>>>
valueFromLovelace 0
valueFromList []
>>>
valueFromLovelace 100
valueFromList [(GYLovelace,100)]
valueFromApiTxOutValue ∷ TxOutValue era → GYValue #
valueAssets ∷ GYValue → Set GYAssetClass #
Set of assets within a GYValue
in non-zero quantities.
∷ Bool | Attempt to try parsing without separator in asset class when parsing fails with separator. |
→ KeyMap Value | JSON object. |
→ Parser GYValue |
Parse a GYValue
from a JSON object.
Arithmetic
valueMinus ∷ GYValue → GYValue → GYValue #
Substracts the second GYValue
from the first one. AssetClass by AssetClass.
valueNegate ∷ GYValue → GYValue #
Returns the given GYValue
with all amounts negated.
valueNonNegative ∷ GYValue → Bool #
valueGreaterOrEqual ∷ GYValue → GYValue → Bool #
valueGreater ∷ GYValue → GYValue → Bool #
Unions & Intersections
valueUnionWith ∷ (Integer → Integer → Integer) → GYValue → GYValue → GYValue #
Combine two values with given function.
valueIntersection ∷ GYValue → GYValue → GYValue #
Left biased intersection of two GYValue
s.
Persist only the assets in the first value that also exist in the second.
valueIntersectionWith ∷ (Integer → Integer → Integer) → GYValue → GYValue → GYValue #
Intersection of two GYValue
s with a combining function.
Lookup
valueAssetClass ∷ GYValue → GYAssetClass → Integer #
Returns the amount of a GYAssetClass
contained in the given GYValue
.
Splitting
valueSplitAda ∷ GYValue → (Integer, GYValue) #
Splits a GYValue
into the lovelace amount and the rest of it's components.
>>>
valueSplitAda $ valueFromLovelace 100
(100,valueFromList [])
>>>
valueSplitAda $ valueFromList [(GYLovelace, 100), (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "GOLD",101)]
(100,valueFromList [(GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "GOLD",101)])
valueSplitSign ∷ GYValue → (GYValue, GYValue) #
Split a GYValue
into its positive and negative components. The first element of
the pair is the positive components of the value. The second element is the negative component.
>>>
valueSplitSign $ valueFromList [(GYLovelace,22),(GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "GOLD",-10)]
(valueFromList [(GYLovelace,22)],valueFromList [(GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "GOLD",10)])
Predicates
isEmptyValue ∷ GYValue → Bool #
Checks if the given GYValue
is empty
>>>
isEmptyValue mempty
True
>>>
isEmptyValue $ valueFromLovelace 100
False
>>>
isEmptyValue $ valueMinus (valueFromLovelace 100) (valueFromLovelace 100)
True
valueVerifyNonNegative ∷ GYValue → Maybe (Map GYAssetClass Natural) #
Verify the value only consists of positive amounts, returning a map containing naturals as a result.
Debug
valueValid ∷ GYValue → Bool #
Conversion errors
data GYFromPlutusValueError #
GYTokenNameTooBig !TokenName | Length of the token name bytestring is more than 32. |
GYInvalidPolicyId !CurrencySymbol | PolicyId deserialization failure. |
Instances
Asset class
data GYAssetClass #
Asset class. Either lovelace or minted token.
Instances
FromJSON GYAssetClass # |
|
Defined in GeniusYield.Types.Value | |
FromJSONKey GYAssetClass # | |
ToJSON GYAssetClass # |
|
Defined in GeniusYield.Types.Value toJSON ∷ GYAssetClass → Value # toEncoding ∷ GYAssetClass → Encoding # toJSONList ∷ [GYAssetClass] → Value # toEncodingList ∷ [GYAssetClass] → Encoding # omitField ∷ GYAssetClass → Bool # | |
ToJSONKey GYAssetClass # | |
IsString GYAssetClass # | |
Defined in GeniusYield.Types.Value | |
Generic GYAssetClass # | |
Defined in GeniusYield.Types.Value type Rep GYAssetClass ∷ Type → Type # from ∷ GYAssetClass → Rep GYAssetClass x # to ∷ Rep GYAssetClass x → GYAssetClass # | |
Show GYAssetClass # | |
Defined in GeniusYield.Types.Value showsPrec ∷ Int → GYAssetClass → ShowS # show ∷ GYAssetClass → String # showList ∷ [GYAssetClass] → ShowS # | |
PrintfArg GYAssetClass # |
|
Defined in GeniusYield.Types.Value | |
FromField GYAssetClass # |
|
Defined in GeniusYield.Types.Value | |
ToField GYAssetClass # |
|
Defined in GeniusYield.Types.Value toField ∷ GYAssetClass → Field # | |
Eq GYAssetClass # | |
Defined in GeniusYield.Types.Value (==) ∷ GYAssetClass → GYAssetClass → Bool # (/=) ∷ GYAssetClass → GYAssetClass → Bool # | |
Ord GYAssetClass # | |
Defined in GeniusYield.Types.Value compare ∷ GYAssetClass → GYAssetClass → Ordering # (<) ∷ GYAssetClass → GYAssetClass → Bool # (<=) ∷ GYAssetClass → GYAssetClass → Bool # (>) ∷ GYAssetClass → GYAssetClass → Bool # (>=) ∷ GYAssetClass → GYAssetClass → Bool # max ∷ GYAssetClass → GYAssetClass → GYAssetClass # min ∷ GYAssetClass → GYAssetClass → GYAssetClass # | |
Hashable GYAssetClass # | |
Defined in GeniusYield.Types.Value hashWithSalt ∷ Int → GYAssetClass → Int # hash ∷ GYAssetClass → Int # | |
FromHttpApiData GYAssetClass # | Note: not used currently by API (tests only)
|
Defined in GeniusYield.Types.Value | |
ToHttpApiData GYAssetClass # |
|
Defined in GeniusYield.Types.Value | |
ToParamSchema GYAssetClass # | |
Defined in GeniusYield.Types.Value toParamSchema ∷ ∀ (t ∷ SwaggerKind Type). Proxy GYAssetClass → ParamSchema t # | |
ToSchema GYAssetClass # | |
Defined in GeniusYield.Types.Value | |
type Rep GYAssetClass # | |
Defined in GeniusYield.Types.Value type Rep GYAssetClass = D1 ('MetaData "GYAssetClass" "GeniusYield.Types.Value" "atlas-cardano-0.6.3-inplace" 'False) (C1 ('MetaCons "GYLovelace" 'PrefixI 'False) (U1 ∷ Type → Type) :+: C1 ('MetaCons "GYToken" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 GYMintingPolicyId) :*: S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 GYTokenName))) |
assetClassToPlutus ∷ GYAssetClass → AssetClass #
Converts a GYAssetClass
into a Plutus AssetClass
.
assetClassFromPlutus ∷ AssetClass → Either GYFromPlutusValueError GYAssetClass #
Converts a Plutus AssetClass
into a GYAssetClass
.
Returns Left GYFromPlutusValueError
if it fails.
parseAssetClassWithSep ∷ Char → Text → Either String GYAssetClass #
Parse hex encoded currency symbol and hex encoded token name separated by the given separator.
>>> parseAssetClassWithSep .
"lovelace"
Right GYLovelace
>>>
parseAssetClassWithSep '.' ""
Right GYLovelace
>>>
parseAssetClassWithSep '.' "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.476f6c64"
Right (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "Gold")>>>
parseAssetClassWithSep '#' "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef#476f6c64"
Right (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "Gold")>>>
parseAssetClassWithSep '#' "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef#"
Right (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "")
parseAssetClassWithoutSep ∷ Text → Either String GYAssetClass #
Parse hex encoded currency symbol and hex encoded token name joined together without any separator. >>> parseAssetClassWithoutSep "lovelace" Right GYLovelace
>>>
parseAssetClassWithoutSep ""
Right GYLovelace
>>>
parseAssetClassWithoutSep "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef476f6c64"
Right (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "Gold")>>>
parseAssetClassWithoutSep "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef"
Right (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "")
parseAssetClassCore ∷ Char → (ByteString → Parser GYTokenName) → Text → Either String GYAssetClass #
Token name
newtype GYTokenName #
Token name is an arbitrary byte string up to 32 bytes long.
TODO: it's unclear whether it's an arbitrary byte string or UTF8 encoded text #32 (which encoded byte form is 32 byte long at most). (https:/github.comgeniusyieldatlasissues/32) We treat it as an arbitrary string.
>>>
LBS8.putStrLn $ Aeson.encode ("Gold" :: GYTokenName)
"476f6c64"
Instances
FromJSON GYTokenName # |
|
Defined in GeniusYield.Types.Value | |
ToJSON GYTokenName # |
|
Defined in GeniusYield.Types.Value toJSON ∷ GYTokenName → Value # toEncoding ∷ GYTokenName → Encoding # toJSONList ∷ [GYTokenName] → Value # toEncodingList ∷ [GYTokenName] → Encoding # omitField ∷ GYTokenName → Bool # | |
IsString GYTokenName # | Does NOT UTF8-encode. |
Defined in GeniusYield.Types.Value fromString ∷ String → GYTokenName # | |
Show GYTokenName # | |
Defined in GeniusYield.Types.Value showsPrec ∷ Int → GYTokenName → ShowS # show ∷ GYTokenName → String # showList ∷ [GYTokenName] → ShowS # | |
Eq GYTokenName # | |
Defined in GeniusYield.Types.Value (==) ∷ GYTokenName → GYTokenName → Bool # (/=) ∷ GYTokenName → GYTokenName → Bool # | |
Ord GYTokenName # | |
Defined in GeniusYield.Types.Value compare ∷ GYTokenName → GYTokenName → Ordering # (<) ∷ GYTokenName → GYTokenName → Bool # (<=) ∷ GYTokenName → GYTokenName → Bool # (>) ∷ GYTokenName → GYTokenName → Bool # (>=) ∷ GYTokenName → GYTokenName → Bool # max ∷ GYTokenName → GYTokenName → GYTokenName # min ∷ GYTokenName → GYTokenName → GYTokenName # | |
FromHttpApiData GYTokenName # |
|
Defined in GeniusYield.Types.Value | |
ToParamSchema GYTokenName # | |
Defined in GeniusYield.Types.Value toParamSchema ∷ ∀ (t ∷ SwaggerKind Type). Proxy GYTokenName → ParamSchema t # | |
ToSchema GYTokenName # | |
Defined in GeniusYield.Types.Value |
tokenNameFromPlutus ∷ HasCallStack ⇒ TokenName → Maybe GYTokenName #
Convert Plutus TokenName
to GYTokenName
.
makeAssetClass ∷ Text → Text → Either String GYAssetClass #