Struct RestClient

Source
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: u64

Request timeout in seconds

§poll_attemps: u64

Number of attempts to poll for transaction status

§poll_attemp_interval_time: u64

Interval between poll attempts in seconds

Implementations§

Source§

impl<'a> RestClient<'a>

Source

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?;
Source

pub async fn get_blockchain_rid( &self, blockchain_iid: u8, ) -> Result<String, RestError>

Retrieves the blockchain RID for a given blockchain IID.

§Arguments
  • blockchain_iid - Blockchain Instance Identifier
§Returns
  • Result<String, RestError> - Blockchain RID on success, or error on failure
Source

pub fn print_error(&self, error: &RestError, ignore_all_errors: bool) -> bool

Prints error information and determines if the error should be ignored.

§Arguments
  • error - The REST error to print
  • ignore_all_errors - Whether to ignore all errors
§Returns
  • bool - Whether the error should stop execution
Source

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);
Source

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
Source

pub async fn get_transaction_status( &self, blockchain_rid: &str, tx_rid: &str, ) -> Result<TransactionStatus, RestError>

Gets the status of a transaction without polling.

§Arguments
  • blockchain_rid - Blockchain RID
  • tx_rid - Transaction RID
§Returns
  • Result<TransactionStatus, RestError> - Transaction status or error
Source

pub async fn get_transaction_status_with_poll( &self, blockchain_rid: &str, tx_rid: &str, attempts: u64, ) -> Result<TransactionStatus, RestError>

Gets the status of a transaction with polling for confirmation.

§Arguments
  • blockchain_rid - Blockchain RID
  • tx_rid - Transaction RID
  • attempts - Number of polling attempts made so far
§Returns
  • Result<TransactionStatus, RestError> - Transaction status or error
Source

pub async fn send_transaction( &self, tx: &Transaction<'a>, ) -> Result<RestResponse, RestError>

Sends a transaction to the blockchain.

§Arguments
  • tx - Transaction to send
§Returns
  • Result<RestResponse, RestError> - Response from the blockchain or error
Source

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 RID
  • query_prefix - Optional prefix for the query endpoint
  • query_type - Type of query to execute
  • query_params - Optional query parameters
  • query_args - Optional query arguments
§Returns
  • Result<RestResponse, RestError> - Query response or error

Trait Implementations§

Source§

impl<'a> Debug for RestClient<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for RestClient<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
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,