Skip to main content

Client

Struct Client 

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

Client for the Transaction Resolve Protocol (TRP).

This client provides methods for interacting with a TRP server to resolve transaction templates, submit signed transactions, and monitor transaction status.

The client is cloneable and can be reused across multiple requests.

§Example

use tx3_sdk::trp::{Client, ClientOptions};

let client = Client::new(ClientOptions {
    endpoint: "https://trp.example.com".to_string(),
    headers: None,
});

// Use the client for multiple operations
let tx = client.resolve(params).await?;
let status = client.check_status(vec![tx.hash]).await?;

Implementations§

Source§

impl Client

Source

pub fn new(options: ClientOptions) -> Self

Creates a new TRP client with the given options.

§Arguments
  • options - Configuration options including endpoint URL and optional headers
§Example
use tx3_sdk::trp::{Client, ClientOptions};

let client = Client::new(ClientOptions {
    endpoint: "https://trp.example.com".to_string(),
    headers: None,
});
Source

pub async fn call(&self, method: &str, params: Value) -> Result<Value, Error>

Makes a raw JSON-RPC call to the TRP server.

This is a low-level method for making JSON-RPC calls. Generally, you should use the higher-level methods like resolve, submit, etc.

§Arguments
  • method - The JSON-RPC method name
  • params - The method parameters as a JSON value
§Returns

Returns the result as a JSON value on success, or an error on failure.

Source

pub async fn resolve(&self, request: ResolveParams) -> Result<TxEnvelope, Error>

Resolves a transaction template into a concrete transaction.

This method takes a Transaction Intermediate Representation (TIR) envelope and arguments, and resolves it into a concrete UTxO transaction ready for signing.

§Arguments
  • request - The resolve parameters including TIR and arguments
§Returns

Returns a TxEnvelope containing the resolved transaction hash and CBOR bytes.

§Errors

Can return various errors including:

  • Error::UnsupportedTir if the TIR version is not supported
  • Error::MissingTxArg if required arguments are missing
  • Error::InputNotResolved if an input cannot be found
  • Error::TxScriptFailure if script execution fails
§Example
use tx3_sdk::trp::{Client, ResolveParams};
use tx3_sdk::core::TirEnvelope;

let client = Client::new(/* ... */);

let params = ResolveParams {
    tir: TirEnvelope { /* ... */ },
    args: serde_json::Map::new(),
    env: None,
};

let tx = client.resolve(params).await?;
println!("Resolved hash: {}", tx.hash);
Source

pub async fn submit( &self, request: SubmitParams, ) -> Result<SubmitResponse, Error>

Submits a signed transaction to the network.

This method submits a signed transaction with its witnesses to the blockchain network via the TRP server.

§Arguments
  • request - The submit parameters including transaction bytes and witnesses
§Returns

Returns a SubmitResponse containing the submitted transaction hash.

§Example
use tx3_sdk::trp::{Client, SubmitParams, TxWitness, WitnessType};
use tx3_sdk::core::BytesEnvelope;

let client = Client::new(/* ... */);

let params = SubmitParams {
    tx: BytesEnvelope { /* signed tx */ },
    witnesses: vec![TxWitness { /* ... */ }],
};

let response = client.submit(params).await?;
println!("Submitted: {}", response.hash);
Source

pub async fn check_status( &self, hashes: Vec<String>, ) -> Result<CheckStatusResponse, Error>

Checks the status of one or more transactions.

This method queries the TRP server for the current status of the specified transactions.

§Arguments
  • hashes - Vector of transaction hashes to check
§Returns

Returns a CheckStatusResponse containing a map of transaction hashes to their current status.

§Example
use tx3_sdk::trp::Client;

let client = Client::new(/* ... */);

let hashes = vec!["abc123...".to_string()];
let status = client.check_status(hashes).await?;

for (hash, tx_status) in status.statuses {
    println!("{}: {:?}", hash, tx_status.stage);
}
Source

pub async fn dump_logs( &self, cursor: Option<u64>, limit: Option<u64>, include_payload: Option<bool>, ) -> Result<DumpLogsResponse, Error>

Dumps transaction logs with optional pagination.

This method retrieves a paginated list of transaction log entries, useful for monitoring and auditing transaction history.

§Arguments
  • cursor - Optional pagination cursor for fetching specific pages
  • limit - Optional limit on the number of entries to return
  • include_payload - Whether to include transaction payloads in the response
§Returns

Returns a DumpLogsResponse containing log entries and an optional next cursor for pagination.

§Example
use tx3_sdk::trp::Client;

let client = Client::new(/* ... */);

// Get first page with 100 entries
let logs = client.dump_logs(None, Some(100), Some(false)).await?;

for entry in logs.entries {
    println!("{}: {:?}", entry.hash, entry.stage);
}

// Get next page if available
if let Some(next) = logs.next_cursor {
    let more_logs = client.dump_logs(Some(next), Some(100), Some(false)).await?;
}
Source

pub async fn peek_pending( &self, limit: Option<u64>, include_payload: Option<bool>, ) -> Result<PeekPendingResponse, Error>

Peeks at pending transactions in the mempool.

This method retrieves pending transactions that are waiting to be included in a block, useful for monitoring mempool state.

§Arguments
  • limit - Optional limit on the number of pending transactions to return
  • include_payload - Whether to include transaction payloads in the response
§Returns

Returns a PeekPendingResponse containing pending transactions.

§Example
use tx3_sdk::trp::Client;

let client = Client::new(/* ... */);

let pending = client.peek_pending(Some(50), Some(false)).await?;

println!("Found {} pending transactions", pending.entries.len());
if pending.has_more {
    println!("More transactions available");
}
Source

pub async fn peek_inflight( &self, limit: Option<u64>, include_payload: Option<bool>, ) -> Result<PeekInflightResponse, Error>

Peeks at in-flight transactions being tracked by the server.

This method retrieves transactions that have been submitted and are being tracked through their lifecycle stages.

§Arguments
  • limit - Optional limit on the number of in-flight transactions to return
  • include_payload - Whether to include transaction payloads in the response
§Returns

Returns a PeekInflightResponse containing in-flight transactions.

§Example
use tx3_sdk::trp::Client;

let client = Client::new(/* ... */);

let inflight = client.peek_inflight(Some(50), Some(false)).await?;

for tx in inflight.entries {
    println!("{}: {:?} ({} confirmations)",
        tx.hash, tx.stage, tx.confirmations);
}

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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,