canton_token/lib.rs
1//! Canton Network token-standard workflows (CIP-56 and CIP-0112).
2//!
3//! The token-standard **types** are generated from the Splice DARs and live in
4//! the `canton-splice-api-token-*` crates. This crate is the *workflow* over
5//! them: resolving a factory, asking a registry for a choice context,
6//! attaching the contracts it says to disclose, and exercising the choice.
7//!
8//! Nothing here re-declares a Daml type. That would duplicate the code
9//! generator and go stale on the next Splice release; the `Holding` this crate
10//! names is the same Rust type an application reads out of the ledger.
11//!
12//! # Why a registry is involved at all
13//!
14//! A transfer is exercised through an interface, and only the registry knows
15//! what reference data that choice needs — its own configuration contracts,
16//! the rules for an instrument, the current round. So the client asks for a
17//! choice context and gets back both the data to pass in and the contracts the
18//! participant must be shown. Those contracts are usually invisible to the
19//! submitting party, which is exactly what explicit disclosure is for.
20//!
21//! The registry's API is off-ledger HTTP, specified by the token standard's
22//! OpenAPI documents.
23//!
24//! # Scan
25//!
26//! The registry for Amulet is the network's Scan, and Scan publishes more
27//! than the registry routes: the DSO's contracts an application discloses,
28//! traffic balances, the update history, snapshots. [`scan::ScanClient`] is a
29//! typed client for that, asked of a Scan directly or through a validator's
30//! scan-proxy.
31
32#![forbid(unsafe_code)]
33
34pub mod allocation;
35mod context;
36pub mod holdings;
37mod registry;
38pub mod scan;
39pub mod transfer;
40pub mod v2;
41
42pub use context::{ChoiceContext, ChoiceContextRequest, WireChoiceContext, WireDisclosedContract};
43pub use registry::{
44 AllocationChoice, AllocationInstructionChoice, FactoryWithContext, Instrument, RegistryClient,
45 RegistryInfo, TransferInstructionChoice, TransferKind,
46};
47pub use scan::ScanClient;
48/// The V1 (CIP-56) workflow, re-exported at the root because it is the one most
49/// networks run today. The V2 (CIP-0112) workflow keeps the same names and so
50/// stays behind [`v2`] — `token::transfer` and `token::v2::transfer` are
51/// different standards, and the path is what says which you meant.
52pub use transfer::{TokenCommand, accept, reject, transfer, withdraw};
53
54pub mod types {
55 //! The generated token-standard types this crate's API is written in terms
56 //! of, re-exported so they can be named without depending on each
57 //! generated crate directly.
58 //!
59 //! This is not a convenience. `transfer` takes a
60 //! [`Transfer`](v1::transfer_instruction::Transfer) and `v2::transfer`
61 //! takes a [`Transfer`](v2::transfer_instruction::Transfer) — so without
62 //! these a `cargo add canton` user could reach the *functions* through the
63 //! facade and be unable to name their arguments. The whole token
64 //! deliverable was unreachable that way, which is the same defect the
65 //! crate's own conformance suite states the rule against: a capability
66 //! that works only via a member crate is not one `cargo add canton`
67 //! delivers.
68 //!
69 //! Whole modules rather than a hand-listed set of types, because a list
70 //! goes stale the first time the standard adds a record and nothing
71 //! notices.
72
73 /// Metadata — `ExtraArgs`, `ChoiceContext`, `Metadata`. Shared by both
74 /// standards: there is no `metadata-v2`.
75 pub use canton_splice_api_token_metadata_v1::splice_api_token_metadata_v1::Splice_Api_Token_MetadataV1 as metadata;
76
77 /// CIP-56 — the V1 token standard.
78 pub mod v1 {
79 pub use canton_splice_api_token_allocation_instruction_v1::splice_api_token_allocation_instruction_v1::Splice_Api_Token_AllocationInstructionV1 as allocation_instruction;
80 pub use canton_splice_api_token_allocation_v1::splice_api_token_allocation_v1::Splice_Api_Token_AllocationV1 as allocation;
81 pub use canton_splice_api_token_holding_v1::splice_api_token_holding_v1::Splice_Api_Token_HoldingV1 as holding;
82 pub use canton_splice_api_token_transfer_instruction_v1::splice_api_token_transfer_instruction_v1::Splice_Api_Token_TransferInstructionV1 as transfer_instruction;
83 }
84
85 /// CIP-0112 — the V2 token standard.
86 pub mod v2 {
87 pub use canton_splice_api_token_allocation_instruction_v2::splice_api_token_allocation_instruction_v2::Splice_Api_Token_AllocationInstructionV2 as allocation_instruction;
88 pub use canton_splice_api_token_allocation_v2::splice_api_token_allocation_v2::Splice_Api_Token_AllocationV2 as allocation;
89 pub use canton_splice_api_token_holding_v2::splice_api_token_holding_v2::Splice_Api_Token_HoldingV2 as holding;
90 pub use canton_splice_api_token_transfer_events_v2::splice_api_token_transfer_events_v2::Splice_Api_Token_TransferEventsV2 as transfer_events;
91 pub use canton_splice_api_token_transfer_instruction_v2::splice_api_token_transfer_instruction_v2::Splice_Api_Token_TransferInstructionV2 as transfer_instruction;
92 }
93}
94
95/// The V1 `Holding` interface, at the root because it is the type a caller
96/// reaches for first. Everything else is under [`types`].
97pub use canton_splice_api_token_holding_v1::splice_api_token_holding_v1::Splice_Api_Token_HoldingV1::Holding;