solana_message/
inline_nonce.rs1use {
4 solana_address::Address,
5 solana_instruction::{AccountMeta, Instruction},
6 solana_sdk_ids::{system_program, sysvar},
7};
8
9const ADVANCE_NONCE_DATA: [u8; 4] = [4, 0, 0, 0];
12
13pub fn is_advance_nonce_instruction_data(data: &[u8]) -> bool {
19 data.get(0..4) == Some(&ADVANCE_NONCE_DATA)
20}
21
22pub(crate) fn advance_nonce_account_instruction(
25 nonce_pubkey: &Address,
26 nonce_authority_pubkey: &Address,
27) -> Instruction {
28 Instruction::new_with_bytes(
29 system_program::id(),
30 &ADVANCE_NONCE_DATA,
31 vec![
32 AccountMeta::new(*nonce_pubkey, false),
33 #[allow(deprecated)]
34 AccountMeta::new_readonly(sysvar::recent_blockhashes::id(), false),
35 AccountMeta::new_readonly(*nonce_authority_pubkey, true),
36 ],
37 )
38}
39
40#[cfg(test)]
41mod test {
42 use {
43 super::*,
44 solana_system_interface::instruction::{advance_nonce_account, SystemInstruction},
45 };
46
47 #[test]
48 fn inline_instruction_data_matches_program() {
49 let nonce = Address::new_unique();
50 let nonce_authority = Address::new_unique();
51 assert_eq!(
52 advance_nonce_account_instruction(&nonce, &nonce_authority),
53 advance_nonce_account(&nonce, &nonce_authority),
54 );
55 }
56
57 #[test]
58 fn test_advance_nonce_ix_prefix() {
59 let advance_nonce_ix: SystemInstruction =
60 bincode::deserialize(&ADVANCE_NONCE_DATA).unwrap();
61 assert_eq!(advance_nonce_ix, SystemInstruction::AdvanceNonceAccount);
62 }
63}