Skip to content

Commit

Permalink
rename Raw imports
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Nov 19, 2024
1 parent 4758358 commit b43648f
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 263 deletions.
14 changes: 14 additions & 0 deletions blocks/evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- [x] **Gas Changes**
- [x] **Nonce Changes**

## Graph

```mermaid
graph TD;
raw[sf.ethereum.type.v2.Block];
Expand All @@ -33,3 +35,15 @@ graph TD;
extended --> gas_changes;
extended --> nonce_changes;
```

## Modules

```bash
Name: map_events
Initial block: 0
Kind: map
Input: source: sf.substreams.v1.Clock
Input: source: sf.ethereum.type.v2.Block
Output Type: proto:evm.Events
Hash: e9a39ec8c7084a493d9a9f60c1f2f5d18f7505ad
```
10 changes: 5 additions & 5 deletions blocks/evm/src/account_creations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use common::utils::bytes_to_hex;

use substreams_ethereum::pb::eth::v2::Block;

use crate::pb::evm::AccountCreation as RawAccountCreation;
use crate::pb::evm::AccountCreation;

// https://github.com/streamingfast/firehose-ethereum/blob/1bcb32a8eb3e43347972b6b5c9b1fcc4a08c751e/proto/sf/ethereum/type/v2/type.proto#L736
// DetailLevel: EXTENDED
pub fn collect_account_creations(block: &Block, timestamp: &BlockTimestamp) -> Vec<RawAccountCreation> {
let mut account_creations: Vec<RawAccountCreation> = vec![];
pub fn collect_account_creations(block: &Block, timestamp: &BlockTimestamp) -> Vec<AccountCreation> {
let mut account_creations: Vec<AccountCreation> = vec![];

// Collect account creations from system calls
for call in &block.system_calls {
for account_creation in &call.account_creations {
account_creations.push(RawAccountCreation {
account_creations.push(AccountCreation {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand All @@ -28,7 +28,7 @@ pub fn collect_account_creations(block: &Block, timestamp: &BlockTimestamp) -> V
for transaction in &block.transaction_traces {
for call in &transaction.calls {
for account_creation in &call.account_creations {
account_creations.push(RawAccountCreation {
account_creations.push(AccountCreation {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand Down
10 changes: 5 additions & 5 deletions blocks/evm/src/balance_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use common::utils::optional_bigint_to_string;
use common::utils::{bytes_to_hex, optional_bigint_to_decimal};
use substreams_ethereum::pb::eth::v2::Block;

use crate::pb::evm::BalanceChange as RawBalanceChange;
use crate::pb::evm::BalanceChange;

pub fn balance_change_reason_to_string(reason: i32) -> String {
match reason {
Expand Down Expand Up @@ -35,14 +35,14 @@ pub fn balance_change_reason_to_string(reason: i32) -> String {

// https://github.com/streamingfast/firehose-ethereum/blob/1bcb32a8eb3e43347972b6b5c9b1fcc4a08c751e/proto/sf/ethereum/type/v2/type.proto#L658
// DetailLevel: EXTENDED
pub fn collect_balance_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<RawBalanceChange> {
let mut balance_changes: Vec<RawBalanceChange> = vec![];
pub fn collect_balance_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<BalanceChange> {
let mut balance_changes: Vec<BalanceChange> = vec![];

// Collect balance changes from system calls
for call in &block.system_calls {
for balance_change in &call.balance_changes {
let amount = optional_bigint_to_decimal(balance_change.new_value.clone()) - optional_bigint_to_decimal(balance_change.old_value.clone());
balance_changes.push(RawBalanceChange {
balance_changes.push(BalanceChange {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand All @@ -63,7 +63,7 @@ pub fn collect_balance_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec
for call in &transaction.calls {
for balance_change in &call.balance_changes {
let amount = optional_bigint_to_decimal(balance_change.new_value.clone()) - optional_bigint_to_decimal(balance_change.old_value.clone());
balance_changes.push(RawBalanceChange {
balance_changes.push(BalanceChange {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand Down
6 changes: 3 additions & 3 deletions blocks/evm/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use common::utils::{bytes_to_hex, optional_bigint_to_u64, optional_u64_to_string

use substreams_ethereum::pb::eth::v2::Block;

use crate::pb::evm::Block as RawBlock;
use crate::pb::evm::Block as BlockHeader;

pub fn block_detail_to_string(detail_level: i32) -> String {
match detail_level {
Expand All @@ -17,15 +17,15 @@ pub fn block_detail_to_string(detail_level: i32) -> String {

// https://github.com/streamingfast/firehose-ethereum/blob/develop/proto/sf/ethereum/type/v2/type.proto
// DetailLevel: BASE
pub fn collect_block(block: &Block, timestamp: &BlockTimestamp) -> RawBlock {
pub fn collect_block(block: &Block, timestamp: &BlockTimestamp) -> BlockHeader {
let header = block.header.as_ref().unwrap();

let total_transactions = block.transaction_traces.len() as u64;
let successful_transactions = block.transaction_traces.iter().filter(|t| t.status == 1).count() as u64;
let failed_transactions = total_transactions - successful_transactions;
let total_withdrawals = block.balance_changes.iter().filter(|t| t.reason == 16).count() as u64;

RawBlock {
BlockHeader {
time: Some(timestamp.time),
number: header.number,
date: timestamp.date.clone(),
Expand Down
10 changes: 5 additions & 5 deletions blocks/evm/src/code_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use common::structs::BlockTimestamp;
use common::utils::bytes_to_hex;
use substreams_ethereum::pb::eth::v2::Block;

use crate::pb::evm::CodeChange as RawCodeChange;
use crate::pb::evm::CodeChange;

// https://github.com/streamingfast/firehose-ethereum/blob/1bcb32a8eb3e43347972b6b5c9b1fcc4a08c751e/proto/sf/ethereum/type/v2/type.proto#L744
// DetailLevel: EXTENDED
pub fn collect_code_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<RawCodeChange> {
let mut code_changes: Vec<RawCodeChange> = vec![];
pub fn collect_code_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<CodeChange> {
let mut code_changes: Vec<CodeChange> = vec![];

// Collect code changes from system calls
for call in &block.system_calls {
for code_change in &call.code_changes {
code_changes.push(RawCodeChange {
code_changes.push(CodeChange {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand All @@ -31,7 +31,7 @@ pub fn collect_code_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<Ra
for transaction in &block.transaction_traces {
for call in &transaction.calls {
for code_change in &call.code_changes {
code_changes.push(RawCodeChange {
code_changes.push(CodeChange {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand Down
10 changes: 5 additions & 5 deletions blocks/evm/src/gas_changes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use common::structs::BlockTimestamp;
use substreams_ethereum::pb::eth::v2::Block;

use crate::pb::evm::GasChange as RawGasChange;
use crate::pb::evm::GasChange;

pub fn gas_change_reason_to_string(reason: i32) -> String {
match reason {
Expand Down Expand Up @@ -37,13 +37,13 @@ pub fn gas_change_reason_to_string(reason: i32) -> String {

// https://github.com/streamingfast/firehose-ethereum/blob/1bcb32a8eb3e43347972b6b5c9b1fcc4a08c751e/proto/sf/ethereum/type/v2/type.proto#L726C9-L726C20
// DetailLevel: EXTENDED
pub fn collect_gas_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<RawGasChange> {
let mut gas_changes: Vec<RawGasChange> = vec![];
pub fn collect_gas_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<GasChange> {
let mut gas_changes: Vec<GasChange> = vec![];

// Collect gas changes from system calls
for call in &block.system_calls {
for gas_change in &call.gas_changes {
gas_changes.push(RawGasChange {
gas_changes.push(GasChange {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand All @@ -61,7 +61,7 @@ pub fn collect_gas_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<Raw
for transaction in &block.transaction_traces {
for call in &transaction.calls {
for gas_change in &call.gas_changes {
gas_changes.push(RawGasChange {
gas_changes.push(GasChange {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand Down
8 changes: 4 additions & 4 deletions blocks/evm/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ use common::structs::BlockTimestamp;
use common::utils::{bytes_to_hex, extract_topic};
use substreams_ethereum::pb::eth::v2::Block;

use crate::pb::evm::Log as RawLog;
use crate::pb::evm::Log;
use crate::transactions::{is_transaction_success, transaction_status_to_string};

// https://github.com/streamingfast/firehose-ethereum/blob/1bcb32a8eb3e43347972b6b5c9b1fcc4a08c751e/proto/sf/ethereum/type/v2/type.proto#L512
// DetailLevel: BASE (only successful transactions) & EXTENDED
pub fn collect_logs(block: &Block, timestamp: &BlockTimestamp, detail_level: &str) -> Vec<RawLog> {
pub fn collect_logs(block: &Block, timestamp: &BlockTimestamp, detail_level: &str) -> Vec<Log> {
// Only required DetailLevel=BASE since traces are not available in BASE
if detail_level == "Base" {
return vec![];
}

let mut logs: Vec<RawLog> = vec![];
let mut logs: Vec<Log> = vec![];

for transaction in &block.transaction_traces {
let receipt = transaction.receipt.as_ref().unwrap();
for log in &receipt.logs {
logs.push(RawLog {
logs.push(Log {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand Down
10 changes: 5 additions & 5 deletions blocks/evm/src/nonce_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use common::structs::BlockTimestamp;
use common::utils::bytes_to_hex;
use substreams_ethereum::pb::eth::v2::Block;

use crate::pb::evm::NonceChange as RawNonceChange;
use crate::pb::evm::NonceChange;

// https://github.com/streamingfast/firehose-ethereum/blob/1bcb32a8eb3e43347972b6b5c9b1fcc4a08c751e/proto/sf/ethereum/type/v2/type.proto#L726C9-L726C20
// DetailLevel: EXTENDED
pub fn collect_nonce_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<RawNonceChange> {
let mut nonce_changes: Vec<RawNonceChange> = vec![];
pub fn collect_nonce_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<NonceChange> {
let mut nonce_changes: Vec<NonceChange> = vec![];

// Collect nonce changes from system calls
for call in &block.system_calls {
for nonce_change in &call.nonce_changes {
nonce_changes.push(RawNonceChange {
nonce_changes.push(NonceChange {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand All @@ -29,7 +29,7 @@ pub fn collect_nonce_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<R
for transaction in &block.transaction_traces {
for call in &transaction.calls {
for nonce_change in &call.nonce_changes {
nonce_changes.push(RawNonceChange {
nonce_changes.push(NonceChange {
block_time: Some(timestamp.time),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
Expand Down
Loading

0 comments on commit b43648f

Please sign in to comment.