atlas-cardano-0.5.0: Application backend for Plutus smart contracts on Cardano
Copyright(c) 2023 GYELD GMBH
LicenseApache 2.0
Maintainer[email protected]
Stabilitydevelop
Safe HaskellSafe-Inferred
LanguageGHC2021

GeniusYield.Types.Value

Description

 
Synopsis

Value

data GYValue #

Value: a (total) map from asset classes (GYAssetClass) to amount (Integer).

Instances

Instances details
FromJSON GYValue #
>>> Aeson.decode @GYValue "{\"ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.474f4c44\":101,\"lovelace\":22}"
Just (valueFromList [(GYLovelace,22),(GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "GOLD",101)])
Instance details

Defined in GeniusYield.Types.Value

ToJSON GYValue #
>>> LBS8.putStrLn . Aeson.encode . valueFromList $ [(GYLovelace,22),(GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "GOLD",101)]
{"lovelace":22,"ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.474f4c44":101}
Instance details

Defined in GeniusYield.Types.Value

Monoid GYValue # 
Instance details

Defined in GeniusYield.Types.Value

Semigroup GYValue # 
Instance details

Defined in GeniusYield.Types.Value

Show GYValue # 
Instance details

Defined in GeniusYield.Types.Value

PrintfArg GYValue #
>>> Printf.printf "value = %s" (valueFromList [])
value =
>>> Printf.printf "value = %s" (valueFromList [(GYLovelace, 1000)])
value = 1000 lovelace
Instance details

Defined in GeniusYield.Types.Value

FromField GYValue # 
Instance details

Defined in GeniusYield.Types.Value

ToField GYValue # 
Instance details

Defined in GeniusYield.Types.Value

Methods

toFieldGYValueField Source #

Eq GYValue # 
Instance details

Defined in GeniusYield.Types.Value

Methods

(==)GYValueGYValueBool Source #

(/=)GYValueGYValueBool Source #

Ord GYValue # 
Instance details

Defined in GeniusYield.Types.Value

ToSchema GYValue # 
Instance details

Defined in GeniusYield.Types.Value

valueToPlutusGYValueValue #

Converts a GYValue to a Plutus Value

valueFromPlutusValueEither GYFromPlutusValueError GYValue #

Converts a Plutus Value to a GYValue. Returns Left GYFromPlutusValueError if it fails.

valueToApiGYValueValue #

Convert a GYValue to a Cardano Api Value

valueFromApiValueGYValue #

Convert a Cardano Api Value to a GYValue

valueSingletonGYAssetClassIntegerGYValue #

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.

valueToListGYValue → [(GYAssetClass, Integer)] #

Returns a list of all GYAssetClass and amount pairs contained in a given GYValue.

valueToMapGYValueMap GYAssetClass Integer #

Returns a map from GYAssetClass to their amount contained in a given GYValue.

valueMap ∷ (GYAssetClassIntegerInteger) → GYValueGYValue #

Map operation over the GYValues amounts.

valueTotalAssetsGYValueInt #

Returns the total count of assets in a given GYValue

valueInsertGYAssetClassIntegerGYValueGYValue #

Insert an asset with its quantity.

valueAdjust ∷ (IntegerInteger) → GYAssetClassGYValueGYValue #

Adjust the amount of a given GYAssetClass in the given GYValue.

valueFromLovelaceIntegerGYValue #

>>> valueFromLovelace 0
valueFromList []
>>> valueFromLovelace 100
valueFromList [(GYLovelace,100)]

valueAssetsGYValueSet GYAssetClass #

Set of assets within a GYValue in non-zero quantities.

Arithmetic

valueMinusGYValueGYValueGYValue #

Substracts the second GYValue from the first one. AssetClass by AssetClass.

valueNegateGYValueGYValue #

Returns the given GYValue with all amounts negated.

valuePositiveGYValueBool #

Checks if all amounts of the given GYValue are positive ( > 0 ).

valueNonNegativeGYValueBool #

Checks if all amounts of the given GYValue are not negative ( >= 0 ).

valueGreaterOrEqualGYValueGYValueBool #

Checks if all amounts of the first GYValue are greater or equal to the second GYValue.

valueGreaterGYValueGYValueBool #

Checks if all amounts of the first GYValue are greater than the second GYValue.

Unions & Intersections

valueUnionWith ∷ (IntegerIntegerInteger) → GYValueGYValueGYValue #

Combine two values with given function.

valueIntersectionGYValueGYValueGYValue #

Left biased intersection of two GYValues.

Persist only the assets in the first value that also exist in the second.

valueIntersectionWith ∷ (IntegerIntegerInteger) → GYValueGYValueGYValue #

Intersection of two GYValues with a combining function.

Lookup

valueAssetClassGYValueGYAssetClassInteger #

Returns the amount of a GYAssetClass contained in the given GYValue.

Splitting

valueSplitAdaGYValue → (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)])

valueSplitSignGYValue → (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

isEmptyValueGYValueBool #

Checks if the given GYValue is empty

>>> isEmptyValue mempty
True
>>> isEmptyValue $ valueFromLovelace 100
False
>>> isEmptyValue $ valueMinus (valueFromLovelace 100) (valueFromLovelace 100)
True

valueVerifyNonNegativeGYValueMaybe (Map GYAssetClass Natural) #

Verify the value only consists of positive amounts, returning a map containing naturals as a result.

Debug

valueValidGYValueBool #

Check the GYValue representation invariants.

Should always evaluate to True

Conversion errors

data GYFromPlutusValueError #

Errors raised during Value -> GYValue conversion.

Constructors

GYTokenNameTooBig !TokenName

Length of the token name bytestring is more than 32.

GYInvalidPolicyId !CurrencySymbol

PolicyId deserialization failure.

Asset class

data GYAssetClass #

Asset class. Either lovelace or minted token.

Instances

Instances details
FromJSON GYAssetClass #
>>> Aeson.decode @GYAssetClass "\"lovelace\""
Just GYLovelace
>>> Aeson.decode @GYAssetClass "\"ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.476f6c64\""
Just (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "Gold")
>>> Aeson.decode @GYAssetClass "\"ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.0014df1043727970746f20556e69636f726e\""
Just (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "\NUL\DC4\223\DLECrypto Unicorn")
Instance details

Defined in GeniusYield.Types.Value

FromJSONKey GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

ToJSON GYAssetClass #
>>> LBS8.putStrLn $ Aeson.encode GYLovelace
"lovelace"
>>> LBS8.putStrLn $ Aeson.encode $ GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "Gold"
"ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.476f6c64"
Instance details

Defined in GeniusYield.Types.Value

ToJSONKey GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

IsString GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

Generic GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

Associated Types

type Rep GYAssetClassTypeType Source #

Show GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

PrintfArg GYAssetClass #
>>> Printf.printf "ac = %s" GYLovelace
ac = lovelace
Instance details

Defined in GeniusYield.Types.Value

FromField GYAssetClass #
>>> Csv.runParser @GYAssetClass $ Csv.parseField "lovelace"
Right GYLovelace
>>> Csv.runParser @GYAssetClass $ Csv.parseField ""
Right GYLovelace
>>> Csv.runParser @GYAssetClass $ Csv.parseField "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.476f6c64"
Right (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "Gold")
>>> Csv.runParser @GYAssetClass $ Csv.parseField "not an asset class"
Left "Failed reading: takeWhile1"
Instance details

Defined in GeniusYield.Types.Value

ToField GYAssetClass #
>>> BS8.putStrLn $ Csv.toField GYLovelace
lovelace
>>> BS8.putStrLn $ Csv.toField $ GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "Gold"
ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.476f6c64
Instance details

Defined in GeniusYield.Types.Value

Eq GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

Ord GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

Hashable GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

FromHttpApiData GYAssetClass #

Note: not used currently by API (tests only)

>>> Web.parseUrlPiece @GYAssetClass "lovelace"
Right GYLovelace
>>> Web.parseUrlPiece @GYAssetClass ""
Right GYLovelace
>>> Web.parseUrlPiece @GYAssetClass "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.476f6c64"
Right (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "Gold")
Instance details

Defined in GeniusYield.Types.Value

ToHttpApiData GYAssetClass #
>>> Web.toUrlPiece GYLovelace
"lovelace"
>>> Web.toUrlPiece (GYToken "ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef" "GOLD")
"ff80aaaf03a273b8f5c558168dc0e2377eea810badbae6eceefc14ef.474f4c44"
>>> let tn = unsafeTokenNameFromHex "0014df1043727970746f20556e69636f726e" in Web.toUrlPiece (GYToken "ecda51cf797535f5661a8ade59170d6f3ee7623be5789b58fac583f0" tn)
"ecda51cf797535f5661a8ade59170d6f3ee7623be5789b58fac583f0.0014df1043727970746f20556e69636f726e"
Instance details

Defined in GeniusYield.Types.Value

ToParamSchema GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

ToSchema GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

type Rep GYAssetClass # 
Instance details

Defined in GeniusYield.Types.Value

type Rep GYAssetClass = D1 ('MetaData "GYAssetClass" "GeniusYield.Types.Value" "atlas-cardano-0.5.0-inplace" 'False) (C1 ('MetaCons "GYLovelace" 'PrefixI 'False) (U1TypeType) :+: C1 ('MetaCons "GYToken" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 GYMintingPolicyId) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 GYTokenName)))

parseAssetClassWithSepCharTextEither 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" "")

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"

Constructors

GYTokenName ByteString 

Instances

Instances details
FromJSON GYTokenName #
>>> Aeson.eitherDecode @GYTokenName "\"476f6c64\""
Right "Gold"
>>> Aeson.eitherDecode @GYTokenName "\"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021\""
Left "Error in $: parseJSON @GYTokenName: token name too long (0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021)"
>>> Aeson.eitherDecode @GYTokenName "\"gold\""
Left "Error in $: parseJSON @GYTokenName: not base16 encoded (gold)"
>>> Aeson.eitherDecode @GYTokenName "123"
Left "Error in $: parsing Text failed, expected String, but encountered Number"
Instance details

Defined in GeniusYield.Types.Value

ToJSON GYTokenName #
>>> Aeson.encode @GYTokenName "Gold"
"\"476f6c64\""
Instance details

Defined in GeniusYield.Types.Value

IsString GYTokenName #

Does NOT UTF8-encode.

Instance details

Defined in GeniusYield.Types.Value

Show GYTokenName # 
Instance details

Defined in GeniusYield.Types.Value

Eq GYTokenName # 
Instance details

Defined in GeniusYield.Types.Value

Ord GYTokenName # 
Instance details

Defined in GeniusYield.Types.Value

FromHttpApiData GYTokenName #
>>> Web.parseUrlPiece @GYTokenName "476f6c64"
Right "Gold"
>>> Web.parseUrlPiece @GYTokenName "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021"
Left "token name too long (0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021)"
>>> Web.parseUrlPiece @GYTokenName "Gold"
Left "not base16 encoded (Gold)"
Instance details

Defined in GeniusYield.Types.Value

ToParamSchema GYTokenName # 
Instance details

Defined in GeniusYield.Types.Value

ToSchema GYTokenName # 
Instance details

Defined in GeniusYield.Types.Value