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
impl DamlJsonClient
Sourcepub fn new(
url: impl Into<String>,
token: Option<String>,
) -> DamlJsonResult<Self>
pub fn new( url: impl Into<String>, token: Option<String>, ) -> DamlJsonResult<Self>
Create a new DamlJsonClient.
Sourcepub fn new_from_config(config: DamlJsonClientConfig) -> DamlJsonResult<Self>
pub fn new_from_config(config: DamlJsonClientConfig) -> DamlJsonResult<Self>
Create a new DamlJsonClient from a DamlJsonClientConfig.
Sourcepub const fn config(&self) -> &DamlJsonClientConfig
pub const fn config(&self) -> &DamlJsonClientConfig
Return the current configuration.
Sourcepub async fn create(
&self,
template_id: &str,
payload: Value,
) -> DamlJsonResult<DamlJsonCreatedEvent>
pub async fn create( &self, template_id: &str, payload: Value, ) -> DamlJsonResult<DamlJsonCreatedEvent>
Create a new Daml contract.
Sourcepub async fn create_with_meta(
&self,
template_id: &str,
payload: Value,
meta: DamlJsonRequestMeta,
) -> DamlJsonResult<DamlJsonCreatedEvent>
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.
Sourcepub async fn exercise(
&self,
template_id: &str,
contract_id: &str,
choice: &str,
argument: Value,
) -> DamlJsonResult<DamlJsonExerciseResult>
pub async fn exercise( &self, template_id: &str, contract_id: &str, choice: &str, argument: Value, ) -> DamlJsonResult<DamlJsonExerciseResult>
Exercise a Daml choice by contract id.
Sourcepub async fn exercise_by_key(
&self,
template_id: &str,
key: Value,
choice: &str,
argument: Value,
) -> DamlJsonResult<DamlJsonExerciseResult>
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.
Sourcepub async fn create_and_exercise(
&self,
template_id: &str,
payload: Value,
choice: &str,
argument: Value,
) -> DamlJsonResult<DamlJsonExerciseResult>
pub async fn create_and_exercise( &self, template_id: &str, payload: Value, choice: &str, argument: Value, ) -> DamlJsonResult<DamlJsonExerciseResult>
Create and exercise a Daml choice.
Sourcepub async fn fetch(
&self,
contract_id: &str,
) -> DamlJsonResult<DamlJsonCreatedEvent>
pub async fn fetch( &self, contract_id: &str, ) -> DamlJsonResult<DamlJsonCreatedEvent>
Fetch a Daml contract by id.
Sourcepub async fn fetch_by_key(
&self,
template_id: &str,
key: Value,
) -> DamlJsonResult<DamlJsonCreatedEvent>
pub async fn fetch_by_key( &self, template_id: &str, key: Value, ) -> DamlJsonResult<DamlJsonCreatedEvent>
Fetch a Daml contract by key.
Sourcepub async fn query_all(&self) -> DamlJsonResult<Vec<DamlJsonCreatedEvent>>
pub async fn query_all(&self) -> DamlJsonResult<Vec<DamlJsonCreatedEvent>>
List all currently active contracts for all known templates.
Sourcepub async fn query<S: Into<String> + Debug>(
&self,
template_ids: Vec<S>,
query: Value,
) -> DamlJsonResult<Vec<DamlJsonCreatedEvent>>
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.
Sourcepub async fn fetch_parties<S: Into<String> + Debug>(
&self,
parties: Vec<S>,
) -> DamlJsonResult<Vec<DamlJsonParty>>
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.
Sourcepub async fn fetch_parties_with_unknown<S: Into<String> + Debug>(
&self,
parties: Vec<S>,
) -> DamlJsonResult<(Vec<DamlJsonParty>, Vec<String>)>
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.
Sourcepub async fn fetch_all_parties(&self) -> DamlJsonResult<Vec<DamlJsonParty>>
pub async fn fetch_all_parties(&self) -> DamlJsonResult<Vec<DamlJsonParty>>
Fetch all known Parties.
Sourcepub async fn allocate_party(
&self,
identifier_hint: Option<&str>,
display_name: Option<&str>,
) -> DamlJsonResult<DamlJsonParty>
pub async fn allocate_party( &self, identifier_hint: Option<&str>, display_name: Option<&str>, ) -> DamlJsonResult<DamlJsonParty>
Allocate Party.
Sourcepub async fn list_packages(&self) -> DamlJsonResult<Vec<String>>
pub async fn list_packages(&self) -> DamlJsonResult<Vec<String>>
List All DALF packages
Sourcepub async fn download_package(
&self,
package_id: &str,
) -> DamlJsonResult<Vec<u8>>
pub async fn download_package( &self, package_id: &str, ) -> DamlJsonResult<Vec<u8>>
Download a DALF package.
Sourcepub async fn upload_dar(&self, content: Vec<u8>) -> DamlJsonResult<()>
pub async fn upload_dar(&self, content: Vec<u8>) -> DamlJsonResult<()>
Upload a DAR file.
Auto Trait Implementations§
impl Freeze for DamlJsonClient
impl !RefUnwindSafe for DamlJsonClient
impl Send for DamlJsonClient
impl Sync for DamlJsonClient
impl Unpin for DamlJsonClient
impl !UnwindSafe for DamlJsonClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request