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§
- Contract
Id - 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. - Nested
Opt - A Daml
Optionalnested inside anotherOptional. Same runtime meaning asOption, but its LF-JSON encoding is the nested-optional list form (None → [],Some(x) → [x]) instead ofnull/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). - Numeric
Parse Error - A string that is not a Daml
Numeric(a decimal literal). - Party
- A Daml
Partyidentifier. - Record
- The Ledger API
ValueandRecord— the gRPC wire forms generatedToValue/FromValue/Template::to_recordmove to and from. Re-exported so generated code can name them asrt::Value/rt::Record. Contains nested values. - Timestamp
- A Daml
Timestamp— microseconds since the Unix epoch (UTC). - Unit
- The Daml
Unittype. Its LF-JSON form is the empty object{}— not JSONnull, which is what Rust’s()serializes to — soUnitneeds its own type with a manual serde impl. This is what a nullary variant constructor and aUnit-typed field map to, so their JSON matches the Ledger API’s{"tag": <ctor>, "value": {}}form. The gRPC (Value) form is the protoUnit. - Value
- The Ledger API
ValueandRecord— the gRPC wire forms generatedToValue/FromValue/Template::to_recordmove to and from. Re-exported so generated code can name them asrt::Value/rt::Record. Encodes values that the ledger accepts as command arguments and emits as contract arguments. - Value
Error - An error converting a Ledger API
Valueinto a typed value.
Enums§
- Party
Parse Error - 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. - From
Value - Decode a typed Rust value from a Ledger API
Value. - Interface
- A Daml interface: a
Contractidentified by a marker type (held viaContractId), with a view type. Choices are exercised through the interface id, so aContractId<Interface>can be exercised without knowing the concrete template. - Template
- A Daml template: a
Contractwith 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
CreateCommandfor a new contract of templateTfrom its payload. - exercise_
by_ key_ command - An
ExerciseByKeyCommandexercising choiceC(withargument) on the contract of templateTidentified by its contractkey. - exercise_
command - An
ExerciseCommandexercising choiceC(withargument) on the contractcontract_idof template or interfaceT. - from_
record - Decode a bare wire
Record— the shapeCreatedEvent.create_argumentscarries — into a typed value. See alsoTemplate::from_created_event, which wraps this with a template-identity check.
Type Aliases§
- TextMap
- A Daml
TextMap— a map keyed byText.