1
+ use core:: slice:: from_raw_parts;
1
2
use pinocchio:: {
2
3
account_info:: AccountInfo ,
3
4
instruction:: { AccountMeta , Instruction , Signer } ,
@@ -6,6 +7,8 @@ use pinocchio::{
6
7
ProgramResult ,
7
8
} ;
8
9
10
+ use crate :: { write_bytes, UNINIT_BYTE } ;
11
+
9
12
/// Create an address lookup table
10
13
///
11
14
/// # Account references
@@ -52,18 +55,21 @@ impl Create<'_> {
52
55
] ;
53
56
54
57
// Instruction data:
55
- // - [0..4 ]: Instruction discriminator (1 byte, u8 ) (0 for Create)
58
+ // - [0..4 ]: Instruction discriminator (4 bytes, u32 ) (0 for Create)
56
59
// - [4..12]: Recent Slot
57
60
// - [12 ]: bump seed
58
- let mut instruction_data = [ 0 ; 13 ] ;
59
- instruction_data[ 0 ] = 0 ;
60
- instruction_data[ 4 ..12 ] . copy_from_slice ( & self . recent_slot . to_le_bytes ( ) ) ;
61
- instruction_data[ 12 ] = self . bump_seed ;
61
+ let mut instruction_data = [ UNINIT_BYTE ; 13 ] ;
62
+ write_bytes ( & mut instruction_data, & [ 0 ] ) ;
63
+ write_bytes (
64
+ & mut instruction_data[ 4 ..12 ] ,
65
+ & self . recent_slot . to_le_bytes ( ) ,
66
+ ) ;
67
+ write_bytes ( & mut instruction_data[ 12 ..] , & [ self . bump_seed ] ) ;
62
68
63
69
let instruction = Instruction {
64
70
program_id : & crate :: ID ,
65
71
accounts : & account_metas,
66
- data : & instruction_data,
72
+ data : unsafe { from_raw_parts ( instruction_data. as_ptr ( ) as _ , 13 ) } ,
67
73
} ;
68
74
69
75
invoke_signed (
0 commit comments