Skip to content

Commit bbb2910

Browse files
committed
graph: Remove duplicate struct BlockHandlerData
EthereumBlockHandlerData has the same variants, no need for both.
1 parent ba0c80f commit bbb2910

File tree

5 files changed

+25
-34
lines changed

5 files changed

+25
-34
lines changed

graph/src/components/ethereum/adapter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use web3::types::*;
1414

1515
use super::types::*;
1616
use crate::components::metrics::{CounterVec, GaugeVec, HistogramVec};
17-
use crate::data::subgraph::BlockHandlerData;
1817
use crate::prelude::*;
1918

2019
pub type EventSignature = H256;

graph/src/components/ethereum/types.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::convert::TryFrom;
77
use std::fmt;
88
use web3::types::*;
99

10-
use crate::prelude::{EntityKey, SubgraphDeploymentId, ToEntityKey};
10+
use crate::prelude::{
11+
anyhow, EntityKey, EthereumBlockHandlerData, SubgraphDeploymentId, ToEntityKey,
12+
};
1113

1214
pub type LightEthereumBlock = Block<Transaction>;
1315

@@ -257,6 +259,22 @@ impl Default for BlockType {
257259
}
258260
}
259261

262+
impl<'a> From<&'a EthereumBlockHandlerData> for BlockType {
263+
fn from(block: &'a EthereumBlockHandlerData) -> BlockType {
264+
match block {
265+
EthereumBlockHandlerData::Block => BlockType::Light,
266+
EthereumBlockHandlerData::FullBlock => BlockType::Full,
267+
EthereumBlockHandlerData::FullBlockWithReceipts => BlockType::FullWithReceipts,
268+
}
269+
}
270+
}
271+
272+
#[derive(Clone, Debug, PartialEq, Eq)]
273+
pub struct EthereumBlockTrigger {
274+
pub block_type: BlockType,
275+
pub trigger_type: EthereumBlockTriggerType,
276+
}
277+
260278
#[derive(Clone, Debug, PartialEq, Eq)]
261279
pub enum EthereumBlockTriggerType {
262280
Every,

graph/src/data/subgraph/mod.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -515,26 +515,7 @@ impl UnresolvedMappingABI {
515515
pub struct MappingBlockHandler {
516516
pub handler: String,
517517
pub filter: Option<BlockHandlerFilter>,
518-
pub input: BlockHandlerData,
519-
}
520-
521-
#[derive(Clone, Debug, Hash, Eq, PartialEq, Deserialize)]
522-
pub enum BlockHandlerData {
523-
Block,
524-
FullBlock,
525-
FullBlockWithReceipts,
526-
}
527-
528-
impl From<EthereumBlockHandlerData> for BlockHandlerData {
529-
fn from(data: EthereumBlockHandlerData) -> Self {
530-
match data {
531-
EthereumBlockHandlerData::FullBlockWithReceipts => {
532-
BlockHandlerData::FullBlockWithReceipts
533-
}
534-
EthereumBlockHandlerData::FullBlock => BlockHandlerData::FullBlock,
535-
EthereumBlockHandlerData::Block => BlockHandlerData::Block,
536-
}
537-
}
518+
pub input: EthereumBlockHandlerData,
538519
}
539520

540521
#[derive(Clone, Debug, Hash, Eq, PartialEq, Deserialize)]
@@ -550,7 +531,7 @@ impl From<EthereumBlockHandlerEntity> for MappingBlockHandler {
550531
Self {
551532
handler: entity.handler,
552533
filter: None,
553-
input: BlockHandlerData::from(entity.input),
534+
input: entity.input,
554535
}
555536
}
556537
}

graph/src/data/subgraph/schema.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,15 +1149,6 @@ impl From<EthereumBlockHandlerData> for String {
11491149
}
11501150
}
11511151

1152-
impl From<super::BlockHandlerData> for EthereumBlockHandlerData {
1153-
fn from(data: BlockHandlerData) -> Self {
1154-
match data {
1155-
BlockHandlerData::FullBlock => EthereumBlockHandlerData::FullBlock,
1156-
_ => EthereumBlockHandlerData::Block,
1157-
}
1158-
}
1159-
}
1160-
11611152
impl From<EthereumBlockHandlerData> for q::Value {
11621153
fn from(data: EthereumBlockHandlerData) -> q::Value {
11631154
q::Value::Enum(data.into())

graph/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ pub mod prelude {
127127
AssignmentEvent, Attribute, Entity, NodeId, SubgraphEntityPair, SubgraphVersionSummary,
128128
ToEntityId, ToEntityKey, TryIntoEntity, Value, ValueType,
129129
};
130-
pub use crate::data::subgraph::schema::{SubgraphDeploymentEntity, TypedEntity};
130+
pub use crate::data::subgraph::schema::{
131+
EthereumBlockHandlerData, SubgraphDeploymentEntity, TypedEntity,
132+
};
131133
pub use crate::data::subgraph::{
132-
BlockHandlerData, BlockHandlerFilter, CreateSubgraphResult, DataSource, DataSourceContext,
134+
BlockHandlerFilter, CreateSubgraphResult, DataSource, DataSourceContext,
133135
DataSourceTemplate, Link, MappingABI, MappingBlockHandler, MappingCallHandler,
134136
MappingEventHandler, SubgraphAssignmentProviderError, SubgraphAssignmentProviderEvent,
135137
SubgraphDeploymentId, SubgraphManifest, SubgraphManifestResolveError,

0 commit comments

Comments
 (0)