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

Allow multiple batch inbox addresses #12

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/map_filter_op_batch_inbox_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
}

#[substreams::handlers::map]
fn map_filter_op_batch_inbox_transactions(params: String, blk: Block) -> Result<ListOfOpBatchInboxCallData, Vec<substreams::errors::Error>> {
// Parse the query string parameters safely
let query: Params = match serde_qs::from_str(&params) {
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<OpBatchInboxCallData> = 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),
Expand All @@ -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<Vec<u8>>, Vec<substreams::errors::Error>> {
// Parse the query string parameters safely
let query: FilterParams = match serde_qs::from_str(&params) {
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)
}
2 changes: 1 addition & 1 deletion substreams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ network: mainnet
networks:
mainnet:
params:
map_filter_op_batch_inbox_transactions: "op_batch_inbox=ff00000000000000000000000000000000000010"
map_filter_op_batch_inbox_transactions: "op_batch_inbox_addresses[]=ff00000000000000000000000000000000000010&"
Loading