Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf4cbed

Browse files
committed
store: Refactor StoredDynamicDataSource.context to json value
1 parent 810286a commit cf4cbed

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

chain/ethereum/src/data_source.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use graph::prelude::ethabi::ethereum_types::H160;
66
use graph::prelude::ethabi::StateMutability;
77
use graph::prelude::futures03::future::try_join;
88
use graph::prelude::futures03::stream::FuturesOrdered;
9-
use graph::prelude::{Entity, Link, SubgraphManifestValidationError};
9+
use graph::prelude::{Link, SubgraphManifestValidationError};
1010
use graph::slog::{o, trace};
1111
use std::str::FromStr;
1212
use std::{convert::TryFrom, sync::Arc};
@@ -125,7 +125,7 @@ impl blockchain::DataSource<Chain> for DataSource {
125125
.context
126126
.as_ref()
127127
.as_ref()
128-
.map(|ctx| serde_json::to_string(&ctx).unwrap()),
128+
.map(|ctx| serde_json::to_value(&ctx).unwrap()),
129129
creation_block: self.creation_block,
130130
}
131131
}
@@ -141,9 +141,7 @@ impl blockchain::DataSource<Chain> for DataSource {
141141
creation_block,
142142
} = stored;
143143

144-
let context = context
145-
.map(|ctx| serde_json::from_str::<Entity>(&ctx))
146-
.transpose()?;
144+
let context = context.map(serde_json::from_value).transpose()?;
147145

148146
let contract_abi = template.mapping.find_abi(&template.source.abi)?;
149147

graph/src/components/store/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ pub enum UnfailOutcome {
834834
pub struct StoredDynamicDataSource {
835835
pub name: String,
836836
pub address: Option<Address>,
837-
pub context: Option<String>,
837+
pub context: Option<serde_json::Value>,
838838
pub creation_block: Option<BlockNumber>,
839839
}
840840

store/postgres/src/dynds/shared.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use graph::{
1313
components::store::StoredDynamicDataSource,
1414
constraint_violation,
1515
prelude::{
16-
bigdecimal::ToPrimitive, web3::types::H160, BigDecimal, BlockNumber, BlockPtr,
16+
bigdecimal::ToPrimitive, serde_json, web3::types::H160, BigDecimal, BlockNumber, BlockPtr,
1717
DeploymentHash, StoreError,
1818
},
1919
};
@@ -74,7 +74,7 @@ pub(super) fn load(
7474
let data_source = StoredDynamicDataSource {
7575
name,
7676
address,
77-
context,
77+
context: context.map(|ctx| serde_json::from_str(&ctx)).transpose()?,
7878
creation_block,
7979
};
8080

@@ -123,7 +123,7 @@ pub(super) fn insert(
123123
Ok((
124124
decds::deployment.eq(deployment.as_str()),
125125
decds::name.eq(name),
126-
decds::context.eq(context),
126+
decds::context.eq(serde_json::to_string(context).unwrap()),
127127
decds::address.eq(address),
128128
decds::abi.eq(""),
129129
decds::start_block.eq(0),

0 commit comments

Comments
 (0)