datasource/ethereum: Use more combinators when parsing triggers
@@ -1370,10 +1370,7 @@ fn parse_log_triggers(
log_filter: Option<EthereumLogFilter>,
block: &EthereumBlock,
) -> Vec<EthereumTrigger> {
- if log_filter.is_none() {
- return vec![];
- }
- let log_filter = log_filter.unwrap();
+ log_filter.map_or(vec![], |log_filter| {
block
.transaction_receipts
.iter()
@@ -1386,40 +1383,43 @@ fn parse_log_triggers(
.map(move |log| EthereumTrigger::Log(log.clone()))
})
.collect()
+ })
}
fn parse_call_triggers(
call_filter: Option<EthereumCallFilter>,
block: &EthereumBlockWithCalls,
) -> Vec<EthereumTrigger> {
- if call_filter.is_none() || block.calls.is_none() {
- return vec![];
- }
- let call_filter = call_filter.unwrap();
- let calls = &block.calls.clone().unwrap();
+ call_filter.map_or(vec![], move |call_filter| {
+ block.calls.as_ref().map_or(vec![], |calls| {
calls
.iter()
.filter(move |call| call_filter.matches(call))
.map(move |call| EthereumTrigger::Call(call.clone()))
.collect()
+ })
+ })
}
fn parse_block_triggers(
block_filter: Option<EthereumBlockFilter>,
block: &EthereumBlockWithCalls,
) -> Vec<EthereumTrigger> {
- if block_filter.is_none() {
- return vec![];
- }
- let call_filter = EthereumCallFilter::from(block_filter.clone().unwrap());
- let calls = &block.calls.clone().unwrap();
- let mut triggers = calls
+ block_filter.map_or(vec![], move |block_filter| {
+ let trigger_every_block = block_filter.trigger_every_block;
+ let call_filter = EthereumCallFilter::from(block_filter);
+ let mut triggers = block.calls.as_ref().map_or(vec![], |calls| {
+ calls
.iter()
.filter(move |call| call_filter.matches(call))
- .map(move |call| EthereumTrigger::Block(EthereumBlockTriggerType::WithCallTo(call.to)))
- .collect::<Vec<EthereumTrigger>>();
- if block_filter.unwrap().trigger_every_block {
+ .map(move |call| {
+ EthereumTrigger::Block(EthereumBlockTriggerType::WithCallTo(call.to))
+ })
+ .collect::<Vec<EthereumTrigger>>()
+ });
+ if trigger_every_block {
triggers.push(EthereumTrigger::Block(EthereumBlockTriggerType::Every));
}
triggers
+ })
}
