Skip to content

Conversation

@deanmlittle
Copy link
Contributor

@deanmlittle deanmlittle commented Dec 6, 2025

Made several improvements to the IntrospectedInstruction API, including:

  1. Adding num_account_metas(&self) -> usize helper function
  2. Created a private new_unchecked(raw: *const u8) -> IntrospectedInstruction function that is consumed internally to avoid having to expose PhantomData as a public field
  3. Made num_instructions refer usize and removed all inline usize casts

@deanmlittle deanmlittle changed the title Improve IntrospectedInstruction sdk: Improve IntrospectedInstruction Dec 6, 2025
let offset = u16::from_le_bytes(unsafe { *(self.raw as *const [u8; 2]) }) as usize
* size_of::<IntrospectedInstructionAccount>()
+ ADDRESS_BYTES;
let offset =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit in particular looks much nicer!

pub struct IntrospectedInstruction<'a> {
pub raw: *const u8,
pub marker: PhantomData<&'a [u8]>,
marker: PhantomData<&'a [u8]>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Collaborator

@febo febo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@febo febo merged commit e3650be into anza-xyz:main Dec 6, 2025
8 checks passed
@deanmlittle deanmlittle deleted the improve-introspected-instruction branch December 6, 2025 16:26
///
/// It is private and used internally within the `get_instruction_account_at` function, which
/// performs the necessary index verification. However, to optimize performance for users
/// who are sure that the index is in bounds, we have exposed it as an unsafe function.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, this comment was copied from get_instruction_account_at_unchecked and should not be here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants