diff --git a/solana-explorer/src/lib.rs b/solana-explorer/src/lib.rs index fbbd939..fed52fb 100644 --- a/solana-explorer/src/lib.rs +++ b/solana-explorer/src/lib.rs @@ -3,4 +3,4 @@ mod map_block_full; mod map_block_meta; mod map_filter_instructions; mod map_filter_transactions; -mod map_block_full_no_vote; \ No newline at end of file +mod map_block_without_votes; \ No newline at end of file diff --git a/solana-explorer/src/map_block_full_no_vote.rs b/solana-explorer/src/map_block_full_no_vote.rs deleted file mode 100644 index 7a307f9..0000000 --- a/solana-explorer/src/map_block_full_no_vote.rs +++ /dev/null @@ -1,35 +0,0 @@ -use substreams_solana::pb::sf::solana::r#type::v1::{Block, ConfirmedTransaction}; - -const VOTE_INSTRUCTION: &str = "Vote111111111111111111111111111111111111111"; - -#[substreams::handlers::map] -fn map_block_full_no_vote(block: Block) -> Result { - let mut block_cloned: Block = block.clone(); - - let filtered_transactions: Vec = block.transactions_owned() - .filter(|confirmed_trx| { - let mut valid = false; - let accounts = confirmed_trx.resolved_accounts_as_strings(); - - if let Some(trx) = &confirmed_trx.transaction { - let instructions = trx.message.clone().unwrap().instructions; - - if instructions.len() > 1 { - valid = true - } - - let instruction = &instructions[0]; - let instruction_id = &accounts[instruction.program_id_index as usize]; - - if instruction_id != &VOTE_INSTRUCTION.to_string() { - valid = true - } - } - - valid - }).collect(); - - block_cloned.transactions = filtered_transactions; - - Ok(block_cloned) -} diff --git a/solana-explorer/src/map_block_without_votes.rs b/solana-explorer/src/map_block_without_votes.rs new file mode 100644 index 0000000..cdcd990 --- /dev/null +++ b/solana-explorer/src/map_block_without_votes.rs @@ -0,0 +1,34 @@ +use substreams_solana::pb::sf::solana::r#type::v1::{Block, ConfirmedTransaction}; + +static VOTE_INSTRUCTION: &[u8] = b"Vote111111111111111111111111111111111111111"; + +#[substreams::handlers::map] +fn map_block_without_votes(block: Block) -> Result { + let mut block_cloned: Block = block.clone(); + + let filtered_transactions: Vec = block.transactions_owned() + .filter(|trx| { + let meta = match trx.meta.as_ref() { + Some(meta) => meta, + None => return false, + }; + if meta.err.is_some() { + return false; + } + let transaction = match trx.transaction.as_ref() { + Some(transaction) => transaction, + None => return false, + }; + let message = transaction.message.as_ref().expect("Message is missing"); + + if message.account_keys.contains(&VOTE_INSTRUCTION.to_vec()) { + return false; + } + + true + }).collect(); + + block_cloned.transactions = filtered_transactions; + + Ok(block_cloned) +} diff --git a/solana-explorer/substreams.yaml b/solana-explorer/substreams.yaml index 9b0481d..2c55a17 100644 --- a/solana-explorer/substreams.yaml +++ b/solana-explorer/substreams.yaml @@ -34,7 +34,7 @@ modules: doc: | `map_block_full` allows you to view a complete block, as received by a Substreams module - - name: map_block_full_no_vote + - name: map_block_without_votes kind: map inputs: - source: sf.solana.type.v1.Block