pub struct Client(/* private fields */);
Expand description
Managed client for use on the Hedera network.
Implementations§
source§impl Client
impl Client
sourcepub fn from_config(json: &str) -> Result<Self>
pub fn from_config(json: &str) -> Result<Self>
Create a client from the given json config.
§Errors
Error::BasicParse
if an error occurs parsing the configuration.
sourcepub fn mirror_network(&self) -> Vec<String>
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());
sourcepub fn set_mirror_network<I: IntoIterator<Item = String>>(&self, addresses: I)
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.
sourcepub fn for_network(network: HashMap<String, AccountId>) -> Result<Self>
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
Error::BasicParse
if an error occurs parsing the configuration.
sourcepub fn for_mainnet() -> Self
pub fn for_mainnet() -> Self
Construct a Hedera client pre-configured for mainnet access.
sourcepub fn for_testnet() -> Self
pub fn for_testnet() -> Self
Construct a Hedera client pre-configured for testnet access.
sourcepub fn for_previewnet() -> Self
pub fn for_previewnet() -> Self
Construct a Hedera client pre-configured for previewnet access.
sourcepub fn set_network_from_address_book(&self, address_book: NodeAddressBook)
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.
sourcepub fn set_network(&self, network: HashMap<String, AccountId>) -> Result<()>
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.
sourcepub fn network(&self) -> HashMap<String, AccountId>
pub fn network(&self) -> HashMap<String, AccountId>
Returns the nodes associated with this client.
sourcepub fn max_node_attempts(&self) -> Option<NonZeroUsize>
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.
sourcepub fn set_max_node_attempts(&self, attempts: usize)
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.
sourcepub fn max_node_backoff(&self) -> Duration
pub fn max_node_backoff(&self) -> Duration
Returns the max backoff interval for network nodes if gRPC response fail.
sourcepub fn set_max_node_backoff(&self, max_node_backoff: Duration)
pub fn set_max_node_backoff(&self, max_node_backoff: Duration)
Sets max backoff interval for network nodes
sourcepub fn min_node_backoff(&self) -> Duration
pub fn min_node_backoff(&self) -> Duration
Returns the initial backoff interval for network nodes if gRPC response fail.
sourcepub fn set_min_node_backoff(&self, min_node_backoff: Duration)
pub fn set_min_node_backoff(&self, min_node_backoff: Duration)
Sets initial backoff interval for network nodes
sourcepub fn for_name(name: &str) -> Result<Self>
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
Error::BasicParse
if the network name is not a supported network name.
sourcepub fn set_ledger_id(&self, ledger_id: Option<LedgerId>)
pub fn set_ledger_id(&self, ledger_id: Option<LedgerId>)
Sets the ledger ID for the Client’s network.
sourcepub fn auto_validate_checksums(&self) -> bool
pub fn auto_validate_checksums(&self) -> bool
Returns true if checksums should be automatically validated.
sourcepub fn set_auto_validate_checksums(&self, value: bool)
pub fn set_auto_validate_checksums(&self, value: bool)
Enable or disable automatic entity ID checksum validation.
sourcepub fn default_regenerate_transaction_id(&self) -> bool
pub fn default_regenerate_transaction_id(&self) -> bool
Returns true if transaction IDs should be automatically regenerated.
This is true
by default.
sourcepub fn set_default_regenerate_transaction_id(&self, value: bool)
pub fn set_default_regenerate_transaction_id(&self, value: bool)
Enable or disable transaction ID regeneration.
sourcepub fn set_operator(&self, id: AccountId, key: PrivateKey)
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.
sourcepub fn set_operator_with<F: Fn(&[u8]) -> Vec<u8> + Send + Sync + 'static>(
&self,
id: AccountId,
public_key: PublicKey,
f: F
)
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.
sourcepub fn set_default_max_transaction_fee(&self, amount: Hbar)
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
sourcepub fn default_max_transaction_fee(&self) -> Option<Hbar>
pub fn default_max_transaction_fee(&self) -> Option<Hbar>
Gets the maximum transaction fee the paying account is willing to pay.
sourcepub fn default_max_query_payment(&self) -> Option<Hbar>
pub fn default_max_query_payment(&self) -> Option<Hbar>
Gets the maximum query fee the paying account is willing to pay.
sourcepub fn set_default_max_query_payment(&self, amount: Hbar)
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
sourcepub fn request_timeout(&self) -> Option<Duration>
pub fn request_timeout(&self) -> Option<Duration>
Returns the maximum amount of time that will be spent on a request.
sourcepub fn set_request_timeout(&self, timeout: Option<Duration>)
pub fn set_request_timeout(&self, timeout: Option<Duration>)
Sets the maximum amount of time that will be spent on a request.
sourcepub fn max_attempts(&self) -> usize
pub fn max_attempts(&self) -> usize
Returns the maximum number of attempts for a request.
sourcepub fn set_max_attempts(&self, max_attempts: usize)
pub fn set_max_attempts(&self, max_attempts: usize)
Sets the maximum number of attempts for a request.
sourcepub fn min_backoff(&self) -> Duration
pub fn min_backoff(&self) -> Duration
The initial backoff for a request being executed.
sourcepub fn set_min_backoff(&self, max_backoff: Duration)
pub fn set_min_backoff(&self, max_backoff: Duration)
Sets the initial backoff for a request being executed.
sourcepub fn max_backoff(&self) -> Duration
pub fn max_backoff(&self) -> Duration
Returns the maximum amount of time a request will wait between attempts.
sourcepub fn set_max_backoff(&self, max_backoff: Duration)
pub fn set_max_backoff(&self, max_backoff: Duration)
Sets the maximum amount of time a request will wait between attempts.
sourcepub async fn ping(&self, node_account_id: AccountId) -> Result<()>
pub async fn ping(&self, node_account_id: AccountId) -> Result<()>
Send a ping to the given node.
sourcepub async fn ping_with_timeout(
&self,
node_account_id: AccountId,
timeout: Duration
) -> Result<()>
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.
sourcepub async fn ping_all_with_timeout(&self, timeout: Duration) -> Result<()>
pub async fn ping_all_with_timeout(&self, timeout: Duration) -> Result<()>
Send a ping to all nodes, canceling the ping after timeout
has elapsed.
sourcepub fn network_update_period(&self) -> Option<Duration>
pub fn network_update_period(&self) -> Option<Duration>
Returns the frequency at which the network will update (if it will update at all).
sourcepub fn set_network_update_period(&self, period: Option<Duration>)
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.
sourcepub fn get_operator_account_id(&self) -> Option<AccountId>
pub fn get_operator_account_id(&self) -> Option<AccountId>
Returns the Account ID for the operator.
sourcepub fn get_operator_public_key(&self) -> Option<PublicKey>
pub fn get_operator_public_key(&self) -> Option<PublicKey>
Returns the PublicKey
for the current operator.
Trait Implementations§
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> 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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request