A library for writing Substreams handlers.
Substreams consists of a number of modules which provide structs and macros for implementing Substreams handlers. The handlers are defined in your Manifest. Learn more about Substreams at https://substreams.streamingfast.io
Handler Examples
Below are a few map
handler examples. The signature of the handler function is based
on the inputs and output defined in the map
module definition in the Manifest. There
are a few things to note:
- Best practice is to name your
map
module function `map_<your_action>' map
module function must always return a Result- The Result must have an Error type set to
substreams::error:Error
use substreams::prelude::{StoreGet, StoreNew};
use substreams::{errors::Error, store};
use substreams::store::{DeltaBigDecimal, StoreGetProto};
# mod eth { pub type Block = (); }
# mod pb { // holding all codegen'd protobuf structs
# pub type Custom = ();
# #[derive(Clone, PartialEq, ::prost::Message)]
# pub struct Pairs {}
}
/// Map handler which takes a source as input
#[substreams::handlers::map]
fn map_transfers(blk: eth::Block) -> Result<pb::Custom, Error> {
unimplemented!("do something");
}
/// Map handler which takes a source, and a store in get mode as inputs
#[substreams::handlers::map]
fn map_ownerships(blk: eth::Block, my_things: StoreGetProto<pb::Pairs>) -> Result<pb::Custom, Error> {
unimplemented!("do something");
}
/// Map handler which takes a source, another map, and a store in get mode as inputs
#[substreams::handlers::map]
fn map_mints(blk: eth::Block, mints: pb::Custom, myt_things: StoreGetProto<pb::Pairs>) -> Result<pb::Custom, Error> {
unimplemented!("do something");
}
/// Map handler which takes a source, another map, and a store in delta mode as inputs
#[substreams::handlers::map]
fn map_db(blk: eth::Block, mints: pb::Custom, store_deltas: store::Deltas<DeltaBigDecimal>) -> Result<pb::Custom, Error> {
unimplemented!("do something");
}
Below are a few store
handler examples. The signature of the handler function is based
on the inputs defined in the store
module definition in the Manifest. There
are a few things to note:
- Best practice is to name your
map
module function `store_<your_action>' store
module function must return nothing
use substreams::store;
use substreams::prelude::{StoreGet, StoreNew};
use substreams::store::{DeltaBigDecimal, StoreGetProto, StoreAddInt64};
# mod pb {
# use std::todo;
# use substreams::pb::substreams::StoreDelta;
# use substreams::store::Delta;
# pub type Custom = ();
#
# #[derive(Clone, PartialEq, ::prost::Message)]
# pub struct Pairs {}
# #[derive(Clone, PartialEq, ::prost::Message)]
# pub struct Tokens {}
# #[derive(Clone, PartialEq, ::prost::Message)]
# pub struct Others {}
# }
#[substreams::handlers::store]
fn store_transfers(objects: pb::Custom, output: StoreAddInt64) {
// to something
}
#[substreams::handlers::store]
fn store_ownerships(objects: pb::Custom, store: StoreGetProto<pb::Pairs>, output: StoreAddInt64) {
// to something
}
#[substreams::handlers::store]
fn store_mints(objects: pb::Custom, store: StoreGetProto<pb::Pairs>, another_store: StoreGetProto<pb::Tokens>, store_deltas: store::Deltas<DeltaBigDecimal>, output: StoreAddInt64) {
// to something
}