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
impl Client
Sourcepub fn new(options: ClientOptions) -> Self
pub fn new(options: ClientOptions) -> Self
Sourcepub async fn call(&self, method: &str, params: Value) -> Result<Value, Error>
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 nameparams- The method parameters as a JSON value
§Returns
Returns the result as a JSON value on success, or an error on failure.
Sourcepub async fn resolve(&self, request: ResolveParams) -> Result<TxEnvelope, Error>
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::UnsupportedTirif the TIR version is not supportedError::MissingTxArgif required arguments are missingError::InputNotResolvedif an input cannot be foundError::TxScriptFailureif 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);Sourcepub async fn submit(
&self,
request: SubmitParams,
) -> Result<SubmitResponse, Error>
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);Sourcepub async fn check_status(
&self,
hashes: Vec<String>,
) -> Result<CheckStatusResponse, Error>
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);
}Sourcepub async fn dump_logs(
&self,
cursor: Option<u64>,
limit: Option<u64>,
include_payload: Option<bool>,
) -> Result<DumpLogsResponse, Error>
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 pageslimit- Optional limit on the number of entries to returninclude_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?;
}Sourcepub async fn peek_pending(
&self,
limit: Option<u64>,
include_payload: Option<bool>,
) -> Result<PeekPendingResponse, Error>
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 returninclude_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");
}Sourcepub async fn peek_inflight(
&self,
limit: Option<u64>,
include_payload: Option<bool>,
) -> Result<PeekInflightResponse, Error>
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 returninclude_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);
}