Skip to content

Commit ecd5b5e

Browse files
committed
data source: Move MAX_API_VERSION check
1 parent 03f3599 commit ecd5b5e

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

chain/ethereum/src/data_source.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use web3::types::{Log, Transaction, H256};
1515
use graph::{
1616
blockchain::{self, Blockchain},
1717
prelude::{
18-
async_trait, info, lazy_static, serde_json, BlockNumber, CheapClone,
19-
DataSourceTemplateInfo, Deserialize, EthereumCall, LightEthereumBlock,
20-
LightEthereumBlockExt, LinkResolver, Logger, TryStreamExt,
18+
async_trait, info, serde_json, BlockNumber, CheapClone, DataSourceTemplateInfo,
19+
Deserialize, EthereumCall, LightEthereumBlock, LightEthereumBlockExt, LinkResolver, Logger,
20+
TryStreamExt,
2121
},
2222
};
2323

@@ -26,13 +26,6 @@ use graph::data::subgraph::{calls_host_fn, DataSourceContext, Source};
2626
use crate::chain::Chain;
2727
use crate::trigger::{EthereumBlockTriggerType, EthereumTrigger, MappingTrigger};
2828

29-
lazy_static! {
30-
static ref MAX_API_VERSION: semver::Version = std::env::var("GRAPH_MAX_API_VERSION")
31-
.ok()
32-
.and_then(|api_version_str| semver::Version::parse(&api_version_str).ok())
33-
.unwrap_or(semver::Version::new(0, 0, 5));
34-
}
35-
3629
/// Runtime representation of a data source.
3730
// Note: Not great for memory usage that this needs to be `Clone`, considering how there may be tens
3831
// of thousands of data sources in memory at once.
@@ -867,19 +860,10 @@ impl UnresolvedMapping {
867860
file: link,
868861
} = self;
869862

870-
let api_version = semver::Version::parse(&api_version)?;
871-
872-
ensure!(
873-
semver::VersionReq::parse(&format!("<= {}", *MAX_API_VERSION))
874-
.unwrap()
875-
.matches(&api_version),
876-
"The maximum supported mapping API version of this indexer is {}, but `{}` was found",
877-
*MAX_API_VERSION,
878-
api_version
879-
);
880-
881863
info!(logger, "Resolve mapping"; "link" => &link.link);
882864

865+
let api_version = semver::Version::parse(&api_version)?;
866+
883867
let (abis, runtime) = try_join(
884868
// resolve each abi
885869
abis.into_iter()

graph/src/data/subgraph/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::ensure;
12
use anyhow::{anyhow, Error};
23
use futures03::{future::try_join3, stream::FuturesOrdered, TryStreamExt as _};
34
use itertools::Itertools;
@@ -60,6 +61,10 @@ lazy_static! {
6061
.ok()
6162
.and_then(|api_version_str| Version::parse(&api_version_str).ok())
6263
.unwrap_or(SPEC_VERSION_0_0_3);
64+
static ref MAX_API_VERSION: semver::Version = std::env::var("GRAPH_MAX_API_VERSION")
65+
.ok()
66+
.and_then(|api_version_str| semver::Version::parse(&api_version_str).ok())
67+
.unwrap_or(semver::Version::new(0, 0, 5));
6368
}
6469

6570
/// Rust representation of the GraphQL schema for a `SubgraphManifest`.
@@ -790,6 +795,17 @@ impl<C: Blockchain> UnresolvedSubgraphManifest<C> {
790795
)
791796
.await?;
792797

798+
for ds in &data_sources {
799+
ensure!(
800+
semver::VersionReq::parse(&format!("<= {}", *MAX_API_VERSION))
801+
.unwrap()
802+
.matches(&ds.api_version()),
803+
"The maximum supported mapping API version of this indexer is {}, but `{}` was found",
804+
*MAX_API_VERSION,
805+
ds.api_version()
806+
);
807+
}
808+
793809
Ok(SubgraphManifest {
794810
id,
795811
spec_version,

0 commit comments

Comments
 (0)