Value

scalus.cardano.onchain.plutus.v1.Value
See theValue companion object
case class Value

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

inline def *(factor: BigInt): Value
Extension method from Value

Extension alias for Value.multiply.

Extension alias for Value.multiply.

Attributes

inline def +(other: Value): Value
Extension method from Value

Extension alias for Value.plus.

Extension alias for Value.plus.

Attributes

inline def -(other: Value): Value
Extension method from Value

Extension alias for Value.minus.

Extension alias for Value.minus.

Attributes

def flatten: List[(PolicyId, TokenName, BigInt)]
Extension method from Value

Flattens the Value into a list of policy id, token name, and amount triples.

Flattens the Value into a list of policy id, token name, and amount triples.

Converts the nested map structure into a flat list representation where each element contains the policy id, token name, and corresponding amount.

Attributes

Returns

A flattened list of tuples containing (policyId, tokenName, amount)

Example
 val value = Value.fromList(
   List.Cons(
     (Value.adaPolicyId, List.Cons((Value.adaTokenName, BigInt(1000000)), List.Nil)),
     List.Cons(
       (ByteString.fromString("ff"), List.Cons((ByteString.fromString("TOKEN"), BigInt(100)), List.Nil)),
       List.Nil
     )
   )
 )
 value.flatten ===
 List.Cons(
    (Value.adaPolicyId, Value.adaTokenName, BigInt(1000000)),
    List.Cons(
      (ByteString.fromString("ff"), ByteString.fromString("TOKEN"), BigInt(100)),
      List.Nil
    )
 )
def getLovelace: BigInt
Extension method from Value

Returns the amount of Lovelace in this Value.

Returns the amount of Lovelace in this Value.

If the Value contains no Lovelace, it returns zero.

Attributes

Returns

The amount of Lovelace in this Value

Example
 val value = Value.lovelace(BigInt(1000000))
 value.getLovelace === BigInt(1000000)
 val emptyValue = Value.zero
 emptyValue.getLovelace === BigInt(0)
inline def isPositive: Boolean
Extension method from Value

Checks if this Value is non-zero and positive, meaning it contains at least one token or currency symbol with a non-zero positive amount and all amounts are positive.

Checks if this Value is non-zero and positive, meaning it contains at least one token or currency symbol with a non-zero positive amount and all amounts are positive.

Attributes

Returns

true if the Value is non-empty and has all positive amounts, false otherwise

inline def isZero: Boolean
Extension method from Value

Checks if this Value is zero, meaning it contains no tokens or currency symbols.

Checks if this Value is zero, meaning it contains no tokens or currency symbols.

Attributes

Returns

true if the Value is empty, false otherwise

Example
 val value = Value.zero
 value.isZero === true
 val nonZeroValue = Value.lovelace(BigInt(1000000))
 nonZeroValue.isZero === false
inline def nonZero: Boolean
Extension method from Value

Checks if this Value is non-zero, meaning it contains at least one token or currency symbol with a non-zero amount.

Checks if this Value is non-zero, meaning it contains at least one token or currency symbol with a non-zero amount.

Attributes

Returns

true if the Value is non-empty, false otherwise

Example
 val value = Value.zero
 value.nonZero === false
 val nonZeroValue = Value.lovelace(BigInt(1000000))
 nonZeroValue.nonZero === true
Extension method from Value

A list of all policy ids in that scalus.cardano.onchain.plutus.v1.Value with non-zero tokens.

A list of all policy ids in that scalus.cardano.onchain.plutus.v1.Value with non-zero tokens.

Attributes

Returns

A list of sorted scalus.cardano.onchain.plutus.v1.PolicyId

Example
 val value = Value.fromList(
   List.Cons(
     (Value.adaPolicyId, List.Cons((Value.adaTokenName, BigInt(1000000)), List.Nil)),
     List.Cons(
       (ByteString.fromString("ff"), List.Cons((ByteString.fromString("TOKEN"), BigInt(100)), List.Nil)),
       List.Nil
     )
   )
 )
 value.policyIds ===
 List.Cons(
    Value.adaPolicyId,
    List.Cons(
      ByteString.fromString("ff"),
      List.Nil
    )
 )
def quantityOf(cs: PolicyId, tn: TokenName): BigInt
Extension method from Value

Gets the amount of a specific token in a policy id from a Value.

Gets the amount of a specific token in a policy id from a Value.

Returns the token amount for the given policy id and token name pair. If either the policy id or token name is not found, returns zero.

Value parameters

cs

The policy id to look up

tn

The token name to look up within that policy id

Attributes

Returns

The amount of the specified token, or zero if not found

Example
 val value = Value.fromList(
   List.Cons(
     (Value.adaPolicyId, List.Cons((Value.adaTokenName, BigInt(1000000)), List.Nil)),
     List.Cons(
       (ByteString.fromString("ff"), List.Cons((ByteString.fromString("TOKEN"), BigInt(100)), List.Nil)),
       List.Nil
     )
   )
 )
 value.quantityOf(Value.adaPolicyId, Value.adaTokenName) === BigInt(1000000)
 value.quantityOf(ByteString.fromString("ff"), ByteString.fromString("TOKEN")) === BigInt(100)
 value.quantityOf(ByteString.fromString("missing"), ByteString.fromString("TOKEN")) === BigInt(0)
inline def showDebug: String
Extension method from Value

Extension alias for Value.debugToString.

Extension alias for Value.debugToString.

Attributes

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
def tokens(cs: PolicyId): SortedMap[TokenName, BigInt]
Extension method from Value

Get all tokens associated with a given policy.

Get all tokens associated with a given policy.

Returns the token SortedMap for the given policy id. If the policy id is not found, returns an empty SortedMap.

Value parameters

cs

The policy id to look up

Attributes

Returns

The SortedMap of the specified token, or an empty SortedMap if not found

Example
 val value = Value.fromList(
   List.Cons(
     (Value.adaPolicyId, List.Cons((Value.adaTokenName, BigInt(1000000)), List.Nil)),
     List.Cons(
       (utf8"ff", List.Cons((utf8"TOKEN", BigInt(100)), List.Nil)),
       List.Nil
     )
   )
 )
 value.quantityOf(Value.adaPolicyId) === SortedMap.singleton(Value.adaTokenName, BigInt(1000000))
 value.quantityOf(utf8"ff") === SortedMap.singleton(utf8"TOKEN", BigInt(100))
 value.quantityOf(utf8"missing") === SortedMap.empty
inline def unary_-: Value
Extension method from Value

Extension alias for Value.negate.

Extension alias for Value.negate.

Attributes

Extension method from Value

Returns a new Value with all ADA/Lovelace tokens removed.

Returns a new Value with all ADA/Lovelace tokens removed.

This method creates a copy of the value with the ADA policy id removed, effectively removing all Lovelace tokens while preserving other tokens.

Attributes

Returns

A new Value without any Lovelace tokens

Example
 val value = Value.fromList(
   List.Cons(
     (Value.adaPolicyId, List.Cons((Value.adaTokenName, BigInt(1000000)), List.Nil)),
     List.Cons(
       (ByteString.fromString("ff"), List.Cons((ByteString.fromString("TOKEN"), BigInt(100)), List.Nil)),
       List.Nil
     )
   )
 )
 val withoutAda = Value.fromList(
   List.Cons(
     (ByteString.fromString("ff"), List.Cons((ByteString.fromString("TOKEN"), BigInt(100)), List.Nil)),
     List.Nil
   )
 )
 value.withoutLovelace === withoutAda

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product
Extension method from Value

Converts this Value to a scalus.cardano.ledger.Value

Converts this Value to a scalus.cardano.ledger.Value

Attributes

Throws
IllegalArgumentException

if AssetName exceeds 32 bytes (thrown by AssetName constructor)

Inherited from:
ValueOffchainOps (hidden)