Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plerkle Solana Desierializers #8

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
refactor: add another parser for fb inner instructions to solana inne…
…r instructions
  • Loading branch information
kespinola committed Feb 29, 2024
commit 6c883b67472d7331ae15d04cd9c2d3f1f3d24e15
45 changes: 42 additions & 3 deletions plerkle_serialization/src/deserializer/solana.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
CompiledInnerInstructions as FBCompiledInnerInstructions,
CompiledInstruction as FBCompiledInstruction, Pubkey as FBPubkey,
CompiledInstruction as FBCompiledInstruction, InnerInstructions as FBInnerInstructions,
Pubkey as FBPubkey,
};
use flatbuffers::{ForwardsUOffset, Vector};
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature};
@@ -51,7 +52,7 @@ pub fn parse_account_keys(
.collect::<SolanaDeserializeResult<Vec<Pubkey>>>()
}

pub fn parse_message_instructions(
pub fn parse_compiled_instructions(
vec_cix: Option<Vector<'_, ForwardsUOffset<FBCompiledInstruction>>>,
) -> SolanaDeserializeResult<Vec<CompiledInstruction>> {
let mut message_instructions = vec![];
@@ -74,7 +75,7 @@ pub fn parse_message_instructions(
Ok(message_instructions)
}

pub fn parse_meta_inner_instructions(
pub fn parse_compiled_inner_instructions(
vec_ixs: Option<Vector<'_, ForwardsUOffset<FBCompiledInnerInstructions>>>,
) -> SolanaDeserializeResult<Vec<InnerInstructions>> {
let mut meta_inner_instructions = vec![];
@@ -111,3 +112,41 @@ pub fn parse_meta_inner_instructions(
}
Ok(meta_inner_instructions)
}

pub fn parse_inner_instructions(
vec_ixs: Option<Vector<'_, ForwardsUOffset<FBInnerInstructions>>>,
) -> SolanaDeserializeResult<Vec<InnerInstructions>> {
vec_ixs
.ok_or(SolanaDeserializerError::NotFound)?
.iter()
.map(|iixs| {
let instructions = iixs
.instructions()
.ok_or(SolanaDeserializerError::NotFound)?
.iter()
.map(|cix| {
Ok(InnerInstruction {
instruction: CompiledInstruction {
program_id_index: cix.program_id_index(),
accounts: cix
.accounts()
.ok_or(SolanaDeserializerError::NotFound)?
.bytes()
.to_vec(),
data: cix
.data()
.ok_or(SolanaDeserializerError::NotFound)?
.bytes()
.to_vec(),
},
stack_height: Some(0),
})
})
.collect::<SolanaDeserializeResult<Vec<InnerInstruction>>>()?;
Ok(InnerInstructions {
index: iixs.index(),
instructions,
})
})
.collect::<SolanaDeserializeResult<Vec<InnerInstructions>>>()
}