canton-api-client

Crates.iocanton-api-client
lib.rscanton-api-client
version3.3.0-0.1.1
created_at2025-05-16 16:17:19.223689+00
updated_at2025-08-26 17:28:39.021669+00
descriptionCanton Ledger API rust client
homepage
repository
max_upload_size
id1676661
size945,147
Robert Tera (scolear)

documentation

README

Rust API client for canton-api-client

A rust client for Canton JSON API.

Published to crates.io and available on docs.rs.

Note that POST /v2/packages package uploads are not supported yet.

Overview

This API client was generated by the OpenAPI Generator project. By using the openapi-spec from a remote server, you can easily generate an API client.

  • API version: 3.3.0-SNAPSHOT
  • Package version: 3.3.0-0.1.0
  • Generator version: 7.13.0
  • Build package: org.openapitools.codegen.languages.RustClientCodegen

Installation

Put the package under your project folder in a directory named canton-api-client and add the following to Cargo.toml under [dependencies]:

canton-api-client = { path = "./canton-api-client" }

Or add using cargo:

cargo add canton-api-client

Usage

use canton_api_client::apis::configuration::Configuration;
use canton_api_client::apis::default_api as canton_api;
use canton_api_client::models;
use std::error::Error;
use log::{info, LevelFilter};
use simple_logger::SimpleLogger;

// Create a struct to hold our API client
struct CantonClient {
    configuration: Configuration,
}

impl CantonClient {
    // Constructor to create a new instance with the given auth token
    fn new(auth_token: String, base_url: String) -> Self {
        let configuration = Configuration {
            base_path: base_url,
            bearer_access_token: Some(auth_token),
            ..Configuration::default()
        };

        CantonClient { configuration }
    }

    // Method to get the ledger end
    pub async fn get_ledger_end(&self) -> Result<models::GetLedgerEndResponse, Box<dyn Error>> {
        let response = canton_api::get_v2_state_ledger_end(&self.configuration).await?;
        Ok(response)
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Initialize logger
    SimpleLogger::new()
        .with_level(LevelFilter::Info)
        .init()
        .unwrap();

    // Set up API client with auth token
    let auth_token = "your_auth_token".to_string();
    let base_url = "http://localhost:7575".to_string();
    let client = CantonClient::new(auth_token, base_url);

    // Call the API method
    info!("Fetching ledger end from Canton API...");
    match client.get_ledger_end().await {
        Ok(response) => {
            info!("Successfully retrieved ledger end: {:?}", response);
        },
        Err(e) => {
            eprintln!("Error getting ledger end: {}", e);
            return Err(e);
        }
    }

    Ok(())
}

Note about enum variants

// We need to implement the conversion from ExerciseCommand (and similar types) to Command
// This is a workaround for the fact that the generated code does not expose
// the enum variants directly,
// See https://github.com/Ixrec/rust-orphan-rules
pub trait ExerciseCommandExt {
    fn into_command_enum_variant(self) -> models::Command;
}

impl ExerciseCommandExt for models::ExerciseCommand {
    fn into_command_enum_variant(self) -> models::Command {
        let specific_payload = models::CommandOneOf3::new(self);
        models::Command::CommandOneOf3(Box::new(specific_payload))
    }
}

// Then you can use it like this:
let js_commands = models::JsCommands {
  command_id: create_random_command_id(),
  commands: Some(vec![models::ExerciseCommand {
      template_id: "some_template_id".to_string(),
      contract_id: "some_contract_id".to_string(),
      choice: "choice".to_string(),
      choice_argument: Some(
          serde_json::json!({"key": "value"}),
      ),
  }
  .into_command_enum_variant()]), //NOTE:!
  act_as: Some(vec![some_party_id.clone()]),
  user_id: Some("some_user_id".to_string()),
  ..models::JsCommands::default()
};

Documentation for API Endpoints

All URIs are relative to http://localhost

Class Method HTTP request Description
DefaultApi delete_v2_idps_idp_id DELETE /v2/idps/{idp_id}
DefaultApi delete_v2_users_user_id DELETE /v2/users/{user_id}
DefaultApi get_v2_idps GET /v2/idps
DefaultApi get_v2_idps_idp_id GET /v2/idps/{idp_id}
DefaultApi get_v2_interactive_submission_preferred_package_version GET /v2/interactive-submission/preferred-package-version
DefaultApi get_v2_packages GET /v2/packages
DefaultApi get_v2_packages_package_id GET /v2/packages/{package_id}
DefaultApi get_v2_packages_package_id_status GET /v2/packages/{package_id}/status
DefaultApi get_v2_parties GET /v2/parties
DefaultApi get_v2_parties_participant_id GET /v2/parties/participant-id
DefaultApi get_v2_parties_party GET /v2/parties/{party}
DefaultApi get_v2_state_connected_synchronizers GET /v2/state/connected-synchronizers
DefaultApi get_v2_state_latest_pruned_offsets GET /v2/state/latest-pruned-offsets
DefaultApi get_v2_state_ledger_end GET /v2/state/ledger-end
DefaultApi get_v2_updates_transaction_tree_by_id_update_id GET /v2/updates/transaction-tree-by-id/{update_id}
DefaultApi get_v2_updates_transaction_tree_by_offset_offset GET /v2/updates/transaction-tree-by-offset/{offset}
DefaultApi get_v2_users GET /v2/users
DefaultApi get_v2_users_user_id GET /v2/users/{user_id}
DefaultApi get_v2_users_user_id_rights GET /v2/users/{user_id}/rights
DefaultApi get_v2_version GET /v2/version
DefaultApi patch_v2_idps_idp_id PATCH /v2/idps/{idp_id}
DefaultApi patch_v2_parties_party PATCH /v2/parties/{party}
DefaultApi patch_v2_users_user_id PATCH /v2/users/{user_id}
DefaultApi patch_v2_users_user_id_identity_provider_id PATCH /v2/users/{user_id}/identity-provider-id
DefaultApi patch_v2_users_user_id_rights PATCH /v2/users/{user_id}/rights
DefaultApi post_v2_commands_async_submit POST /v2/commands/async/submit
DefaultApi post_v2_commands_async_submit_reassignment POST /v2/commands/async/submit-reassignment
DefaultApi post_v2_commands_completions POST /v2/commands/completions
DefaultApi post_v2_commands_submit_and_wait POST /v2/commands/submit-and-wait
DefaultApi post_v2_commands_submit_and_wait_for_reassignment POST /v2/commands/submit-and-wait-for-reassignment
DefaultApi post_v2_commands_submit_and_wait_for_transaction POST /v2/commands/submit-and-wait-for-transaction
DefaultApi post_v2_commands_submit_and_wait_for_transaction_tree POST /v2/commands/submit-and-wait-for-transaction-tree
DefaultApi post_v2_events_events_by_contract_id POST /v2/events/events-by-contract-id
DefaultApi post_v2_idps POST /v2/idps
DefaultApi post_v2_interactive_submission_execute POST /v2/interactive-submission/execute
DefaultApi post_v2_interactive_submission_prepare POST /v2/interactive-submission/prepare
DefaultApi post_v2_packages POST /v2/packages
DefaultApi post_v2_parties POST /v2/parties
DefaultApi post_v2_state_active_contracts POST /v2/state/active-contracts
DefaultApi post_v2_updates_flats POST /v2/updates/flats
DefaultApi post_v2_updates_transaction_by_id POST /v2/updates/transaction-by-id
DefaultApi post_v2_updates_transaction_by_offset POST /v2/updates/transaction-by-offset
DefaultApi post_v2_updates_trees POST /v2/updates/trees
DefaultApi post_v2_updates_update_by_id POST /v2/updates/update-by-id
DefaultApi post_v2_updates_update_by_offset POST /v2/updates/update-by-offset
DefaultApi post_v2_users POST /v2/users
DefaultApi post_v2_users_user_id_rights POST /v2/users/{user_id}/rights

Documentation For Models

To get access to the crate's generated documentation, use:


cargo doc --open

Author


Commit count: 0

cargo fmt