Skip to content

Commit ba0c80f

Browse files
committed
graph: Use Ord impl for EthereumBlockHandlerData and BlockType
1 parent 7e095ea commit ba0c80f

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed

graph/src/components/ethereum/adapter.rs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -435,28 +435,14 @@ impl EthereumBlockFilter {
435435
.iter()
436436
.any(|block_handler| block_handler.filter.is_none());
437437

438-
let block_type = if data_source
438+
let block_type = data_source
439439
.mapping
440440
.block_handlers
441441
.iter()
442-
.any(|block_handler| match block_handler.input {
443-
BlockHandlerData::FullBlockWithReceipts => return true,
444-
_ => return false,
445-
}) {
446-
BlockType::FullWithReceipts
447-
} else if data_source
448-
.mapping
449-
.block_handlers
450-
.iter()
451-
.any(|block_handler| match block_handler.input {
452-
BlockHandlerData::FullBlock => return true,
453-
_ => return false,
454-
})
455-
{
456-
BlockType::Full
457-
} else {
458-
BlockType::Light
459-
};
442+
.map(|handler| &handler.input)
443+
.max()
444+
.unwrap_or(&EthereumBlockHandlerData::Block)
445+
.into();
460446

461447
filter_opt.extend(Self {
462448
trigger_every_block: has_block_handler_without_filter,
@@ -478,14 +464,7 @@ impl EthereumBlockFilter {
478464

479465
pub fn extend(&mut self, other: EthereumBlockFilter) {
480466
self.trigger_every_block = self.trigger_every_block || other.trigger_every_block;
481-
self.block_type = match self.block_type {
482-
BlockType::FullWithReceipts => BlockType::FullWithReceipts,
483-
BlockType::Full => match other.block_type {
484-
BlockType::FullWithReceipts => BlockType::FullWithReceipts,
485-
_ => BlockType::Full,
486-
},
487-
BlockType::Light => other.block_type,
488-
};
467+
self.block_type = self.block_type.max(other.block_type);
489468

490469
self.contract_addresses = self.contract_addresses.iter().cloned().fold(
491470
HashSet::new(),

graph/src/components/ethereum/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl Default for EthereumBlockType {
244244
}
245245
}
246246

247-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
247+
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Ord, Eq)]
248248
pub enum BlockType {
249249
Light,
250250
Full,

graph/src/data/subgraph/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ impl TryFromValue for EthereumBlockHandlerFilterEntity {
11101110
}
11111111
}
11121112

1113-
#[derive(Debug, PartialEq)]
1113+
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Deserialize)]
11141114
pub enum EthereumBlockHandlerData {
11151115
Block,
11161116
FullBlock,

0 commit comments

Comments
 (0)