From 12f393340edaa5f73e2e26def74c9800d96745cd Mon Sep 17 00:00:00 2001 From: catalyst17 <37663786+catalyst17@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:26:12 +0100 Subject: [PATCH] feat: allow multiple batch inbox addresses --- src/map_filter_op_batch_inbox_transactions.rs | 39 ++++++++++++------- substreams.yaml | 2 +- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/map_filter_op_batch_inbox_transactions.rs b/src/map_filter_op_batch_inbox_transactions.rs index 3cec480..5e2ac13 100644 --- a/src/map_filter_op_batch_inbox_transactions.rs +++ b/src/map_filter_op_batch_inbox_transactions.rs @@ -4,27 +4,17 @@ use substreams::Hex; use substreams_ethereum::pb::eth::v2::Block; #[derive(Debug, Deserialize)] -struct Params { - op_batch_inbox: String +struct FilterParams { + op_batch_inbox_addresses: Vec } #[substreams::handlers::map] fn map_filter_op_batch_inbox_transactions(params: String, blk: Block) -> Result> { - // Parse the query string parameters safely - let query: Params = match serde_qs::from_str(¶ms) { - Ok(query) => query, - Err(_) => return Err(vec![substreams::errors::Error::msg("Failed to parse query parameters")]), - }; - - // Decode the op_batch_inbox address - let op_batch_inbox_address = match Hex::decode(&query.op_batch_inbox) { - Ok(addr) => addr, - Err(_) => return Err(vec![substreams::errors::Error::msg("Failed to decode op_batch_inbox address")]), - }; + let decoded_addresses = filters_from_params(params)?; let data: Vec = blk .transaction_traces.iter() - .filter(|tx| tx.to == op_batch_inbox_address) + .filter(|tx| decoded_addresses.iter().any(|addr| &tx.to == addr)) .map(|tx| OpBatchInboxCallData { tx_hash: Hex::encode(&tx.hash), batcher_address: Hex::encode(&tx.from), @@ -36,3 +26,24 @@ fn map_filter_op_batch_inbox_transactions(params: String, blk: Block) -> Result< Ok(ListOfOpBatchInboxCallData { data }) } + +fn filters_from_params(params: String) -> Result>, Vec> { + // Parse the query string parameters safely + let query: FilterParams = match serde_qs::from_str(¶ms) { + Ok(query) => query, + Err(_) => return Err(vec![substreams::errors::Error::msg("Failed to parse input parameters")]), + }; + + // Decode the op_batch_inbox address + let mut decoded_addresses = Vec::new(); + + for address in &query.op_batch_inbox_addresses { + let decoded_address = match Hex::decode(address) { + Ok(addr) => addr, + Err(_) => return Err(vec![substreams::errors::Error::msg("Failed to decode op_batch_inbox_addresses")]), + }; + decoded_addresses.push(decoded_address); + } + + Ok(decoded_addresses) +} \ No newline at end of file diff --git a/substreams.yaml b/substreams.yaml index ea2c420..f5fa923 100644 --- a/substreams.yaml +++ b/substreams.yaml @@ -100,4 +100,4 @@ network: mainnet networks: mainnet: params: - map_filter_op_batch_inbox_transactions: "op_batch_inbox=ff00000000000000000000000000000000000010" \ No newline at end of file + map_filter_op_batch_inbox_transactions: "op_batch_inbox_addresses[]=ff00000000000000000000000000000000000010&" \ No newline at end of file