plutus-core-1.69.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
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 ∷ Type → Type Source #

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 Source #

hash ∷ Value → Int Source #

ExMemoryUsage Value Source #

Measure the size of a Value by its totalSize.

Instance details

Defined in PlutusCore.Evaluation.Machine.ExMemoryUsage

Flat Value Source # 
Instance details

Defined in PlutusCore.Value

Pretty Value Source # 
Instance details

Defined in PlutusCore.Value

Methods

pretty ∷ Value → Doc ann Source #

prettyList ∷ [Value] → Doc ann Source #

Serialise Value Source # 
Instance details

Defined in PlutusCore.Value

PrettyBy ConstConfig Value Source # 
Instance details

Defined in PlutusCore.Pretty.PrettyConst

Methods

prettyBy ∷ ConstConfig → Value → Doc ann Source #

prettyListBy ∷ ConstConfig → [Value] → Doc ann Source #

KnownBuiltinTypeIn DefaultUni term Value ⇒ MakeKnownIn DefaultUni term Value Source # 
Instance details

Defined in PlutusCore.Default.Universe

Methods

makeKnown ∷ Value → BuiltinResult term Source #

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 ∷ Type → Type Source #

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 Source #

hash ∷ K → Int Source #

Flat K Source # 
Instance details

Defined in PlutusCore.Value

Methods

encode ∷ K → Encoding Source #

decode ∷ Get K Source #

size ∷ K → NumBits → NumBits Source #

Serialise K Source # 
Instance details

Defined in PlutusCore.Value

PrettyBy ConstConfig K Source # 
Instance details

Defined in PlutusCore.Pretty.PrettyConst

Methods

prettyBy ∷ ConstConfig → K → Doc ann Source #

prettyListBy ∷ ConstConfig → [K] → Doc ann Source #

type Rep K Source # 
Instance details

Defined in PlutusCore.Value

type Rep K = D1 ('MetaData "K" "PlutusCore.Value" "plutus-core-1.69.0.0-inplace" '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 ∷ Type → Type Source #

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

Pretty Quantity Source # 
Instance details

Defined in PlutusCore.Value

Methods

pretty ∷ Quantity → Doc ann Source #

prettyList ∷ [Quantity] → Doc ann Source #

Serialise Quantity Source # 
Instance details

Defined in PlutusCore.Value

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.69.0.0-inplace" '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))\)

policies ∷ Value → [ByteString] Source #

\(O(m)\), where \(m\) is the size of the outer map. The currency symbols in the Value, in ascending order, including the lovelace currency symbol (the empty bytestring) if present.

keepPolicies ∷ [ByteString] → Value → Value Source #

The Value restricted to the given currency symbols.

\(O(p \log p + m + n')\), where \(p\) is the length of the policy list, \(m\) is the size of the outer map and \(n'\) is the total size of the result.

Ids the Value does not have, including any longer than maxKeyLen, are ignored. Restricting the outer map can neither empty an inner map nor zero a quantity, so the result is already normalized and this can use pack' rather than pack.

dropPolicies ∷ [ByteString] → Value → Value Source #

The Value with the given currency symbols removed.

\(O(p \log m + d)\), where \(p\) is the length of the policy list, \(m\) is the size of the outer map and \(d\) is the total size of the dropped currencies.

Ids the Value does not have, including any longer than maxKeyLen, are ignored.

keepPolicies rebuilds the caches by folding its result. This subtracts each dropped currency's contribution instead, so the currencies that stay are never looked at: dropping two of them from a huge Value costs the two, not the whole Value.

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.

buildValueWith Source #

Arguments

∷ ∀ m a b. MonadFail m 
⇒ String 
→ (a → m (K, [b]))

Convert an outer entry into (currency, inner entries)

→ (b → m (K, Quantity))

Convert an inner entry into (token, quantity)

→ [a] 
→ m Value 

Build a Value from a list of entries. It fails unless the following conditions are met:

  • currency symbols are strictly ascending
  • token names are strictly ascending
  • every quantity is within bounds
  • no zero quantity