pub struct RestClient<'a> {
pub node_url: Vec<&'a str>,
pub request_time_out: u64,
pub poll_attemps: u64,
pub poll_attemp_interval_time: u64,
}Expand description
A REST client for interacting with Postchain blockchain nodes.
This client handles communication with blockchain nodes, including:
- Transaction submission and status checking
- Node discovery and management
- Query execution
- Error handling
Fields§
§node_url: Vec<&'a str>List of node URLs to connect to
request_time_out: u64Request timeout in seconds
poll_attemps: u64Number of attempts to poll for transaction status
poll_attemp_interval_time: u64Interval between poll attempts in seconds
Implementations§
Source§impl<'a> RestClient<'a>
impl<'a> RestClient<'a>
Sourcepub async fn get_nodes_from_directory(
&self,
brid: &str,
) -> Result<Vec<String>, RestError>
pub async fn get_nodes_from_directory( &self, brid: &str, ) -> Result<Vec<String>, RestError>
Retrieves a list of node URLs from the blockchain directory.
§Arguments
brid- Blockchain RID (Resource Identifier)
§Returns
Result<Vec<String>, RestError>- List of node URLs on success, or error on failure
§Example
let client = RestClient::default();
let nodes = client.get_nodes_from_directory("blockchain_rid").await?;Sourcepub fn print_error(&self, error: &RestError, ignore_all_errors: bool) -> bool
pub fn print_error(&self, error: &RestError, ignore_all_errors: bool) -> bool
Sourcepub async fn detect_merkle_hash_version(&self, brid: &str) -> u8
pub async fn detect_merkle_hash_version(&self, brid: &str) -> u8
Detects the Merkle hash version used by a blockchain.
This function queries the blockchain’s configuration to determine which version of the Merkle hash algorithm is being used. If the query fails or the version information is not available, it defaults to version 1.
§Arguments
brid- The blockchain RID (Resource Identifier) as a hex-encoded string
§Returns
u8- The Merkle hash version number (defaults to 1 if not specified)
§Example
let client = RestClient::default();
let brid = "DCE5D72ED7E1675291AFE7F9D649D898C8D3E7411E52882D03D1B3D240BDD91B";
let hash_version = client.detect_merkle_hash_version(brid).await;
println!("Blockchain uses Merkle hash version {}", hash_version);Sourcepub fn update_node_urls(&mut self, node_urls: &'a Vec<String>)
pub fn update_node_urls(&mut self, node_urls: &'a Vec<String>)
Updates the list of node URLs used by the client.
§Arguments
node_urls- New list of node URLs to use
Sourcepub async fn get_transaction_status(
&self,
blockchain_rid: &str,
tx_rid: &str,
) -> Result<TransactionStatus, RestError>
pub async fn get_transaction_status( &self, blockchain_rid: &str, tx_rid: &str, ) -> Result<TransactionStatus, RestError>
Sourcepub async fn get_transaction_status_with_poll(
&self,
blockchain_rid: &str,
tx_rid: &str,
attempts: u64,
) -> Result<TransactionStatus, RestError>
pub async fn get_transaction_status_with_poll( &self, blockchain_rid: &str, tx_rid: &str, attempts: u64, ) -> Result<TransactionStatus, RestError>
Sourcepub async fn send_transaction(
&self,
tx: &Transaction<'a>,
) -> Result<RestResponse, RestError>
pub async fn send_transaction( &self, tx: &Transaction<'a>, ) -> Result<RestResponse, RestError>
Sourcepub async fn query<T: AsRef<str>>(
&self,
brid: &str,
query_prefix: Option<&str>,
query_type: &'a str,
query_params: Option<&'a mut Vec<(&'a str, &'a str)>>,
query_args: Option<&'a mut Vec<(T, Params)>>,
) -> Result<RestResponse, RestError>
pub async fn query<T: AsRef<str>>( &self, brid: &str, query_prefix: Option<&str>, query_type: &'a str, query_params: Option<&'a mut Vec<(&'a str, &'a str)>>, query_args: Option<&'a mut Vec<(T, Params)>>, ) -> Result<RestResponse, RestError>
Executes a query on the blockchain.
§Arguments
brid- Blockchain RIDquery_prefix- Optional prefix for the query endpointquery_type- Type of query to executequery_params- Optional query parametersquery_args- Optional query arguments
§Returns
Result<RestResponse, RestError>- Query response or error
Trait Implementations§
Source§impl<'a> Debug for RestClient<'a>
impl<'a> Debug for RestClient<'a>
Auto Trait Implementations§
impl<'a> Freeze for RestClient<'a>
impl<'a> RefUnwindSafe for RestClient<'a>
impl<'a> Send for RestClient<'a>
impl<'a> Sync for RestClient<'a>
impl<'a> Unpin for RestClient<'a>
impl<'a> UnwindSafe for RestClient<'a>
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
Mutably borrows from an owned value. Read more