Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change block helpers api #23

Merged
merged 11 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"core",
"substreams-antelope",
Expand All @@ -12,7 +13,7 @@ opt-level = 's'
strip = "debuginfo"

[workspace.package]
version = "0.3.4"
version = "0.4.1"
edition = "2021"
description = "Substreams development kit for Antelope chains, contains Firehose Block model and helpers."
authors = ["Fred <[email protected]>", "Denis <[email protected]>", "Yaro <[email protected]>"]
Expand Down
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,23 @@

- [Substreams documentation](https://substreams.streamingfast.io)

## 🛠 Feature Roadmap

- [x] [Antelope blocks](https://github.com/pinax-network/firehose-antelope/blob/develop/proto/sf/antelope/type/v1/type.proto)
- [x] Block helper methods
- [x] all_transaction_traces
- [x] executed_transaction_traces
- [x] transaction_traces_count
- [x] executed_input_action_count
- [x] executed_total_action_count
- [x] actions()

## Install

```
$ cargo add substreams-antelope
```

## Quickstart
## Usage

Refer to [Docs.rs](https://docs.rs/substreams-antelope/latest/substreams_antelope/struct.Block.html#implementations) for helper methods on `Block` that extract action and transaction iterators from the Antelope block.

**Cargo.toml**

```toml
[dependencies]
substreams = "0.5"
substreams-antelope = "0.2"
substreams-antelope = "0.4"
```

**src/lib.rs**
Expand All @@ -53,7 +45,7 @@ use substreams_antelope::{Block, ActionTraces};
fn map_action_traces(block: Block) -> Result<ActionTraces, Error> {
let mut action_traces = vec![];

for trx in block.executed_transaction_traces() {
for trx in block.transaction_traces() {
for trace in trx.action_traces {
action_traces.push(trace);
}
Expand All @@ -62,16 +54,16 @@ fn map_action_traces(block: Block) -> Result<ActionTraces, Error> {
}
```

Or, using `actions()` filter to filter all actions of `Statelog` type from `myaccount` account:
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**

```rust
#[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 {
transfers: block.actions::<abi::contract::actions::Transfer>(&["eosio.token"])
.map(|(action, trace)| Transfer {
// set action fields
})
.collect(),
Expand Down
Loading
Loading