-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
101 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
use common::{blocks::insert_timestamp, utils::hex_array_to_string}; | ||
use substreams::{pb::substreams::Clock, Hex}; | ||
use substreams_database_change::pb::database::{table_change, DatabaseChanges}; | ||
use common::utils::bytes_to_hex; | ||
|
||
use crate::{keys::blob_keys, pb::sf::beacon::r#type::v1::Blob}; | ||
use crate::{ | ||
pb::{beacon::rawblocks::Blob as RawBlob, sf::beacon::r#type::v1::Blob}, | ||
structs::BlockTimestamp, | ||
utils::encode_hex_2d_array, | ||
}; | ||
|
||
pub fn insert_blobs(tables: &mut DatabaseChanges, clock: &Clock, blobs: &Vec<Blob>) { | ||
for b in blobs { | ||
let index = b.index; | ||
let blob = Hex::encode(&b.blob); | ||
let kzg_commitment = Hex::encode(&b.kzg_commitment); | ||
let kzg_proof = Hex::encode(&b.kzg_proof); | ||
let kzg_commitment_inclusion_proof = hex_array_to_string(&b.kzg_commitment_inclusion_proof); | ||
|
||
let keys = blob_keys(&clock.id, index); | ||
|
||
let row = tables | ||
.push_change_composite("blobs", keys, 0, table_change::Operation::Create) | ||
.change("blob", ("", blob.as_str())) | ||
.change("kzg_commitment", ("", kzg_commitment.as_str())) | ||
.change("kzg_proof", ("", kzg_proof.as_str())) | ||
.change("kzg_commitment_inclusion_proof", ("", kzg_commitment_inclusion_proof.as_str())); | ||
pub fn collect_blobs(blobs: &Vec<Blob>, timestamp: &BlockTimestamp) -> Vec<RawBlob> { | ||
let mut blobs_vec = Vec::<RawBlob>::new(); | ||
|
||
insert_timestamp(row, clock, false, true); | ||
for b in blobs { | ||
blobs_vec.push(RawBlob { | ||
block_time: Some(timestamp.time), | ||
block_number: timestamp.number, | ||
block_date: timestamp.date.clone(), | ||
block_hash: timestamp.hash.clone(), | ||
index: b.index, | ||
blob: bytes_to_hex(&b.blob), | ||
kzg_commitment: bytes_to_hex(&b.kzg_commitment), | ||
kzg_proof: bytes_to_hex(&b.kzg_proof), | ||
kzg_commitment_inclusion_proof: encode_hex_2d_array(&b.kzg_commitment_inclusion_proof), | ||
}); | ||
} | ||
|
||
blobs_vec | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters