Skip to content

Commit 1a06f0d

Browse files
committed
graph: Rename to_light_block, add to_json on CachedBlock
1 parent 760cccb commit 1a06f0d

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,8 +1639,8 @@ impl EthereumAdapterTrait for EthereumAdapter {
16391639
.await
16401640
.map_err(|e| error!(&logger, "Error accessing block cache {}", e))
16411641
.unwrap_or_default()
1642-
.into_iter()
1643-
.map(|b| b.into_light_block())
1642+
.iter()
1643+
.map(|b| b.to_light_block())
16441644
.collect();
16451645

16461646
let missing_blocks = Vec::from_iter(

graph/src/components/ethereum/types.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl CachedBlock {
278278
}
279279
}
280280

281-
pub fn into_light_block(&self) -> Arc<LightEthereumBlock> {
281+
pub fn to_light_block(&self) -> Arc<LightEthereumBlock> {
282282
match self {
283283
CachedBlock::Full(block) => block.block.clone(),
284284
CachedBlock::Light(block) => block.clone(),
@@ -292,6 +292,13 @@ impl CachedBlock {
292292
}
293293
}
294294

295+
pub fn to_json(&self) -> serde_json::Result<serde_json::Value> {
296+
match self {
297+
CachedBlock::Full(b) => serde_json::to_value(b),
298+
CachedBlock::Light(b) => serde_json::to_value(b),
299+
}
300+
}
301+
295302
/// Deserializes a JSON block from the store into a typed `CachedBlock`.
296303
/// Returns `None` for shallow (header-only) blocks.
297304
///

server/index-node/src/resolver.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use graph::schema::EntityType;
99
use git_testament::{git_testament, CommitKind};
1010
use graph::amp;
1111
use graph::blockchain::{Blockchain, BlockchainKind, BlockchainMap};
12-
use graph::components::ethereum::CachedBlock;
1312
use graph::components::link_resolver::LinkResolverContext;
1413
use graph::components::store::{BlockPtrForNumber, BlockStore, QueryPermit, Store};
1514
use graph::components::versions::VERSIONS;
@@ -237,10 +236,7 @@ where
237236
Ok(mut blocks) => {
238237
assert!(blocks.len() == 1, "Multiple blocks with the same hash");
239238
let block = blocks.pop().unwrap();
240-
let json = match block {
241-
CachedBlock::Full(ref b) => serde_json::to_value(b),
242-
CachedBlock::Light(ref b) => serde_json::to_value(b),
243-
};
239+
let json = block.to_json();
244240
match json {
245241
Ok(json) => json.into(),
246242
Err(e) => {

0 commit comments

Comments
 (0)