substreams-antelope

Crates.iosubstreams-antelope
lib.rssubstreams-antelope
version0.3.5
sourcesrc
created_at2023-01-24 23:27:52.595505
updated_at2024-03-27 14:08:05.513391
descriptionSubstreams development kit for Antelope chains, contains Firehose Block model and helpers.
homepagehttps://github.com/pinax-network/substreams-antelope
repositoryhttps://github.com/pinax-network/substreams-antelope
max_upload_size
id767005
size5,626
Yaro Shkvorets (YaroShkvorets)

documentation

README

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

🛠 Feature Roadmap

  • Antelope blocks
  • Block helper methods
    • all_transaction_traces
    • executed_transaction_traces
    • transaction_traces_count
    • executed_input_action_count
    • executed_total_action_count
    • actions()

Install

$ cargo add substreams-antelope

Quickstart

Cargo.toml

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

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.executed_transaction_traces() {
        for trace in trx.action_traces {
            action_traces.push(trace);
        }
    }
    Ok(ActionTraces { action_traces })
}

Or, using actions() filter to filter all actions of Statelog type from myaccount account:

src/lib.rs

#[substreams::handlers::map]
fn map_actions(param_account: String, block: substreams_antelope::Block) -> Result<Actions, substreams::errors::Error> {
    Ok(Actions {
        statelogs: block.actions::<abi::contract::actions::Statelog>(&["myaccount"])
            .map(|(action, trx)| StateLog {
                // 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");
}
Commit count: 158

cargo fmt