#substreams #firehose #antelope #thegraph #pinax #api-bindings

substreams-antelope-core

Substreams development kit for Antelope chains, contains Firehose Block model and helpers

9 releases

0.4.1 Mar 24, 2024
0.4.0 Mar 24, 2024
0.3.5 Mar 27, 2024
0.3.2 Aug 4, 2023
0.0.4 Jan 10, 2023

#5 in #antelope

Download history 29/week @ 2024-02-19 10/week @ 2024-02-26 5/week @ 2024-03-04 30/week @ 2024-03-11 465/week @ 2024-03-18 129/week @ 2024-03-25 59/week @ 2024-04-01

684 downloads per month
Used in 2 crates

MIT/Apache

490KB
5.5K SLoC

Substreams for Antelope

github crates.io docs.rs GitHub Workflow Status

This library contains the generated protobuffer for the Antelope blocks as well as helper methods to extract and parse block data.

📖 Documentation

https://docs.rs/substreams-antelope

Further resources

Install

$ cargo add substreams-antelope

Usage

Refer to Docs.rs for helper methods on Block that extract action and transaction iterators from the Antelope block.

Cargo.toml

[dependencies]
substreams = "0.5"
substreams-antelope = "0.4"

src/lib.rs

use substreams::prelude::*;
use substreams::errors::Error;
use substreams_antelope::{Block, ActionTraces};

#[substreams::handlers::map]
fn map_action_traces(block: Block) -> Result<ActionTraces, Error> {
    let mut action_traces = vec![];

    for trx in block.transaction_traces() {
        for trace in trx.action_traces {
            action_traces.push(trace);
        }
    }
    Ok(ActionTraces { action_traces })
}

Or, using actions() helper method to filter all actions of Statelog type from myaccount account. As a parameter you can specify a list of contract account names to include actions from, that can be empty if you want actions with this signature from any contract account.

src/lib.rs

#[substreams::handlers::map]
fn map_actions(param_account: String, block: substreams_antelope::Block) -> Result<Actions, substreams::errors::Error> {
    Ok(Actions {
        transfers: block.actions::<abi::contract::actions::Transfer>(&["eosio.token"])
            .map(|(action, trace)| Transfer {
                // set action fields
            })
            .collect(),
    })
}

Using Abigen

To generate ABI bindings for your smart contract you can add abi/contract.abi.json file containing the smart contract ABI, as well as the following build.rs file to the root of your project. This will ensure that src/abi/contract.rs module containing Rust bindings for your smart contract is always generated in your project:

build.rs

fn main() {
    substreams_antelope::Abigen::new("Contract", "abi/gems.blend.abi.json")
        .expect("failed to load abi")
        .generate()
        .expect("failed to generate contract")
        .write_to_file("src/abi/gems.blend.abi.rs")
        .expect("failed to write contract");
}

Dependencies

~2.2–4.5MB
~81K SLoC