Skip to content

Commit

Permalink
Replaced db_out with graph_out in eosio.token
Browse files Browse the repository at this point in the history
  • Loading branch information
chamorin committed May 8, 2023
1 parent 6a92eba commit 9a057d3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 37 deletions.
1 change: 1 addition & 0 deletions eosio.token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ substreams-database-change = { workspace = true }
substreams-sink-kv = { workspace = true }
substreams-sink-winston = { workspace = true }
substreams-antelope = { workspace = true }
substreams-entity-change = { workspace = true }
6 changes: 3 additions & 3 deletions eosio.token/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ param:
sink:
substreams run -e eos.firehose.eosnation.io:9001 log_out -s 292442484 -t +1000000 -o jsonl

.PHONY: db_out
db_out:
substreams gui -e eos.firehose.eosnation.io:9001 db_out -s 292442484 -t +1000000
.PHONY: graph_out
graph_out:
substreams gui -e eos.firehose.eosnation.io:9001 graph_out -s 292442484 -t +1000000
20 changes: 10 additions & 10 deletions eosio.token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ graph TD;
sf.antelope.type.v1.Block[source: sf.antelope.type.v1.Block] --> map_accounts;
map_stat[map: map_stat];
sf.antelope.type.v1.Block[source: sf.antelope.type.v1.Block] --> map_stat;
db_out[map: db_out];
map_transfers --> db_out;
graph_out[map: graph_out];
map_transfers --> graph_out;
kv_out[map: kv_out];
map_accounts --> kv_out;
map_stat --> kv_out;
Expand All @@ -51,37 +51,37 @@ graph TD;

```yaml
Package name: eosio_token
Version: v0.9.0
Version: v0.10.0
Doc: Antelope `eosio.token` based action traces & database operations.
Modules:
----
Name: map_transfers
Initial block: 0
Kind: map
Output Type: proto:antelope.eosio.token.v1.TransferEvents
Hash: e832d395d7c4ad888f045ffe08fd3fa6952b5598
Hash: d331e4b9f5d02495638bd6e8caa638a6a8e56740

Name: map_accounts
Initial block: 0
Kind: map
Output Type: proto:antelope.eosio.token.v1.Accounts
Hash: 92884539c7ceb7107b48965b48da26fabd6b96a5
Hash: b75af7789f4a7055b166c9ca61deca146f4ef23e

Name: map_stat
Initial block: 0
Kind: map
Output Type: proto:antelope.eosio.token.v1.Stats
Hash: 61356dd96ff90b2f8bc32c28e1e6e57c268c0175
Hash: 1adb9207a8728f7707ee6a70541c6525ba8c1b64

Name: db_out
Name: graph_out
Initial block: 0
Kind: map
Output Type: proto:sf.substreams.sink.database.v1.DatabaseChanges
Hash: a63bf736a39ac384ef038d92961ade52b90c5908
Output Type: proto:substreams.entity.v1.EntityChanges
Hash: 10fe3d0d70d4794af36a03cd67d55a428e40f21d

Name: kv_out
Initial block: 0
Kind: map
Output Type: proto:sf.substreams.sink.kv.v1.KVOperations
Hash: 785658f5d1ffc6857196a7e1619ba138f46afd3e
Hash: f0e646700ff89e5eb89e5708a4c63685ef5fad9e
```
36 changes: 16 additions & 20 deletions eosio.token/src/sinks.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
use antelope::Asset;
use substreams::errors::Error;
use substreams_database_change::pb::database::{table_change::Operation, DatabaseChanges};
use substreams_entity_change::pb::entity::{entity_change::Operation, EntityChanges};
use substreams_sink_kv::pb::sf::substreams::sink::kv::v1::KvOperations;

use crate::eosio_token::{Accounts, Stats, TransferEvents};

#[substreams::handlers::map]
pub fn db_out(map_transfers: TransferEvents) -> Result<DatabaseChanges, Error> {
let mut db_out = DatabaseChanges::default();
pub fn graph_out(map_transfers: TransferEvents) -> Result<EntityChanges, Error> {
let mut entity_changes: EntityChanges = Default::default();

for transfer in map_transfers.items {
let pk = format!("{}-{}", transfer.trx_id, transfer.action_ordinal);
db_out
.push_change("transfer", pk.as_str(), 0, Operation::Create)
entity_changes
.push_change("transfer", transfer.trx_id.as_str(), 0, Operation::Create)
// transaction
.change("trx_id", ("", transfer.trx_id.as_str()))
.change(
"action_ordinal",
("", transfer.action_ordinal.to_string().as_str()),
)
.change("trx_id", transfer.trx_id)
.change("action_ordinal", transfer.action_ordinal.to_string())
// contract & scope
.change("contract", ("", transfer.contract.as_str()))
.change("symcode", ("", transfer.symcode.as_str()))
.change("contract", transfer.contract)
.change("symcode", transfer.symcode)
// data payload
.change("from", ("", transfer.from.as_str()))
.change("to", ("", transfer.to.as_str()))
.change("memo", ("", transfer.memo.as_str()))
.change("quantity", ("", transfer.quantity.as_str()))
.change("from", transfer.from)
.change("to", transfer.to)
.change("memo", transfer.memo)
.change("quantity", transfer.quantity)
// extras
.change("amount", ("", transfer.amount.to_string().as_str()))
.change("precision", ("", transfer.precision.to_string().as_str()));
.change("amount", transfer.amount.to_string())
.change("precision", transfer.precision.to_string());
}

Ok(db_out)
Ok(entity_changes)
}

#[substreams::handlers::map]
Expand Down
8 changes: 4 additions & 4 deletions eosio.token/substreams.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
specVersion: v0.1.0
package:
name: eosio_token
version: v0.9.0
version: v0.10.0
url: https://github.com/pinax-network/substreams
doc: Antelope `eosio.token` based action traces & database operations.

imports:
winston: https://github.com/pinax-network/substreams-sink-winston/releases/download/v0.1.2/substreams-sink-winston-v0.1.2.spkg
database_change: https://github.com/streamingfast/substreams-database-change/releases/download/v1.0.0/substreams-database-change-v1.0.0.spkg
entities: https://github.com/streamingfast/substreams-entity-change/releases/download/v0.2.1/substreams-entity-change-v0.2.1.spkg
kv: https://github.com/streamingfast/substreams-sink-kv/releases/download/v0.1.2/substreams-sink-kv-v0.1.2.spkg

binaries:
Expand Down Expand Up @@ -44,12 +44,12 @@ modules:
output:
type: proto:antelope.eosio.token.v1.Stats

- name: db_out
- name: graph_out
kind: map
inputs:
- map: map_transfers
output:
type: proto:sf.substreams.sink.database.v1.DatabaseChanges
type: proto:substreams.entity.v1.EntityChanges

- name: kv_out
kind: map
Expand Down

0 comments on commit 9a057d3

Please sign in to comment.