Struct hedera::Client

source ·
pub struct Client(/* private fields */);
Expand description

Managed client for use on the Hedera network.

Implementations§

source§

impl Client

source

pub fn from_config(json: &str) -> Result<Self>

Create a client from the given json config.

§Errors
source

pub fn mirror_network(&self) -> Vec<String>

Returns the addresses for the configured mirror network.

Unless explicitly set, the return value isn’t guaranteed to be anything in particular in order to allow future changes without breaking semver. However, when a function such as for_testnet is used, some valid value will be returned.

Current return values (reminder that these are semver exempt)

  • mainnet: ["mainnet-public.mirrornode.hedera.com:443"]
  • testnet: ["testnet.mirrornode.hedera.com:443"]
  • previewnet: ["previewnet.mirrornode.hedera.com:443"]
§Examples
use hedera::Client;

let client = Client::for_testnet();

// note: This isn't *guaranteed* in a semver sense, but this is the current result.
let expected = Vec::from(["testnet.mirrornode.hedera.com:443".to_owned()]);
assert_eq!(expected, client.mirror_network());
source

pub fn set_mirror_network<I: IntoIterator<Item = String>>(&self, addresses: I)

Sets the addresses to use for the mirror network.

This is mostly useful if you used Self::for_network and need to set a mirror network.

source

pub fn for_network(network: HashMap<String, AccountId>) -> Result<Self>

Construct a client with the given nodes configured.

Note that this disables network auto-updating.

§Errors
source

pub fn for_mainnet() -> Self

Construct a Hedera client pre-configured for mainnet access.

source

pub fn for_testnet() -> Self

Construct a Hedera client pre-configured for testnet access.

source

pub fn for_previewnet() -> Self

Construct a Hedera client pre-configured for previewnet access.

source

pub fn set_network_from_address_book(&self, address_book: NodeAddressBook)

Updates the network to use the given address book.

Note: This is only really useful if you used for_network, because the network can auto-update.

If network auto-updating is enabled this will eventually be overridden.

source

pub fn set_network(&self, network: HashMap<String, AccountId>) -> Result<()>

Updates the network to use the given addresses.

Note: This is only really useful if you used for_network, because the network can auto-update.

If network auto-updating is enabled this will eventually be overridden.

Tend to prefer set_network_from_address_book where possible.

§Errors

Error::BasicParse If any node address is unparsable.

source

pub fn network(&self) -> HashMap<String, AccountId>

Returns the nodes associated with this client.

source

pub fn max_node_attempts(&self) -> Option<NonZeroUsize>

Returns the max number of times a node can be retried before removing it from the network.

source

pub fn set_max_node_attempts(&self, attempts: usize)

Set the max number of times a node can return a bad gRPC status before we remove it from the list.

source

pub fn max_node_backoff(&self) -> Duration

Returns the max backoff interval for network nodes if gRPC response fail.

source

pub fn set_max_node_backoff(&self, max_node_backoff: Duration)

Sets max backoff interval for network nodes

source

pub fn min_node_backoff(&self) -> Duration

Returns the initial backoff interval for network nodes if gRPC response fail.

source

pub fn set_min_node_backoff(&self, min_node_backoff: Duration)

Sets initial backoff interval for network nodes

source

pub fn for_name(name: &str) -> Result<Self>

Construct a hedera client pre-configured for access to the given network.

Currently supported network names are "mainnet", "testnet", and "previewnet".

§Errors
source

pub fn set_ledger_id(&self, ledger_id: Option<LedgerId>)

Sets the ledger ID for the Client’s network.

source

pub fn auto_validate_checksums(&self) -> bool

Returns true if checksums should be automatically validated.

source

pub fn set_auto_validate_checksums(&self, value: bool)

Enable or disable automatic entity ID checksum validation.

source

pub fn default_regenerate_transaction_id(&self) -> bool

Returns true if transaction IDs should be automatically regenerated.

This is true by default.

source

pub fn set_default_regenerate_transaction_id(&self, value: bool)

Enable or disable transaction ID regeneration.

source

pub fn set_operator(&self, id: AccountId, key: PrivateKey)

Sets the account that will, by default, be paying for transactions and queries built with this client.

The operator account ID is used to generate the default transaction ID for all transactions executed with this client.

The operator private key is used to sign all transactions executed by this client.

source

pub fn set_operator_with<F: Fn(&[u8]) -> Vec<u8> + Send + Sync + 'static>( &self, id: AccountId, public_key: PublicKey, f: F )

Sets the account that will, by default, be paying for transactions and queries built with this client.

The operator account ID is used to generate the default transaction ID for all transactions executed with this client.

The operator signer is used to sign all transactions executed by this client.

source

pub fn set_default_max_transaction_fee(&self, amount: Hbar)

Sets the maximum transaction fee to be used when no explicit max transaction fee is set.

Note: Setting amount to zero is “unlimited”

§Panics
  • if amount is negative
source

pub fn default_max_transaction_fee(&self) -> Option<Hbar>

Gets the maximum transaction fee the paying account is willing to pay.

source

pub fn default_max_query_payment(&self) -> Option<Hbar>

Gets the maximum query fee the paying account is willing to pay.

source

pub fn set_default_max_query_payment(&self, amount: Hbar)

Sets the maximum query payment to be used when no explicit max query payment is set.

Note: Setting amount to zero is “unlimited”

§Panics
  • if amount is negative
source

pub fn request_timeout(&self) -> Option<Duration>

Returns the maximum amount of time that will be spent on a request.

source

pub fn set_request_timeout(&self, timeout: Option<Duration>)

Sets the maximum amount of time that will be spent on a request.

source

pub fn max_attempts(&self) -> usize

Returns the maximum number of attempts for a request.

source

pub fn set_max_attempts(&self, max_attempts: usize)

Sets the maximum number of attempts for a request.

source

pub fn min_backoff(&self) -> Duration

The initial backoff for a request being executed.

source

pub fn set_min_backoff(&self, max_backoff: Duration)

Sets the initial backoff for a request being executed.

source

pub fn max_backoff(&self) -> Duration

Returns the maximum amount of time a request will wait between attempts.

source

pub fn set_max_backoff(&self, max_backoff: Duration)

Sets the maximum amount of time a request will wait between attempts.

source

pub async fn ping(&self, node_account_id: AccountId) -> Result<()>

Send a ping to the given node.

source

pub async fn ping_with_timeout( &self, node_account_id: AccountId, timeout: Duration ) -> Result<()>

Send a ping to the given node, canceling the ping after timeout has elapsed.

source

pub async fn ping_all(&self) -> Result<()>

Send a ping to all nodes.

source

pub async fn ping_all_with_timeout(&self, timeout: Duration) -> Result<()>

Send a ping to all nodes, canceling the ping after timeout has elapsed.

source

pub fn network_update_period(&self) -> Option<Duration>

Returns the frequency at which the network will update (if it will update at all).

source

pub fn set_network_update_period(&self, period: Option<Duration>)

Sets the frequency at which the network will update.

Note that network updates will not affect any in-flight requests.

source

pub fn get_operator_account_id(&self) -> Option<AccountId>

Returns the Account ID for the operator.

source

pub fn get_operator_public_key(&self) -> Option<PublicKey>

Returns the PublicKey for the current operator.

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Client

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl !Unpin for Client

§

impl !UnwindSafe for Client

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

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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