DamlJsonClient

Struct DamlJsonClient 

Source
pub struct DamlJsonClient { /* private fields */ }
Expand description

Daml JSON API client.

See here for full details of the Daml JSON API.

§Examples

The following example connects to a Daml ledger via the JSON API and creates a contract:

use serde_json::json;
use daml_json::service::DamlJsonClientBuilder;
use daml_json::error::DamlJsonResult;
#[tokio::main]
async fn main() -> DamlJsonResult<()> {
    let payload = json!({ "sender": "Alice", "receiver": "Bob", "count": "0" });
    let client = DamlJsonClientBuilder::url("https://api.myledger.org")
        .with_auth("...token...".into())
        .build()?;
    let create_response = client.create("Fuji.PingPong:Ping", payload.clone()).await?;
    assert_eq!(create_response.payload, payload);
    Ok(())
}

Implementations§

Source§

impl DamlJsonClient

Source

pub fn new( url: impl Into<String>, token: Option<String>, ) -> DamlJsonResult<Self>

Create a new DamlJsonClient.

Source

pub fn new_from_config(config: DamlJsonClientConfig) -> DamlJsonResult<Self>

Create a new DamlJsonClient from a DamlJsonClientConfig.

Source

pub const fn config(&self) -> &DamlJsonClientConfig

Return the current configuration.

Source

pub async fn create( &self, template_id: &str, payload: Value, ) -> DamlJsonResult<DamlJsonCreatedEvent>

Create a new Daml contract.

Source

pub async fn create_with_meta( &self, template_id: &str, payload: Value, meta: DamlJsonRequestMeta, ) -> DamlJsonResult<DamlJsonCreatedEvent>

Create a new Daml Contract with optional meta field.

Source

pub async fn exercise( &self, template_id: &str, contract_id: &str, choice: &str, argument: Value, ) -> DamlJsonResult<DamlJsonExerciseResult>

Exercise a Daml choice by contract id.

Source

pub async fn exercise_by_key( &self, template_id: &str, key: Value, choice: &str, argument: Value, ) -> DamlJsonResult<DamlJsonExerciseResult>

Exercise a Daml choice by contract key.

Source

pub async fn create_and_exercise( &self, template_id: &str, payload: Value, choice: &str, argument: Value, ) -> DamlJsonResult<DamlJsonExerciseResult>

Create and exercise a Daml choice.

Source

pub async fn fetch( &self, contract_id: &str, ) -> DamlJsonResult<DamlJsonCreatedEvent>

Fetch a Daml contract by id.

Source

pub async fn fetch_by_key( &self, template_id: &str, key: Value, ) -> DamlJsonResult<DamlJsonCreatedEvent>

Fetch a Daml contract by key.

Source

pub async fn query_all(&self) -> DamlJsonResult<Vec<DamlJsonCreatedEvent>>

List all currently active contracts for all known templates.

Source

pub async fn query<S: Into<String> + Debug>( &self, template_ids: Vec<S>, query: Value, ) -> DamlJsonResult<Vec<DamlJsonCreatedEvent>>

List currently active contracts that match a given query.

Source

pub async fn fetch_parties<S: Into<String> + Debug>( &self, parties: Vec<S>, ) -> DamlJsonResult<Vec<DamlJsonParty>>

Fetch Daml Parties by identifiers.

Retrieve the DamlJsonParty entries for the given parties identifiers. Unknown parties are silently discarded.

Source

pub async fn fetch_parties_with_unknown<S: Into<String> + Debug>( &self, parties: Vec<S>, ) -> DamlJsonResult<(Vec<DamlJsonParty>, Vec<String>)>

Fetch Daml Parties and unknown Daml Parties by identifiers.

Retrieve the DamlJsonParty entries for the given parties identifiers and unknown party identifiers.

Source

pub async fn fetch_all_parties(&self) -> DamlJsonResult<Vec<DamlJsonParty>>

Fetch all known Parties.

Source

pub async fn allocate_party( &self, identifier_hint: Option<&str>, display_name: Option<&str>, ) -> DamlJsonResult<DamlJsonParty>

Allocate Party.

Source

pub async fn list_packages(&self) -> DamlJsonResult<Vec<String>>

List All DALF packages

Source

pub async fn download_package( &self, package_id: &str, ) -> DamlJsonResult<Vec<u8>>

Download a DALF package.

Source

pub async fn upload_dar(&self, content: Vec<u8>) -> DamlJsonResult<()>

Upload a DAR file.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,