Skip to content

Commit

Permalink
add kv module
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroShkvorets committed Feb 23, 2024
1 parent f0ab7aa commit 8aca99d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions eth.blobs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions eth.blobs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions eth.blobs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Blobs, substreams::errors::Error> {
Expand All @@ -25,3 +26,16 @@ fn map_blobs(blk: BeaconBlock) -> Result<Blobs, substreams::errors::Error> {
};
Ok(Blobs { blobs })
}

#[substreams::handlers::map]
fn kv_out(blobs: Blobs) -> Result<KvOperations, substreams::errors::Error> {
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)
}
17 changes: 17 additions & 0 deletions eth.blobs/substreams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit 8aca99d

Please sign in to comment.