2022-03-25 13:36:36 -07:00
|
|
|
//! Durable transaction nonce helpers.
|
|
|
|
|
2022-08-09 20:18:36 -07:00
|
|
|
pub use crate::nonblocking::nonce_utils::{
|
|
|
|
account_identity_ok, data_from_account, data_from_state, state_from_account, Error,
|
|
|
|
};
|
2021-03-26 20:26:06 -07:00
|
|
|
use {
|
|
|
|
crate::rpc_client::RpcClient,
|
2022-08-09 20:18:36 -07:00
|
|
|
solana_sdk::{account::Account, commitment_config::CommitmentConfig, pubkey::Pubkey},
|
2020-09-21 12:55:44 -07:00
|
|
|
};
|
|
|
|
|
2022-03-25 13:36:36 -07:00
|
|
|
/// Get a nonce account from the network.
|
|
|
|
///
|
|
|
|
/// This is like [`RpcClient::get_account`] except:
|
|
|
|
///
|
|
|
|
/// - it returns this module's [`Error`] type,
|
|
|
|
/// - it returns an error if any of the checks from [`account_identity_ok`] fail.
|
2020-09-21 12:55:44 -07:00
|
|
|
pub fn get_account(rpc_client: &RpcClient, nonce_pubkey: &Pubkey) -> Result<Account, Error> {
|
|
|
|
get_account_with_commitment(rpc_client, nonce_pubkey, CommitmentConfig::default())
|
|
|
|
}
|
|
|
|
|
2022-03-25 13:36:36 -07:00
|
|
|
/// Get a nonce account from the network.
|
|
|
|
///
|
|
|
|
/// This is like [`RpcClient::get_account_with_commitment`] except:
|
|
|
|
///
|
|
|
|
/// - it returns this module's [`Error`] type,
|
|
|
|
/// - it returns an error if the account does not exist,
|
|
|
|
/// - it returns an error if any of the checks from [`account_identity_ok`] fail.
|
2020-09-21 12:55:44 -07:00
|
|
|
pub fn get_account_with_commitment(
|
|
|
|
rpc_client: &RpcClient,
|
|
|
|
nonce_pubkey: &Pubkey,
|
|
|
|
commitment: CommitmentConfig,
|
|
|
|
) -> Result<Account, Error> {
|
|
|
|
rpc_client
|
|
|
|
.get_account_with_commitment(nonce_pubkey, commitment)
|
|
|
|
.map_err(|e| Error::Client(format!("{}", e)))
|
|
|
|
.and_then(|result| {
|
|
|
|
result
|
|
|
|
.value
|
|
|
|
.ok_or_else(|| Error::Client(format!("AccountNotFound: pubkey={}", nonce_pubkey)))
|
|
|
|
})
|
2021-04-08 11:40:37 -07:00
|
|
|
.and_then(|a| account_identity_ok(&a).map(|()| a))
|
2020-09-21 12:55:44 -07:00
|
|
|
}
|