2025-10-07 21:20:00 +08:00
|
|
|
use crate::common::SolanaRpcClient;
|
2025-09-04 16:32:34 +08:00
|
|
|
use solana_hash::Hash;
|
2025-09-27 14:24:41 +08:00
|
|
|
use solana_nonce::state::State;
|
|
|
|
|
use solana_nonce::versions::Versions;
|
2025-09-04 16:32:34 +08:00
|
|
|
use solana_sdk::account_utils::StateMut;
|
2025-05-29 18:53:58 +08:00
|
|
|
use solana_sdk::pubkey::Pubkey;
|
2025-09-04 16:32:34 +08:00
|
|
|
use tracing::error;
|
2025-05-29 18:53:58 +08:00
|
|
|
|
2025-09-20 14:00:45 +08:00
|
|
|
/// DurableNonceInfo structure to store durable nonce-related information
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct DurableNonceInfo {
|
|
|
|
|
/// Nonce account address
|
|
|
|
|
pub nonce_account: Option<Pubkey>,
|
|
|
|
|
/// Current nonce value
|
|
|
|
|
pub current_nonce: Option<Hash>,
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-07 21:20:00 +08:00
|
|
|
/// Fetch nonce information using RPC
|
|
|
|
|
pub async fn fetch_nonce_info(
|
|
|
|
|
rpc: &SolanaRpcClient,
|
|
|
|
|
nonce_account: Pubkey,
|
|
|
|
|
) -> Option<DurableNonceInfo> {
|
|
|
|
|
match rpc.get_account(&nonce_account).await {
|
|
|
|
|
Ok(account) => match account.state() {
|
|
|
|
|
Ok(Versions::Current(state)) => {
|
|
|
|
|
if let State::Initialized(data) = *state {
|
|
|
|
|
let blockhash = data.durable_nonce.as_hash();
|
|
|
|
|
return Some(DurableNonceInfo {
|
|
|
|
|
nonce_account: Some(nonce_account),
|
|
|
|
|
current_nonce: Some(*blockhash),
|
|
|
|
|
});
|
2025-09-04 16:32:34 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-10-07 21:20:00 +08:00
|
|
|
_ => (),
|
|
|
|
|
},
|
|
|
|
|
Err(e) => {
|
|
|
|
|
error!("Failed to get nonce account information: {:?}", e);
|
2025-09-04 16:32:34 +08:00
|
|
|
}
|
2025-05-29 18:53:58 +08:00
|
|
|
}
|
2025-10-07 21:20:00 +08:00
|
|
|
None
|
2025-05-29 18:53:58 +08:00
|
|
|
}
|