Skip to content

Commit

Permalink
implement newaccount decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroShkvorets committed Mar 7, 2023
1 parent c6ebb7f commit 5340826
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion accounts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ info:

.PHONY: run
run:
substreams run -e eos.firehose.eosnation.io:9001 map_accounts -s 1000000 -t +10000 -o jsonl
substreams run -e eos.firehose.eosnation.io:9001 map_accounts -s 1000026 -t +1

.PHONY: gui
gui:
Expand Down
3 changes: 2 additions & 1 deletion accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
mod accounts;
mod abi;
mod maps;
mod sinks;
mod sinks;
mod utils;
35 changes: 16 additions & 19 deletions accounts/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use substreams::errors::Error;
use substreams_antelope::Block;

use crate::abi;
use crate::accounts::{Accounts, Account, Creator, Authority};
use crate::accounts;

/// Extracts new account events from the contract
#[substreams::handlers::map]
fn map_accounts(block: Block) -> Result<Accounts, Error> {
fn map_accounts(block: Block) -> Result<accounts::Accounts, Error> {
let mut accounts = vec![];

for trx in block.clone().all_transaction_traces() {
Expand All @@ -18,31 +18,28 @@ fn map_accounts(block: Block) -> Result<Accounts, Error> {
if action.account == "eosio" && action.name == "newaccount" {
if let Ok(params) = action.json_data.parse::<abi::NewAccount>() {
log::debug!("newaccount={:?}", params);
let creator = Some(Creator::default()); // TO-DO

accounts.push(Account {
// action details
creator,
let creator = accounts::Creator {
creator: params.creator.clone(),
service: None,
authorizations: vec![],
};
let owner = accounts::Authority::from(params.owner);
let active = accounts::Authority::from(params.active);
accounts.push(accounts::Account {
creator: Some(creator),
name: params.name,
owner: Some(Authority::default()), // TO-DO
active: Some(Authority::default()), // TO-DO

// transaction details
owner: Some(owner),
active: Some(active),
timestamp: block.header.as_ref().unwrap().timestamp.clone(),
trx_id: trace.transaction_id.clone(),
block_num: block.number,

// account details
ram_bytes: 0, // will be updated later
stake_net_quantity: 0, // will be updated later
stake_cpu_quantity: 0, // will be updated later
transfer: false, // will be updated later
..Default::default()
});
}
}

// parse buy RAM actions (normally one transaction per new account created)
// TODO: instead, get the RAM usage from dbOps (this will also cover buyram)
// TODO: instead, get the RAM usage and CPU/NET staked from dbOps (this will also cover buyram) BLOCKED: need to replay the blockchain to get decoded JSONs for dbOps
if action.account == "eosio" && action.name == "buyrambytes" {
if let Ok(params) = action.json_data.parse::<abi::BuyRamBytes>() {
if let Some(last) = accounts.last_mut() {
Expand All @@ -55,5 +52,5 @@ fn map_accounts(block: Block) -> Result<Accounts, Error> {
}
}
}
Ok(Accounts { accounts })
Ok(accounts::Accounts { accounts })
}
26 changes: 26 additions & 0 deletions accounts/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

use crate::accounts;
use crate::abi;

impl From<abi::Authority> for accounts::Authority {
fn from(authority: abi::Authority) -> Self {
accounts::Authority {
threshold: authority.threshold,
keys: authority.keys.iter().map(|kw| accounts::KeyWeight {
public_key: kw.key.clone(),
weight: kw.weight as u32,
}).collect(),
accounts: authority.accounts.iter().map(|plw| accounts::PermissionLevelWeight {
permission: Some(accounts::PermissionLevel {
actor: plw.permission.account.clone(),
permission: plw.permission.permission.clone(),
}),
weight: plw.weight as u32,
}).collect(),
waits: authority.waits.iter().map(|ww| accounts::WaitWeight {
wait_sec: ww.wait_sec,
weight: ww.weight as u32,
}).collect(),
}
}
}
2 changes: 1 addition & 1 deletion accounts/substreams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package:

imports:
kv: https://github.com/streamingfast/substreams-sink-kv/releases/download/v0.1.2/substreams-sink-kv-v0.1.2.spkg
prom: https://github.com/pinax-network/substreams-sink-prometheus/releases/download/v0.1.8/substreams-sink-prometheus-v0.1.8.spkg
prom: https://github.com/pinax-network/substreams-sink-prometheus.rs/releases/download/v0.1.9/substreams-sink-prometheus-v0.1.9.spkg

protobuf:
files:
Expand Down

0 comments on commit 5340826

Please sign in to comment.