plutus-core
Safe HaskellNone
LanguageHaskell2010

PlutusCore.Value

Synopsis

Documentation

data Value Source #

The underlying type of the UPLC built-in type Value.

Instances

Instances details
Generic Value Source # 
Instance details

Defined in PlutusCore.Value

Associated Types

type Rep Value 
Instance details

Defined in PlutusCore.Value

Methods

from :: Value -> Rep Value x Source #

to :: Rep Value x -> Value Source #

Show Value Source # 
Instance details

Defined in PlutusCore.Value

NFData Value Source # 
Instance details

Defined in PlutusCore.Value

Methods

rnf :: Value -> () Source #

Eq Value Source # 
Instance details

Defined in PlutusCore.Value

Methods

(==) :: Value -> Value -> Bool Source #

(/=) :: Value -> Value -> Bool Source #

Hashable Value Source # 
Instance details

Defined in PlutusCore.Value

Methods

hashWithSalt :: Int -> Value -> Int

hash :: Value -> Int

Flat Value Source # 
Instance details

Defined in PlutusCore.Value

Methods

encode :: Value -> Encoding

decode :: Get Value

size :: Value -> NumBits -> NumBits

ExMemoryUsage Value Source #

Measure the size of a Value by its totalSize.

Instance details

Defined in PlutusCore.Evaluation.Machine.ExMemoryUsage

Pretty Value Source # 
Instance details

Defined in PlutusCore.Value

Methods

pretty :: Value -> Doc ann #

prettyList :: [Value] -> Doc ann #

Serialise Value Source # 
Instance details

Defined in PlutusCore.Value

Methods

encode :: Value -> Encoding

decode :: Decoder s Value

encodeList :: [Value] -> Encoding

decodeList :: Decoder s [Value]

PrettyBy ConstConfig Value Source # 
Instance details

Defined in PlutusCore.Pretty.PrettyConst

Methods

prettyBy :: ConstConfig -> Value -> Doc ann #

prettyListBy :: ConstConfig -> [Value] -> Doc ann #

KnownBuiltinTypeIn DefaultUni term Value => MakeKnownIn DefaultUni term Value Source # 
Instance details

Defined in PlutusCore.Default.Universe

KnownBuiltinTypeIn DefaultUni term Value => ReadKnownIn DefaultUni term Value Source # 
Instance details

Defined in PlutusCore.Default.Universe

Methods

readKnown :: term -> ReadKnownM Value Source #

Contains DefaultUni Value Source # 
Instance details

Defined in PlutusCore.Default.Universe

KnownBuiltinTypeAst tyname DefaultUni Value => KnownTypeAst tyname DefaultUni Value Source # 
Instance details

Defined in PlutusCore.Default.Universe

Methods

typeAst :: Type tyname DefaultUni () Source #

type Rep Value Source # 
Instance details

Defined in PlutusCore.Value

type IsBuiltin DefaultUni Value Source # 
Instance details

Defined in PlutusCore.Default.Universe

type ToBinds DefaultUni acc Value Source # 
Instance details

Defined in PlutusCore.Default.Universe

type ToHoles DefaultUni hole Value Source # 
Instance details

Defined in PlutusCore.Default.Universe

data K Source #

A ByteString with maximum length of maxKeyLen bytes.

Instances

Instances details
Generic K Source # 
Instance details

Defined in PlutusCore.Value

Associated Types

type Rep K 
Instance details

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

Methods

from :: K -> Rep K x Source #

to :: Rep K x -> K Source #

Show K Source # 
Instance details

Defined in PlutusCore.Value

Methods

showsPrec :: Int -> K -> ShowS Source #

show :: K -> String Source #

showList :: [K] -> ShowS Source #

NFData K Source # 
Instance details

Defined in PlutusCore.Value

Methods

rnf :: K -> () Source #

Eq K Source # 
Instance details

Defined in PlutusCore.Value

Methods

(==) :: K -> K -> Bool Source #

(/=) :: K -> K -> Bool Source #

Ord K Source # 
Instance details

Defined in PlutusCore.Value

Methods

compare :: K -> K -> Ordering Source #

(<) :: K -> K -> Bool Source #

(<=) :: K -> K -> Bool Source #

(>) :: K -> K -> Bool Source #

(>=) :: K -> K -> Bool Source #

max :: K -> K -> K Source #

min :: K -> K -> K Source #

Hashable K Source # 
Instance details

Defined in PlutusCore.Value

Methods

hashWithSalt :: Int -> K -> Int

hash :: K -> Int

Flat K Source # 
Instance details

Defined in PlutusCore.Value

Methods

encode :: K -> Encoding

decode :: Get K

size :: K -> NumBits -> NumBits

Serialise K Source # 
Instance details

Defined in PlutusCore.Value

Methods

encode :: K -> Encoding

decode :: Decoder s K

encodeList :: [K] -> Encoding

decodeList :: Decoder s [K]

PrettyBy ConstConfig K Source # 
Instance details

Defined in PlutusCore.Pretty.PrettyConst

Methods

prettyBy :: ConstConfig -> K -> Doc ann #

prettyListBy :: ConstConfig -> [K] -> Doc ann #

type Rep K Source # 
Instance details

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

data Quantity Source #

A signed 128-bit integer quantity.

Instances

Instances details
Bounded Quantity Source # 
Instance details

Defined in PlutusCore.Value

Generic Quantity Source # 
Instance details

Defined in PlutusCore.Value

Associated Types

type Rep Quantity 
Instance details

Defined in PlutusCore.Value

type Rep Quantity = D1 ('MetaData "Quantity" "PlutusCore.Value" "plutus-core-1.60.0.0-LXFqBsoUlXsJIEqLytHte7" 'True) (C1 ('MetaCons "UnsafeQuantity" 'PrefixI 'True) (S1 ('MetaSel ('Just "unQuantity") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer)))
Show Quantity Source # 
Instance details

Defined in PlutusCore.Value

NFData Quantity Source # 
Instance details

Defined in PlutusCore.Value

Methods

rnf :: Quantity -> () Source #

Eq Quantity Source # 
Instance details

Defined in PlutusCore.Value

Ord Quantity Source # 
Instance details

Defined in PlutusCore.Value

Hashable Quantity Source # 
Instance details

Defined in PlutusCore.Value

Flat Quantity Source # 
Instance details

Defined in PlutusCore.Value

Methods

encode :: Quantity -> Encoding

decode :: Get Quantity

size :: Quantity -> NumBits -> NumBits

Pretty Quantity Source # 
Instance details

Defined in PlutusCore.Value

Methods

pretty :: Quantity -> Doc ann #

prettyList :: [Quantity] -> Doc ann #

Serialise Quantity Source # 
Instance details

Defined in PlutusCore.Value

Methods

encode :: Quantity -> Encoding

decode :: Decoder s Quantity

encodeList :: [Quantity] -> Encoding

decodeList :: Decoder s [Quantity]

PrettyBy ConstConfig Quantity Source # 
Instance details

Defined in PlutusCore.Pretty.PrettyConst

type Rep Quantity Source # 
Instance details

Defined in PlutusCore.Value

type Rep Quantity = D1 ('MetaData "Quantity" "PlutusCore.Value" "plutus-core-1.60.0.0-LXFqBsoUlXsJIEqLytHte7" 'True) (C1 ('MetaCons "UnsafeQuantity" 'PrefixI 'True) (S1 ('MetaSel ('Just "unQuantity") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer)))

quantity :: Integer -> Maybe Quantity Source #

Smart constructor for Quantity that validates bounds.

zeroQuantity :: Quantity Source #

The zero quantity.

addQuantity :: Quantity -> Quantity -> Maybe Quantity Source #

Safely add two quantities, checking for overflow.

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.

toList :: Value -> [(K, [(K, Quantity)])] Source #

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.

valueData :: Value -> BuiltinResult Data Source #

\(O(n)\). Encodes Value as Data, in the same way as non-builtin Value. This is the denotation of ValueData in Plutus V1, V2 and V3.

unValueData :: Data -> BuiltinResult Value Source #

\(O(n)\). Decodes Data into Value. This is the denotation of UnValueData in Plutus V1, V2 and V3.