use solana_hash::Hash;
use solana_sdk::{instruction::Instruction, signature::Keypair, signer::Signer};
use solana_system_interface::instruction::advance_nonce_account;
use crate::common::nonce_cache::DurableNonceInfo;
pub fn add_nonce_instruction(
instructions: &mut Vec<Instruction>,
payer: &Keypair,
durable_nonce: Option<DurableNonceInfo>,
) -> Result<(), anyhow::Error> {
if let Some(durable_nonce) = durable_nonce {
let nonce_advance_ix = advance_nonce_account(&durable_nonce.nonce_account.unwrap(), &payer.pubkey());
instructions.push(nonce_advance_ix);
}
Ok(())
}
pub fn get_transaction_blockhash(
recent_blockhash: Option<Hash>,
durable_nonce: Option<DurableNonceInfo>,
) -> Hash {
if let Some(durable_nonce) = durable_nonce {
durable_nonce.current_nonce.unwrap()
} else {
recent_blockhash.unwrap()
}
}