values

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package values provides helper utilities for working with Canton Ledger API value types.

Index

Constants

View Source
const MetaKeySymbol = "splice.chainsafe.io/symbol"

Variables

This section is empty.

Functions

func ContractID

func ContractID(v *lapiv2.Value) string

ContractID extracts a contract ID value.

func ContractIDValue

func ContractIDValue(v string) *lapiv2.Value

ContractIDValue returns a contract ID ledger value.

func DecodeInstrumentId

func DecodeInstrumentId(v *lapiv2.Value) (admin, id string)

DecodeInstrumentId extracts admin and id from a Splice InstrumentId record value.

func DecodeMetadata

func DecodeMetadata(v *lapiv2.Value) map[string]string

DecodeMetadata extracts a Splice Metadata { values : TextMap Text } into a Go map.

func DecodeOptionalMetadata

func DecodeOptionalMetadata(v *lapiv2.Value) map[string]string

DecodeOptionalMetadata decodes Optional Metadata from Daml. Returns nil for None.

func DecodeTextMap

func DecodeTextMap(v *lapiv2.Value) map[string]string

DecodeTextMap extracts a Daml TextMap Text value into a Go map.

func EmptyMetadata

func EmptyMetadata() *lapiv2.Value

EmptyMetadata returns an empty Splice Metadata record.

func EncodeExtraArgs

func EncodeExtraArgs(choiceContext map[string]string) *lapiv2.Value

EncodeExtraArgs creates a Splice ExtraArgs { context: ChoiceContext { values: TextMap }, meta: Metadata { values: TextMap } } value. If choiceContext is nil or empty, the context field contains an empty TextMap (default behavior). If choiceContext is populated (e.g., from a Transfer Factory Registry response), its entries are encoded.

func EncodeInstrumentId

func EncodeInstrumentId(admin, id string) *lapiv2.Value

EncodeInstrumentId creates a Splice InstrumentId { admin : Party, id : Text } value.

func EncodeMetadata

func EncodeMetadata(kvs map[string]string) *lapiv2.Value

EncodeMetadata creates a Splice Metadata { values : TextMap Text } value. Keys are sorted for deterministic encoding.

func EncodeOptionalMetadata

func EncodeOptionalMetadata(kvs map[string]string) *lapiv2.Value

EncodeOptionalMetadata encodes Optional Metadata — None if nil/empty, Some if populated.

func Int64Value

func Int64Value(v int64) *lapiv2.Value

Int64Value creates a Daml Int64 value.

func IsNone

func IsNone(v *lapiv2.Value) bool

IsNone returns true if the value is a Daml None (Optional with no value).

func ListValue

func ListValue(elements []*lapiv2.Value) *lapiv2.Value

ListValue creates a Daml List value from a slice of values.

func MapLookupText

func MapLookupText(v *lapiv2.Value, key string) string

MapLookupText looks up a string key in a DAML Map Text Text value. Handles both TextMap (DA.TextMap) and GenMap (DA.Map) encodings. Returns "" when v is nil, not a map, or the key is absent.

func MetaSymbol

func MetaSymbol(v *lapiv2.Value) string

MetaSymbol extracts token symbol from a Splice Metadata value. Splice Metadata is a Record { values : TextMap Text }.

func MetaSymbolFromRecord

func MetaSymbolFromRecord(args *lapiv2.Record) string

MetaSymbolFromRecord extracts the token symbol from a contract's CreateArguments record by finding the "meta" field and decoding its Splice Metadata.

func NestedPartyField

func NestedPartyField(v *lapiv2.Value, field string) string

NestedPartyField accesses a Party field within a nested DAML Record value. Use this for fields like instrumentId.admin. Returns "" when v is nil, not a Record, or the field is absent.

func NestedPartyFieldOK

func NestedPartyFieldOK(v *lapiv2.Value, field string) (string, bool)

NestedPartyFieldOK accesses a Party field within a nested DAML Record value and reports whether the lookup succeeded with the right type.

func NestedTextField

func NestedTextField(v *lapiv2.Value, field string) string

NestedTextField accesses a Text field within a nested DAML Record value. Use this for fields like instrumentId.id where instrumentId is a Record. Returns "" when v is nil, not a Record, or the field is absent.

func NestedTextFieldOK

func NestedTextFieldOK(v *lapiv2.Value, field string) (string, bool)

NestedTextFieldOK accesses a Text field within a nested DAML Record value and reports whether the lookup succeeded with the right type.

func NewtypeText

func NewtypeText(v *lapiv2.Value) string

NewtypeText extracts the inner Text from a DAML newtype encoded as a single-field Record (e.g. EvmAddress = EvmAddress { value : Text }). The DAML Ledger API v2 returns newtype values as Records in CreatedEvent payloads. Returns "" if v is nil, not a Record, or the first field is not Text.

func NewtypeValue

func NewtypeValue(inner *lapiv2.Value) *lapiv2.Value

NewtypeValue encodes a DAML newtype as a single-field Record wrapping the inner value. Use this for types like Common.Types.EvmAddress which are defined as: newtype T = T with field : PrimType. The DAML Ledger API v2 represents newtypes as Records; passing the underlying primitive directly causes COMMAND_PREPROCESSING_FAILED.

The RecordField carries no Label: the Ledger API v2 command-preprocessing path matches newtype fields by position, not by name, so omitting the label is correct and intentional. NewtypeText decodes symmetrically via Fields[0].

func None

func None() *lapiv2.Value

None returns an empty optional value.

func Numeric

func Numeric(v *lapiv2.Value) string

Numeric extracts a numeric value as string.

func NumericOK

func NumericOK(v *lapiv2.Value) (string, bool)

NumericOK extracts a numeric value and reports whether the type matched.

func NumericValue

func NumericValue(v string) *lapiv2.Value

NumericValue returns a numeric ledger value.

func Optional

func Optional(v *lapiv2.Value) *lapiv2.Value

Optional wraps an optional value.

func OptionalParty

func OptionalParty(v *lapiv2.Value) string

OptionalParty extracts a Daml Optional Party value. Returns "" for None.

func OptionalRecordFields

func OptionalRecordFields(v *lapiv2.Value) map[string]*lapiv2.Value

OptionalRecordFields extracts the inner Record fields from an Optional(Record) value. Returns nil when v is None or the inner value is not a Record.

func OptionalText

func OptionalText(v *lapiv2.Value) string

OptionalText extracts a Daml Optional Text value. Returns "" for None.

func Party

func Party(v *lapiv2.Value) string

Party extracts a party value.

func PartyList

func PartyList(v *lapiv2.Value) []string

PartyList extracts list of parties.

func PartyOK

func PartyOK(v *lapiv2.Value) (string, bool)

PartyOK extracts a party value and reports whether the type matched.

func PartyValue

func PartyValue(v string) *lapiv2.Value

PartyValue returns a party ledger value.

func RecordField

func RecordField(v *lapiv2.Value) map[string]*lapiv2.Value

RecordField extracts a named field from a Record value, returning the sub-map. Returns nil when v is nil or not a Record.

func RecordToMap

func RecordToMap(r *lapiv2.Record) map[string]*lapiv2.Value

RecordToMap converts a Ledger API record into a map keyed by field label. Fields without labels are ignored.

func Text

func Text(v *lapiv2.Value) string

Text extracts a text value.

func TextOK

func TextOK(v *lapiv2.Value) (string, bool)

TextOK extracts a text value and reports whether the type matched.

func TextValue

func TextValue(v string) *lapiv2.Value

TextValue returns a text ledger value.

func Timestamp

func Timestamp(v *lapiv2.Value) time.Time

Timestamp extracts timestamp.

func TimestampOK

func TimestampOK(v *lapiv2.Value) (time.Time, bool)

TimestampOK extracts a timestamp and reports whether the type matched.

func TimestampValue

func TimestampValue(t time.Time) *lapiv2.Value

TimestampValue returns a timestamp ledger value.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL