Skip to content

Commit

Permalink
refactor: increase version to 2.0.0 some refactoring of instruction p…
Browse files Browse the repository at this point in the history
…arsing
  • Loading branch information
kespinola committed Mar 7, 2024
1 parent 9924e72 commit cd2c6b2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blockbuster/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "blockbuster"
description = "Metaplex canonical program parsers, for indexing, analytics etc...."
version = "1.1.0"
version = "2.0.0"
authors = ["Metaplex Developers <[email protected]>"]
repository = "https://github.com/metaplex-foundation/blockbuster"
license = "AGPL-3.0"
Expand Down
60 changes: 25 additions & 35 deletions blockbuster/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,28 @@ pub fn order_instructions<'a>(
for (outer_instruction_index, message_instruction) in message_instructions.iter().enumerate() {
let non_hoisted_inner_instruction = meta_inner_instructions
.iter()
.filter(|ix| ix.index == outer_instruction_index as u8)
.flat_map(|ix| {
ix.instructions
.iter()
.map(|ix| {
let cix = &ix.instruction;
(account_keys[cix.program_id_index as usize], cix)
})
.collect::<Vec<IxPair>>()
.filter_map(|ix| (ix.index == outer_instruction_index as u8).then(|| &ix.instructions))
.flatten()
.map(|inner_ix| {
let cix = &inner_ix.instruction;
(account_keys[cix.program_id_index as usize], cix)
})
.collect::<Vec<IxPair>>();

let hoisted = hoist_known_programs(programs, &non_hoisted_inner_instruction);
ordered_ixs.extend(hoisted);

let outer_ix_program_id_index = message_instruction.program_id_index as usize;
match account_keys.get(outer_ix_program_id_index) {
Some(outer_program_id) => {
if programs.contains(outer_program_id) {
ordered_ixs.push_back((
(*outer_program_id, message_instruction),
Some(non_hoisted_inner_instruction),
));
}
if let Some(outer_program_id) =
account_keys.get(message_instruction.program_id_index as usize)
{
if programs.contains(outer_program_id) {
ordered_ixs.push_back((
(*outer_program_id, message_instruction),
Some(non_hoisted_inner_instruction),
));
}
None => eprintln!("outer program id deserialization error"),
} else {
eprintln!("outer program id deserialization error");
}
}
ordered_ixs
Expand All @@ -74,25 +70,19 @@ fn hoist_known_programs<'a>(
programs: &HashSet<Pubkey>,
ix_pairs: &[IxPair<'a>],
) -> Vec<(IxPair<'a>, Option<Vec<IxPair<'a>>>)> {
// there must be a safe and less copy way to do this,
// I should only need to move CI, and copy the found nodes matching predicate on 172
ix_pairs
.iter()
.enumerate()
.filter_map(|(index, (pid, ci))| {
if programs.contains(pid) {
let mut inner_copy = vec![];
for new_inner_elem in ix_pairs.iter().skip(index + 1) {
if pid != &new_inner_elem.0 {
inner_copy.push(*new_inner_elem);
} else {
break;
}
}
Some(((*pid, *ci), Some(inner_copy)))
} else {
None
}
.filter_map(|(index, &(pid, ci))| {
programs.contains(&pid).then(|| {
let inner_copy = ix_pairs
.iter()
.skip(index + 1)
.take_while(|&&(inner_pid, _)| inner_pid != pid)
.cloned()
.collect::<Vec<IxPair<'a>>>();
((pid, ci), Some(inner_copy))
})
})
.collect()
}

0 comments on commit cd2c6b2

Please sign in to comment.