Skip to content

Commit

Permalink
Use csv string for beacon
Browse files Browse the repository at this point in the history
  • Loading branch information
zolting committed Nov 14, 2024
1 parent de4ea04 commit dd1d2c3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
6 changes: 4 additions & 2 deletions blocks/beacon-parquet/proto/beacon.rawblocks.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ message Blob {
string blob = 6;
string kzg_commitment = 7;
string kzg_proof = 8;
repeated string kzg_commitment_inclusion_proof = 9;
// csv string for now but should be array(text) once supported
string kzg_commitment_inclusion_proof = 9;
}

message Deposit {
Expand All @@ -61,7 +62,8 @@ message Deposit {

// deposit
uint64 index = 5;
repeated string proof = 6;
// csv string for now but should be array(text) once supported
string proof = 6;
string pubkey = 7;
string withdrawal_credentials = 8;
string signature = 9;
Expand Down
5 changes: 3 additions & 2 deletions blocks/beacon-parquet/src/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use common::utils::bytes_to_hex;
use crate::{
pb::{beacon::rawblocks::Blob as RawBlob, sf::beacon::r#type::v1::Blob},
structs::BlockTimestamp,
utils::encode_hex_2d_array,
utils::encode_2d_array_to_csv_string,
};

pub fn collect_blobs(blobs: &Vec<Blob>, timestamp: &BlockTimestamp) -> Vec<RawBlob> {
Expand All @@ -19,7 +19,8 @@ pub fn collect_blobs(blobs: &Vec<Blob>, timestamp: &BlockTimestamp) -> Vec<RawBl
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),
// TODO: use encode_hex_2d_array once Array(Text) is supported
kzg_commitment_inclusion_proof: encode_2d_array_to_csv_string(&b.kzg_commitment_inclusion_proof),
});
}

Expand Down
5 changes: 3 additions & 2 deletions blocks/beacon-parquet/src/deposits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use common::utils::bytes_to_hex;
use crate::{
pb::{beacon::rawblocks::Deposit as RawDeposit, sf::beacon::r#type::v1::Deposit},
structs::BlockTimestamp,
utils::encode_hex_2d_array,
utils::{encode_2d_array_to_csv_string, encode_hex_2d_array},
};

pub fn collect_deposits(deposits: &Vec<Deposit>, timestamp: &BlockTimestamp) -> Vec<RawDeposit> {
Expand All @@ -16,7 +16,8 @@ pub fn collect_deposits(deposits: &Vec<Deposit>, timestamp: &BlockTimestamp) ->
block_date: timestamp.date.clone(),
block_hash: timestamp.hash.clone(),
index: index as u64,
proof: encode_hex_2d_array(&d.proof),
// TODO: use encode_hex_2d_array once Array(Text) is supported
proof: encode_2d_array_to_csv_string(&d.proof),
pubkey: bytes_to_hex(&d.data.as_ref().unwrap().public_key),
withdrawal_credentials: bytes_to_hex(&d.data.as_ref().unwrap().withdrawal_credentials),
signature: bytes_to_hex(&d.data.as_ref().unwrap().signature),
Expand Down
10 changes: 6 additions & 4 deletions blocks/beacon-parquet/src/pb/beacon.rawblocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ pub struct Blob {
pub kzg_commitment: ::prost::alloc::string::String,
#[prost(string, tag="8")]
pub kzg_proof: ::prost::alloc::string::String,
#[prost(string, repeated, tag="9")]
pub kzg_commitment_inclusion_proof: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// csv string for now but should be array(text) once supported
#[prost(string, tag="9")]
pub kzg_commitment_inclusion_proof: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand All @@ -95,8 +96,9 @@ pub struct Deposit {
/// deposit
#[prost(uint64, tag="5")]
pub index: u64,
#[prost(string, repeated, tag="6")]
pub proof: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// csv string for now but should be array(text) once supported
#[prost(string, tag="6")]
pub proof: ::prost::alloc::string::String,
#[prost(string, tag="7")]
pub pubkey: ::prost::alloc::string::String,
#[prost(string, tag="8")]
Expand Down
2 changes: 1 addition & 1 deletion blocks/beacon-parquet/src/pb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub mod sf {
}
}
pub mod sink {

pub mod service {
// @@protoc_insertion_point(attribute:sf.substreams.sink.service.v1)
pub mod v1 {
Expand All @@ -46,6 +45,7 @@ pub mod sf {
pub mod r#type {
pub mod v1 {
include!("sf.beacon.type.v1.rs");
// @@protoc_insertion_point(sf.beacon.type.v1)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions blocks/beacon-parquet/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ pub fn build_timestamp(clock: &Clock) -> BlockTimestamp {
pub fn encode_hex_2d_array(hex_array: &Vec<Vec<u8>>) -> Vec<String> {
hex_array.iter().map(|bytes| bytes_to_hex(bytes)).collect()
}

pub fn encode_2d_array_to_csv_string(hex_array: &Vec<Vec<u8>>) -> String {
hex_array.iter().map(|bytes| bytes_to_hex(bytes)).collect::<Vec<String>>().join(",")
}

0 comments on commit dd1d2c3

Please sign in to comment.