From 8aca99d34528289f785649e0c69f95190858959c Mon Sep 17 00:00:00 2001 From: YaroShkvorets Date: Fri, 23 Feb 2024 09:56:51 -0500 Subject: [PATCH] add kv module --- Cargo.toml | 2 +- eth.blobs/Cargo.toml | 1 + eth.blobs/Makefile | 4 ++-- eth.blobs/src/lib.rs | 14 ++++++++++++++ eth.blobs/substreams.yaml | 17 +++++++++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1415ec9..e4483aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ substreams = "0.5" substreams-antelope = "0.3.2" substreams-ethereum = "0.9" substreams-bitcoin = "1" -substreams-sink-kv = "0.1.2" +substreams-sink-kv = "0.1.3" substreams-sink-prometheus = "0.1" substreams-sink-winston = "0.1" substreams-database-change = "1.3.0" diff --git a/eth.blobs/Cargo.toml b/eth.blobs/Cargo.toml index 7a7773a..51bb865 100644 --- a/eth.blobs/Cargo.toml +++ b/eth.blobs/Cargo.toml @@ -13,6 +13,7 @@ substreams = { workspace = true } substreams-database-change = { workspace = true } substreams-entity-change = { workspace = true } substreams-ethereum = { workspace = true } +substreams-sink-kv = { workspace = true } [build-dependencies] diff --git a/eth.blobs/Makefile b/eth.blobs/Makefile index fc1cb1a..7967948 100644 --- a/eth.blobs/Makefile +++ b/eth.blobs/Makefile @@ -4,8 +4,8 @@ ENDPOINT ?= goerli-scdm37b.mar.eosn.io:10016 build: cargo build --target wasm32-unknown-unknown --release -.PHONY: codegen -codegen: +.PHONY: protogen +protogen: substreams protogen ./substreams.yaml --exclude-paths="sf/substreams,google,sf/ethereum" .PHONE: package diff --git a/eth.blobs/src/lib.rs b/eth.blobs/src/lib.rs index 19bb8e5..fd77f61 100644 --- a/eth.blobs/src/lib.rs +++ b/eth.blobs/src/lib.rs @@ -2,6 +2,7 @@ mod pb; use pb::eth::blobs::v1::{Blob, Blobs}; use pb::sf::beacon::r#type::v1::{block::Body::*, Block as BeaconBlock}; +use substreams_sink_kv::pb::sf::substreams::sink::kv::v1::KvOperations; #[substreams::handlers::map] fn map_blobs(blk: BeaconBlock) -> Result { @@ -25,3 +26,16 @@ fn map_blobs(blk: BeaconBlock) -> Result { }; Ok(Blobs { blobs }) } + +#[substreams::handlers::map] +fn kv_out(blobs: Blobs) -> Result { + let mut kv_ops: KvOperations = Default::default(); + + for blob in blobs.blobs { + let key = format!("slot:{}:{}", blob.slot, blob.index); + let value = substreams::proto::encode(&blob).expect("unable to encode blob"); + kv_ops.push_new(key, value, 1); + } + + Ok(kv_ops) +} diff --git a/eth.blobs/substreams.yaml b/eth.blobs/substreams.yaml index c1ee61c..ee6918e 100644 --- a/eth.blobs/substreams.yaml +++ b/eth.blobs/substreams.yaml @@ -6,6 +6,7 @@ package: imports: eth: https://github.com/streamingfast/firehose-ethereum/releases/download/v2.0.0/ethereum-v1.1.0.spkg beacon: https://github.com/pinax-network/firehose-beacon/releases/download/v0.1.0/beacon-v0.1.0.spkg + kv: https://github.com/streamingfast/substreams-sink-kv/releases/download/v2.1.6/substreams-sink-kv-v2.1.6.spkg protobuf: files: @@ -20,8 +21,24 @@ binaries: modules: - name: map_blobs + initialBlock: 7677000 kind: map inputs: - source: sf.beacon.type.v1.Block output: type: proto:eth.blobs.v1.Blobs + + - name: kv_out + initialBlock: 7677000 + kind: map + inputs: + - map: map_blobs + output: + type: proto:sf.substreams.sink.kv.v1.KVOperations + +sink: + module: kv_out + type: sf.substreams.sink.kv.v1.GenericService + config: + +network: mainnet-cl