Skip to content

Commit

Permalink
feat: add explorer models maping
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdeafbeef committed Jun 27, 2024
1 parent 6b976f2 commit 2b694e0
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"simulator",
"storage",
"util",
"explorer-mapper",
]

[workspace.dependencies]
Expand Down
17 changes: 17 additions & 0 deletions explorer-mapper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "explorer-mapper"
edition = "2021"
version.workspace = true
authors.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
anyhow = { workspace = true }
explorer-models = { path = "../explorer-models" }
everscale-types = { workspace = true }
serde_json = { workspace = true }

[lints]
workspace = true
71 changes: 71 additions & 0 deletions explorer-mapper/src/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use anyhow::Result;
use everscale_types::models::{Block as BCBlock, BlockId, BlockInfo as BCBlockInfo, PrevBlockRef};
use explorer_models::{Block, BlockInfo, GlobalVersion, HashInsert, ProcessingContext};

pub fn fill_block(ctx: &mut ProcessingContext, block: &BCBlock, block_id: BlockId) -> Result<()> {
let block_info = block.load_info()?;
let prev_info = match block_info.load_prev_ref()? {
PrevBlockRef::Single(rf) => (rf, None),
PrevBlockRef::AfterMerge { left, right } => (left, Some(right)),
};

let block = Block {
workchain: block_id.shard.workchain() as i8,
shard: block_id.shard.prefix(),
seqno: block_id.seqno,
root_hash: HashInsert {
hash: block_id.root_hash.0,
},
file_hash: HashInsert {
hash: block_id.file_hash.0,
},
is_key_block: block_info.key_block,
transaction_count: 0,
gen_utime: block_info.gen_utime,
gen_software_version: block_info.gen_software.version,
prev1: HashInsert {
hash: prev_info.0.root_hash.0,
},
prev1_seqno: prev_info.0.seqno,
prev2: prev_info.1.map(|rf| HashInsert {
hash: rf.root_hash.0,
}),
prev2_seqno: prev_info.1.map(|rf| rf.seqno),
prev_key_block: block_info.prev_key_block_seqno,
block_info: "".to_string(),
value_flow: "".to_string(),
account_blocks: "".to_string(),
shards_info: None,
additional_info: None,
};
}

fn fill_block_info(
ctx: &mut ProcessingContext,
block: &BCBlock,
block_info: &BCBlockInfo,
) -> Result<()> {
let block_info = BlockInfo {
version: block_info.version,
after_merge: block_info.after_merge,
before_split: block_info.before_split,
after_split: block_info.after_split,
want_split: block_info.want_split,
want_merge: block_info.want_merge,
key_block: block_info.key_block,
vert_seq_no: block_info.vert_seqno,
vert_seq_no_incr: 0, // todo: what is this?
flags: block_info.flags,
start_lt: block_info.start_lt,
end_lt: block_info.end_lt,
gen_validator_list_hash_short: block_info.gen_validator_list_hash_short,
gen_catchain_seqno: block_info.gen_catchain_seqno,
min_ref_mc_seqno: block_info.min_ref_mc_seqno,
prev_key_block_seqno: block_info.prev_key_block_seqno,
gen_software: Some(GlobalVersion{

Check failure on line 65 in explorer-mapper/src/block.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

mismatched closing delimiter: `}`
version: 0,
capabilities: 0,
},

};
}
10 changes: 10 additions & 0 deletions explorer-mapper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use everscale_types::models::Block;
use explorer_models::ProcessingContext;

mod block;

pub fn fill_processing_context(block: Block) -> ProcessingContext {
let mut context = ProcessingContext::default();
context.blocks.push(block);
context
}

0 comments on commit 2b694e0

Please sign in to comment.