Skip to content

Commit 5744e20

Browse files
committed
graph,runtime: Parse Block handler data type from the manifest
1 parent ec56d02 commit 5744e20

File tree

6 files changed

+106
-15
lines changed

6 files changed

+106
-15
lines changed

core/src/subgraph/instance_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ async fn process_triggers<B: BlockStreamBuilder, T: RuntimeHostBuilder, S: Send
879879
mut block_state: BlockState,
880880
proof_of_indexing: SharedProofOfIndexing,
881881
ctx: IndexingContext<B, T, S>,
882-
block: &Arc<LightEthereumBlock>,
882+
block: &Arc<EthereumBlock>,
883883
triggers: Vec<EthereumTrigger>,
884884
) -> Result<(IndexingContext<B, T, S>, BlockState), CancelableError<Error>> {
885885
for trigger in triggers.into_iter() {

graph/src/components/ethereum/adapter.rs

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

1515
use super::types::*;
1616
use crate::components::metrics::{CounterVec, GaugeVec, HistogramVec};
17+
use crate::data::subgraph::BlockHandlerData;
1718
use crate::prelude::*;
1819

1920
pub type EventSignature = H256;
@@ -422,8 +423,7 @@ impl EthereumBlockFilter {
422423
let has_block_handler_with_call_filter = data_source
423424
.mapping
424425
.block_handlers
425-
.clone()
426-
.into_iter()
426+
.iter()
427427
.any(|block_handler| match block_handler.filter {
428428
Some(ref filter) if *filter == BlockHandlerFilter::Call => return true,
429429
_ => return false,
@@ -432,14 +432,21 @@ impl EthereumBlockFilter {
432432
let has_block_handler_without_filter = data_source
433433
.mapping
434434
.block_handlers
435-
.clone()
436-
.into_iter()
435+
.iter()
437436
.any(|block_handler| block_handler.filter.is_none());
438437

439-
// TODO: process data source to get full_block boolean
438+
let has_block_handler_with_fullblock = data_source
439+
.mapping
440+
.block_handlers
441+
.iter()
442+
.any(|block_handler| match block_handler.input {
443+
BlockHandlerData::FullBlock => return true,
444+
_ => return false,
445+
});
446+
440447
filter_opt.extend(Self {
441448
trigger_every_block: has_block_handler_without_filter,
442-
full_block: true,
449+
full_block: has_block_handler_with_fullblock,
443450
contract_addresses: if has_block_handler_with_call_filter {
444451
vec![(
445452
data_source.source.start_block,

graph/src/data/subgraph/mod.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ use crate::data::query::QueryExecutionError;
2222
use crate::data::schema::{Schema, SchemaImportError, SchemaValidationError};
2323
use crate::data::store::Entity;
2424
use crate::data::subgraph::schema::{
25-
EthereumBlockHandlerEntity, EthereumCallHandlerEntity, EthereumContractAbiEntity,
26-
EthereumContractDataSourceTemplateEntity, EthereumContractDataSourceTemplateSourceEntity,
27-
EthereumContractEventHandlerEntity, EthereumContractMappingEntity,
28-
EthereumContractSourceEntity, SUBGRAPHS_ID,
25+
EthereumBlockHandlerData, EthereumBlockHandlerEntity, EthereumCallHandlerEntity,
26+
EthereumContractAbiEntity, EthereumContractDataSourceTemplateEntity,
27+
EthereumContractDataSourceTemplateSourceEntity, EthereumContractEventHandlerEntity,
28+
EthereumContractMappingEntity, EthereumContractSourceEntity, SUBGRAPHS_ID,
2929
};
3030
use crate::prelude::{
3131
anyhow::{self, Context},
@@ -515,6 +515,22 @@ 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+
}
526+
527+
impl From<EthereumBlockHandlerData> for BlockHandlerData {
528+
fn from(data: EthereumBlockHandlerData) -> Self {
529+
match data {
530+
EthereumBlockHandlerData::FullBlock => BlockHandlerData::FullBlock,
531+
_ => BlockHandlerData::Block,
532+
}
533+
}
518534
}
519535

520536
#[derive(Clone, Debug, Hash, Eq, PartialEq, Deserialize)]
@@ -530,6 +546,7 @@ impl From<EthereumBlockHandlerEntity> for MappingBlockHandler {
530546
Self {
531547
handler: entity.handler,
532548
filter: None,
549+
input: BlockHandlerData::from(entity.input),
533550
}
534551
}
535552
}

graph/src/data/subgraph/schema.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ impl TryFromValue for EthereumContractAbiEntity {
10091009
pub struct EthereumBlockHandlerEntity {
10101010
pub handler: String,
10111011
pub filter: Option<EthereumBlockHandlerFilterEntity>,
1012+
pub input: EthereumBlockHandlerData,
10121013
}
10131014

10141015
impl WriteOperations for EthereumBlockHandlerEntity {
@@ -1025,6 +1026,7 @@ impl WriteOperations for EthereumBlockHandlerEntity {
10251026
if let Some(filter_id) = filter_id {
10261027
entity.set("filter", filter_id);
10271028
}
1029+
entity.set("data", String::from(self.input));
10281030
ops.add(Self::TYPENAME, id.to_owned(), entity);
10291031
}
10301032
}
@@ -1048,6 +1050,7 @@ impl From<super::MappingBlockHandler> for EthereumBlockHandlerEntity {
10481050
EthereumBlockHandlerEntity {
10491051
handler: block_handler.handler,
10501052
filter,
1053+
input: EthereumBlockHandlerData::from(block_handler.input),
10511054
}
10521055
}
10531056
}
@@ -1065,6 +1068,7 @@ impl TryFromValue for EthereumBlockHandlerEntity {
10651068
Ok(EthereumBlockHandlerEntity {
10661069
handler: map.get_required("handler")?,
10671070
filter: map.get_optional("filter")?,
1071+
input: map.get_optional("input")?.unwrap_or_default(),
10681072
})
10691073
}
10701074
}
@@ -1106,6 +1110,69 @@ impl TryFromValue for EthereumBlockHandlerFilterEntity {
11061110
}
11071111
}
11081112

1113+
#[derive(Debug, PartialEq)]
1114+
pub enum EthereumBlockHandlerData {
1115+
Block,
1116+
FullBlock,
1117+
}
1118+
1119+
impl Default for EthereumBlockHandlerData {
1120+
fn default() -> EthereumBlockHandlerData {
1121+
EthereumBlockHandlerData::Block
1122+
}
1123+
}
1124+
1125+
impl FromStr for EthereumBlockHandlerData {
1126+
type Err = Error;
1127+
1128+
fn from_str(s: &str) -> Result<EthereumBlockHandlerData, Error> {
1129+
match s {
1130+
"FullBlock" => Ok(EthereumBlockHandlerData::FullBlock),
1131+
"Block" => Ok(EthereumBlockHandlerData::Block),
1132+
_ => Err(format_err!(
1133+
"failed to parse `{}` as EthereumBlockHandlerData",
1134+
s
1135+
)),
1136+
}
1137+
}
1138+
}
1139+
1140+
impl From<EthereumBlockHandlerData> for String {
1141+
fn from(data: EthereumBlockHandlerData) -> String {
1142+
match data {
1143+
EthereumBlockHandlerData::FullBlock => "FullBlock".into(),
1144+
EthereumBlockHandlerData::Block => "Block".into(),
1145+
}
1146+
}
1147+
}
1148+
1149+
impl From<super::BlockHandlerData> for EthereumBlockHandlerData {
1150+
fn from(data: BlockHandlerData) -> Self {
1151+
match data {
1152+
BlockHandlerData::FullBlock => EthereumBlockHandlerData::FullBlock,
1153+
_ => EthereumBlockHandlerData::Block,
1154+
}
1155+
}
1156+
}
1157+
1158+
impl From<EthereumBlockHandlerData> for q::Value {
1159+
fn from(data: EthereumBlockHandlerData) -> q::Value {
1160+
q::Value::Enum(data.into())
1161+
}
1162+
}
1163+
1164+
impl TryFromValue for EthereumBlockHandlerData {
1165+
fn try_from_value(value: &q::Value) -> Result<EthereumBlockHandlerData, Error> {
1166+
match value {
1167+
q::Value::Enum(data) => EthereumBlockHandlerData::from_str(data),
1168+
_ => Err(format_err!(
1169+
"cannot parse value as EthereumBlockHandlerData: `{:?}`",
1170+
value
1171+
)),
1172+
}
1173+
}
1174+
}
1175+
11091176
#[derive(Debug)]
11101177
pub struct EthereumCallHandlerEntity {
11111178
pub function: String,

graph/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub mod prelude {
126126
};
127127
pub use crate::data::subgraph::schema::{SubgraphDeploymentEntity, TypedEntity};
128128
pub use crate::data::subgraph::{
129-
BlockHandlerFilter, CreateSubgraphResult, DataSource, DataSourceContext,
129+
BlockHandlerData, BlockHandlerFilter, CreateSubgraphResult, DataSource, DataSourceContext,
130130
DataSourceTemplate, Link, MappingABI, MappingBlockHandler, MappingCallHandler,
131131
MappingEventHandler, SubgraphAssignmentProviderError, SubgraphAssignmentProviderEvent,
132132
SubgraphDeploymentId, SubgraphManifest, SubgraphManifestResolveError,

runtime/wasm/src/host.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl RuntimeHostTrait for RuntimeHost {
576576
proof_of_indexing: SharedProofOfIndexing,
577577
) -> Result<BlockState, anyhow::Error> {
578578
let block_handler = self.handler_for_block(trigger_type)?;
579-
let theblock: EthereumBlockType = match trigger_type {
579+
let theblock: EthereumBlockType = match dbg!(trigger_type) {
580580
EthereumBlockTriggerType::Every(BlockType::Full) => match graph::block_on_allow_panic(
581581
future::lazy(move || {
582582
self.host_exports
@@ -585,7 +585,7 @@ impl RuntimeHostTrait for RuntimeHost {
585585
})
586586
.compat(),
587587
) {
588-
Ok(block) => Ok(EthereumBlockType::Full(block)),
588+
Ok(block) => Ok(EthereumBlockType::Full(dbg!(block))),
589589
Err(e) => Err(anyhow::anyhow!(
590590
"Failed to load full block: {}, error: {}",
591591
&block.number.unwrap().to_string(),
@@ -606,7 +606,7 @@ impl RuntimeHostTrait for RuntimeHost {
606606
MappingTrigger::Block {
607607
handler: block_handler.clone(),
608608
},
609-
&Arc::new(theblock),
609+
&Arc::new(dbg!(theblock)),
610610
proof_of_indexing,
611611
)
612612
.await

0 commit comments

Comments
 (0)