Crates.io | substreams-antelope-core |
lib.rs | substreams-antelope-core |
version | 0.6.0 |
source | src |
created_at | 2023-01-04 21:24:21.750846 |
updated_at | 2024-10-16 22:38:14.57053 |
description | Substreams development kit for Antelope chains, contains Firehose Block model and helpers. |
homepage | https://github.com/pinax-network/substreams-antelope |
repository | https://github.com/pinax-network/substreams-antelope |
max_upload_size | |
id | 751153 |
size | 102,982 |
Substreams
for AntelopeThis library contains the generated Rust protobuf bindings for Antelope blocks as well as helper methods to extract and parse block data.
$ cargo add substreams-antelope
Refer to Docs.rs for helper methods on Block
that extract action and transaction iterators from the Antelope block.
Cargo.toml
[dependencies]
substreams = "0.6"
substreams-antelope = "0.6"
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 {
// action.to, action.from, action.memo, action.quantity are available here.
})
.collect(),
})
}
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/eosio.token.json")
.expect("failed to load abi")
.generate()
.expect("failed to generate contract")
.write_to_file("src/abi/eosio.token.rs")
.expect("failed to write contract");
}
gen.sh
if there were changes in protobufsCargo.toml
substreams-antelope-core
, substreams-antelope-abigen
, substreams-antelope
.TODO: automate releases with github actions