diff --git a/Cargo.lock b/Cargo.lock index c0048b9..af142cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -644,7 +644,7 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "blockbuster" -version = "1.1.0" +version = "2.0.0" dependencies = [ "anchor-lang", "async-trait", diff --git a/blockbuster/Cargo.toml b/blockbuster/Cargo.toml index 3eddb8a..4139902 100644 --- a/blockbuster/Cargo.toml +++ b/blockbuster/Cargo.toml @@ -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 "] repository = "https://github.com/metaplex-foundation/blockbuster" license = "AGPL-3.0" diff --git a/blockbuster/src/instruction.rs b/blockbuster/src/instruction.rs index f8ae0cf..f4544c1 100644 --- a/blockbuster/src/instruction.rs +++ b/blockbuster/src/instruction.rs @@ -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::>() + .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::>(); 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 @@ -74,25 +70,19 @@ fn hoist_known_programs<'a>( programs: &HashSet, ix_pairs: &[IxPair<'a>], ) -> Vec<(IxPair<'a>, Option>>)> { - // 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::>>(); + ((pid, ci), Some(inner_copy)) + }) }) .collect() }