Skip to content

Commit e71d31e

Browse files
fix: ixs discs
1 parent 3320b5d commit e71d31e

File tree

6 files changed

+35
-41
lines changed

6 files changed

+35
-41
lines changed

programs/address-lookup-table/src/instructions/close.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,15 @@ impl Close<'_> {
3434
AccountMeta::writable(self.recipient.key()),
3535
];
3636

37-
// Instruction data:
38-
// - [0]: Instruction discriminator (1 byte, u8) (4 for Close)
39-
40-
let instruction_data = [4u8];
41-
4237
let instruction = Instruction {
4338
program_id: &crate::ID,
4439
accounts: &account_metas,
45-
data: &instruction_data,
40+
data: &[4],
4641
};
4742

4843
invoke_signed(
4944
&instruction,
50-
&[
51-
self.lookup_table,
52-
self.authority,
53-
self.recipient,
54-
],
45+
&[self.lookup_table, self.authority, self.recipient],
5546
signers,
5647
)
5748
}

programs/address-lookup-table/src/instructions/create.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::slice::from_raw_parts;
12
use pinocchio::{
23
account_info::AccountInfo,
34
instruction::{AccountMeta, Instruction, Signer},
@@ -6,6 +7,8 @@ use pinocchio::{
67
ProgramResult,
78
};
89

10+
use crate::{write_bytes, UNINIT_BYTE};
11+
912
/// Create an address lookup table
1013
///
1114
/// # Account references
@@ -52,18 +55,21 @@ impl Create<'_> {
5255
];
5356

5457
// Instruction data:
55-
// - [0..4 ]: Instruction discriminator (1 byte, u8) (0 for Create)
58+
// - [0..4 ]: Instruction discriminator (4 bytes, u32) (0 for Create)
5659
// - [4..12]: Recent Slot
5760
// - [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]);
6268

6369
let instruction = Instruction {
6470
program_id: &crate::ID,
6571
accounts: &account_metas,
66-
data: &instruction_data,
72+
data: unsafe { from_raw_parts(instruction_data.as_ptr() as _, 13) },
6773
};
6874

6975
invoke_signed(

programs/address-lookup-table/src/instructions/deactivate.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,12 @@ impl Deactivate<'_> {
3131
AccountMeta::readonly_signer(self.authority.key()),
3232
];
3333

34-
// Instruction data:
35-
// - [0]: Instruction discriminator (1 byte, u8) (3 for Deactivate)
36-
37-
let instruction_data = [3u8];
38-
3934
let instruction = Instruction {
4035
program_id: &crate::ID,
4136
accounts: &account_metas,
42-
data: &instruction_data,
37+
data: &[3],
4338
};
4439

45-
invoke_signed(
46-
&instruction,
47-
&[self.lookup_table, self.authority],
48-
signers,
49-
)
40+
invoke_signed(&instruction, &[self.lookup_table, self.authority], signers)
5041
}
5142
}

programs/address-lookup-table/src/instructions/extend.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::vec::Vec;
12
use pinocchio::{
23
account_info::AccountInfo,
34
instruction::{AccountMeta, Instruction, Signer},
@@ -27,7 +28,7 @@ pub struct Extend<'a> {
2728
/// System program for CPI.
2829
pub system_program: Option<&'a AccountInfo>,
2930
/// Addresses to extend the table with
30-
pub new_addresses: &'a [Pubkey],
31+
pub new_addresses: Vec<&'a Pubkey>,
3132
}
3233

3334
impl Extend<'_> {
@@ -38,7 +39,7 @@ impl Extend<'_> {
3839

3940
pub fn invoke_signed(&self, signers: &[Signer]) -> ProgramResult {
4041
// Instruction data:
41-
// - [0]: Instruction discriminator (1 byte, u8) (2 for Extend)
42+
// - [0]: Instruction discriminator (4 bytes, u32) (2 for Extend)
4243

4344
// LOOKUP_TABLE_MAX_ADDRESSES == u8::MAX + 1.
4445
let mut instruction_data = [0; 8196]; // TODO: huge for stack, maybe forget about no_std and use vector

programs/address-lookup-table/src/instructions/freeze.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,12 @@ impl Freeze<'_> {
3030
AccountMeta::readonly_signer(self.authority.key()),
3131
];
3232

33-
// Instruction data:
34-
// - [0]: Instruction discriminator (1 byte, u8) (1 for Freeze)
35-
36-
let instruction_data = [1u8];
37-
3833
let instruction = Instruction {
3934
program_id: &crate::ID,
4035
accounts: &account_metas,
41-
data: &instruction_data,
36+
data: &[1],
4237
};
4338

44-
invoke_signed(
45-
&instruction,
46-
&[self.lookup_table, self.authority],
47-
signers,
48-
)
39+
invoke_signed(&instruction, &[self.lookup_table, self.authority], signers)
4940
}
5041
}

programs/address-lookup-table/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22

33
pub mod instructions;
44

5+
extern crate alloc;
6+
57
pinocchio_pubkey::declare_id!("AddressLookupTab1e1111111111111111111111111");
8+
9+
use core::mem::MaybeUninit;
10+
11+
// TODO: copy-pasted from token program/ Maybe it'll be better to move it under pinochio or even into dedicated crate
12+
const UNINIT_BYTE: MaybeUninit<u8> = MaybeUninit::<u8>::uninit();
13+
14+
#[inline(always)]
15+
fn write_bytes(destination: &mut [MaybeUninit<u8>], source: &[u8]) {
16+
for (d, s) in destination.iter_mut().zip(source.iter()) {
17+
d.write(*s);
18+
}
19+
}

0 commit comments

Comments
 (0)