| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
PlutusCore.Value
Synopsis
- data Value
- data K
- k :: ByteString -> Maybe K
- unK :: K -> ByteString
- maxKeyLen :: Int
- data Quantity
- quantity :: Integer -> Maybe Quantity
- unQuantity :: Quantity -> Integer
- zeroQuantity :: Quantity
- addQuantity :: Quantity -> Quantity -> Maybe Quantity
- negativeAmounts :: Value -> Int
- type NestedMap = Map K (Map K Quantity)
- unpack :: Value -> NestedMap
- pack :: NestedMap -> Value
- empty :: Value
- fromList :: [(K, [(K, Quantity)])] -> BuiltinResult Value
- toList :: Value -> [(K, [(K, Quantity)])]
- toFlatList :: Value -> [(K, K, Quantity)]
- totalSize :: Value -> Int
- maxInnerSize :: Value -> Int
- insertCoin :: ByteString -> ByteString -> Integer -> Value -> BuiltinResult Value
- deleteCoin :: ByteString -> ByteString -> Value -> Value
- scaleValue :: Integer -> Value -> BuiltinResult Value
- lookupCoin :: ByteString -> ByteString -> Value -> Integer
- valueContains :: Value -> Value -> BuiltinResult Bool
- unionValue :: Value -> Value -> BuiltinResult Value
- valueData :: Value -> BuiltinResult Data
- unValueData :: Data -> BuiltinResult Value
Documentation
The underlying type of the UPLC built-in type Value.
Instances
A ByteString with maximum length of maxKeyLen bytes.
Instances
| Generic K Source # | |||||
Defined in PlutusCore.Value Associated Types
| |||||
| Show K Source # | |||||
| NFData K Source # | |||||
Defined in PlutusCore.Value | |||||
| Eq K Source # | |||||
| Ord K Source # | |||||
| Hashable K Source # | |||||
Defined in PlutusCore.Value | |||||
| Flat K Source # | |||||
| Serialise K Source # | |||||
Defined in PlutusCore.Value | |||||
| PrettyBy ConstConfig K Source # | |||||
Defined in PlutusCore.Pretty.PrettyConst | |||||
| type Rep K Source # | |||||
Defined in PlutusCore.Value type Rep K = D1 ('MetaData "K" "PlutusCore.Value" "plutus-core-1.60.0.0-LXFqBsoUlXsJIEqLytHte7" 'True) (C1 ('MetaCons "UnsafeK" 'PrefixI 'True) (S1 ('MetaSel ('Just "unK") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
unK :: K -> ByteString Source #
A signed 128-bit integer quantity.
Instances
| Bounded Quantity Source # | |||||
| Generic Quantity Source # | |||||
Defined in PlutusCore.Value Associated Types
| |||||
| Show Quantity Source # | |||||
| NFData Quantity Source # | |||||
Defined in PlutusCore.Value | |||||
| Eq Quantity Source # | |||||
| Ord Quantity Source # | |||||
Defined in PlutusCore.Value | |||||
| Hashable Quantity Source # | |||||
Defined in PlutusCore.Value | |||||
| Flat Quantity Source # | |||||
| Pretty Quantity Source # | |||||
Defined in PlutusCore.Value | |||||
| Serialise Quantity Source # | |||||
Defined in PlutusCore.Value Methods encode :: Quantity -> Encoding encodeList :: [Quantity] -> Encoding decodeList :: Decoder s [Quantity] | |||||
| PrettyBy ConstConfig Quantity Source # | |||||
Defined in PlutusCore.Pretty.PrettyConst Methods prettyBy :: ConstConfig -> Quantity -> Doc ann # prettyListBy :: ConstConfig -> [Quantity] -> Doc ann # | |||||
| type Rep Quantity Source # | |||||
Defined in PlutusCore.Value | |||||
unQuantity :: Quantity -> Integer Source #
zeroQuantity :: Quantity Source #
The zero quantity.
addQuantity :: Quantity -> Quantity -> Maybe Quantity Source #
Safely add two quantities, checking for overflow.
negativeAmounts :: Value -> Int Source #
unpack :: Value -> NestedMap Source #
Unpack a Value into a map from (currency symbol, token name) to quantity.
The map is guaranteed to not contain empty inner map or zero quantity.
pack :: NestedMap -> Value Source #
Pack a map from (currency symbol, token name) to quantity into a Value.
The map will be filtered so that it does not contain empty inner map or zero quantity.
totalSize :: Value -> Int Source #
Total size, i.e., the number of distinct `(currency symbol, token name)` pairs
contained in the Value.
maxInnerSize :: Value -> Int Source #
Size of the largest inner map.
insertCoin :: ByteString -> ByteString -> Integer -> Value -> BuiltinResult Value Source #
\(O(\log \max(m, k))\), where \(m\) is the size of the outer map, and \(k\) is the size of the largest inner map.
deleteCoin :: ByteString -> ByteString -> Value -> Value Source #
\(O(\log \max(m, k))\)
scaleValue :: Integer -> Value -> BuiltinResult Value Source #
\(O(n)\). Scale each token by the given constant factor.
lookupCoin :: ByteString -> ByteString -> Value -> Integer Source #
\(O(\log \max(m, k))\)
valueContains :: Value -> Value -> BuiltinResult Bool Source #
\(O(n_{2}\log \max(m_{1}, k_{1}))\), where \(n_{2}\) is the total size of the second
Value, \(m_{1}\) is the size of the outer map in the first Value and \(k_{1}\) is
the size of the largest inner map in the first Value.
a contains b if for each (currency, token, quantity) in b,
lookup currency token a >= quantity.
Both values must not contain negative amounts.
unionValue :: Value -> Value -> BuiltinResult Value Source #
\(O(n_{1}) + O(n_{2})\), where \(n_{1}\) and \(n_{2}\) are the total sizes (i.e., sum of inner map sizes) of the two maps.
Shortcircuits if either value is empty.
Since unionValue is commutative, we switch the arguments whenever the second
value is larger in total size than the first one. We have found through experimentation
that this results in better performance in practice.
unValueData :: Data -> BuiltinResult Value Source #