Skip to main content

Crate canton_daml

Crate canton_daml 

Source
Expand description

Runtime for canton-codegen-generated Daml bindings.

Generated code depends on this crate (imported as rt) for the Daml primitive types (Party, ContractId, Numeric, Timestamp, Date, TextMap, GenMap), the Template / Interface / Choice traits, the command builders (create_command, exercise_command, exercise_by_key_command), and the ToValue / FromValue codecs that move typed values to and from the Ledger API Value on the wire. The typed read path is Template::from_created_event.

It contains no ledger I/O — it is the thin type/codec layer beneath the generated bindings, kept separate from the codegen tool (which is build-time) and from the client crates (which do the actual RPCs).

§Using it

You rarely name this crate directly: canton-codegen emits bindings that import it as rt. What you do touch are its types, and the three things below — build a payload, turn it into a command, decode a result:

ⓘ
use canton_daml as rt;
use rt::Template as _; // brings `from_created_event` into scope
use my_bindings::my_app::My_Module::{Asset, Asset_Transfer};

// A typed payload, built from the runtime's Daml primitives.
let asset = Asset {
    owner: rt::Party::new("alice::1220ab…"),
    price: "12.50".parse::<rt::Numeric>()?,
    // `None` only for a datetime outside the microsecond range of an `i64`.
    minted_at: rt::Timestamp::from_datetime(time::OffsetDateTime::now_utc())
        .expect("now is representable"),
};

// Commands for the ledger client to submit.
let create = rt::create_command(&asset);
let transfer = rt::exercise_command(&contract_id, &Asset_Transfer {
    new_owner: rt::Party::new("bob::1220cd…"),
});

// The typed read path: a CreatedEvent from a transaction or the ACS.
let read_back: Asset = Asset::from_created_event(&event)?;

Codec failures are ValueError, which converts into canton_core::Error, so one function can call this runtime and the ledger client and use ? on both.

Re-exports§

pub use serde;

Structs§

ContractId
A typed contract id: a handle to a contract of template/type T.
Date
A Daml Date — days since the Unix epoch.
GenMap
A Daml GenMap — a map with an arbitrary key type (key/value pairs on the wire; the LF-JSON form is an array of [key, value] pairs).
Int64
A Daml Int64.
NestedOpt
A Daml Optional nested inside another Optional. Same runtime meaning as Option, but its LF-JSON encoding is the nested-optional list form (None → [], Some(x) → [x]) instead of null/value.
Numeric
A fixed-scale decimal (Numeric), stored as its decimal string — the wire representation (Daml numerics are transmitted as text to avoid binary-float rounding).
NumericParseError
A string that is not a Daml Numeric (a decimal literal).
Party
A Daml Party identifier.
Record
The Ledger API Value and Record — the gRPC wire forms generated ToValue/FromValue/Template::to_record move to and from. Re-exported so generated code can name them as rt::Value / rt::Record. Contains nested values.
Timestamp
A Daml Timestamp — microseconds since the Unix epoch (UTC).
Unit
The Daml Unit type. Its LF-JSON form is the empty object {} — not JSON null, which is what Rust’s () serializes to — so Unit needs its own type with a manual serde impl. This is what a nullary variant constructor and a Unit-typed field map to, so their JSON matches the Ledger API’s {"tag": <ctor>, "value": {}} form. The gRPC (Value) form is the proto Unit.
Value
The Ledger API Value and Record — the gRPC wire forms generated ToValue/FromValue/Template::to_record move to and from. Re-exported so generated code can name them as rt::Value / rt::Record. Encodes values that the ledger accepts as command arguments and emits as contract arguments.
ValueError
An error converting a Ledger API Value into a typed value.

Enums§

PartyParseError
A string that is not a Canton party id.

Traits§

Choice
A choice exercisable on a contract of template T.
Contract
Something with an on-ledger identity that choices can be exercised on: a template or an interface. Its template id is PACKAGE:MODULE:ENTITY.
FromValue
Decode a typed Rust value from a Ledger API Value.
Interface
A Daml interface: a Contract identified by a marker type (held via ContractId), with a view type. Choices are exercised through the interface id, so a ContractId<Interface> can be exercised without knowing the concrete template.
Template
A Daml template: a Contract with a payload codec. Generated code implements this on each template’s payload struct.
ToValue
Encode a typed Rust value as a Ledger API Value.
WithKey
A template that declares a contract key. Generated code implements this on the payload struct of any keyed template, exposing the key’s type so a contract can be looked up and choices exercised by key (see crate::exercise_by_key_command).

Functions§

create_command
A CreateCommand for a new contract of template T from its payload.
exercise_by_key_command
An ExerciseByKeyCommand exercising choice C (with argument) on the contract of template T identified by its contract key.
exercise_command
An ExerciseCommand exercising choice C (with argument) on the contract contract_id of template or interface T.
from_record
Decode a bare wire Record — the shape CreatedEvent.create_arguments carries — into a typed value. See also Template::from_created_event, which wraps this with a template-identity check.

Type Aliases§

TextMap
A Daml TextMap — a map keyed by Text.