pub fn state_from_account<T>(account: &T) -> Result<State, Error>
Expand description
Deserialize the state of a durable transaction nonce account.
§Errors
Returns an error if the account is not owned by the system program or contains no data.
§Examples
Determine if a nonce account is initialized:
use solana_rpc_client_nonce_utils::nonblocking;
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{
nonce::State,
pubkey::Pubkey,
};
use anyhow::Result;
futures::executor::block_on(async {
async fn is_nonce_initialized(
client: &RpcClient,
nonce_account_pubkey: &Pubkey,
) -> Result<bool> {
// Sign the tx with nonce_account's `blockhash` instead of the
// network's latest blockhash.
let nonce_account = client.get_account(nonce_account_pubkey).await?;
let nonce_state = nonblocking::state_from_account(&nonce_account)?;
Ok(!matches!(nonce_state, State::Uninitialized))
}