Skip to content

Commit

Permalink
Add default to number => string
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Aug 7, 2024
1 parent b562dfc commit 8c140c2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"

[workspace.package]
edition = "2021"
version = "0.1.1"
version = "0.1.2"

[workspace.dependencies]
substreams = "0.5"
Expand Down
4 changes: 2 additions & 2 deletions blocks/evm/src/balance_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub fn insert_block_balance_changes(tables: &mut DatabaseChanges, clock: &Clock,
// https://github.com/streamingfast/firehose-ethereum/blob/1bcb32a8eb3e43347972b6b5c9b1fcc4a08c751e/proto/sf/ethereum/type/v2/type.proto#L658
pub fn insert_balance_change(row: &mut TableChange, balance_change: &BalanceChange) {
let address = bytes_to_hex(balance_change.address.clone());
let new_value = optional_bigint_to_string(balance_change.new_value.clone());
let old_value = optional_bigint_to_string(balance_change.old_value.clone());
let new_value = optional_bigint_to_string(balance_change.new_value.clone(), "0");
let old_value = optional_bigint_to_string(balance_change.old_value.clone(), "0");
let delta_value = optional_bigint_to_decimal(balance_change.new_value.clone()) - optional_bigint_to_decimal(balance_change.old_value.clone());
let ordinal = balance_change.ordinal;
let reason_code = balance_change.reason;
Expand Down
16 changes: 9 additions & 7 deletions blocks/evm/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ pub fn insert_blocks(tables: &mut DatabaseChanges, clock: &Clock, block: &Block)
let extra_data_utf8 = String::from_utf8(header.extra_data).unwrap_or_default();
let gas_limit = header.gas_limit;
let gas_used = header.gas_used;
let withdrawals_root = bytes_to_hex(header.withdrawals_root);
let parent_beacon_root = bytes_to_hex(header.parent_beacon_root);

let difficulty = optional_bigint_to_string(header.difficulty);
let total_difficulty = optional_bigint_to_string(header.total_difficulty.clone()); // UInt256
let base_fee_per_gas = optional_bigint_to_string(header.base_fee_per_gas); // UInt256
let excess_blob_gas = optional_u64_to_string(header.excess_blob_gas); // uint64
let blob_gas_used = optional_u64_to_string(header.blob_gas_used); // uint64
let difficulty = optional_bigint_to_string(header.difficulty, "0"); // UInt64
let total_difficulty = optional_bigint_to_string(header.total_difficulty.clone(), "0"); // UInt256

// forks
let withdrawals_root = bytes_to_hex(header.withdrawals_root); // EIP-4895 (Shangai Fork)
let parent_beacon_root = bytes_to_hex(header.parent_beacon_root); // EIP-4788 (Dencun Fork)
let base_fee_per_gas = optional_bigint_to_string(header.base_fee_per_gas, ""); // UInt256 - EIP-1559 (London Fork)
let excess_blob_gas = optional_u64_to_string(header.excess_blob_gas, ""); // UInt64 - EIP-4844 (Dencun Fork)
let blob_gas_used = optional_u64_to_string(header.blob_gas_used, ""); // UInt64 - EIP-4844 (Dencun Fork)

// blocks
let keys = blocks_keys(&clock, true);
Expand Down
2 changes: 1 addition & 1 deletion blocks/evm/src/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn insert_trace(tables: &mut DatabaseChanges, clock: &Clock, call: &Call, tr
let status_failed = call.status_failed;
let status_reverted = call.status_reverted;
let suicide = call.suicide; // or `selfdestruct`?
let value = optional_bigint_to_string(call.value.clone()); // UInt256
let value = optional_bigint_to_string(call.value.clone(), "0"); // UInt256

let keys = traces_keys(&clock, &tx_hash, &tx_index, &index);
let row = tables
Expand Down
8 changes: 4 additions & 4 deletions blocks/evm/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ pub fn insert_transaction(tables: &mut DatabaseChanges, clock: &Clock, transacti
let from = bytes_to_hex(transaction.from.clone()); // EVM Address
let to = bytes_to_hex(transaction.to.clone()); // EVM Address
let nonce = transaction.nonce;
let gas_price = optional_bigint_to_string(transaction.gas_price.clone()); // UInt256
let gas_price = optional_bigint_to_string(transaction.gas_price.clone(), "0"); // UInt256
let gas_limit = transaction.gas_limit;
let value = optional_bigint_to_string(transaction.value.clone()); // UInt256
let value = optional_bigint_to_string(transaction.value.clone(), "0"); // UInt256
let input = bytes_to_hex(transaction.input.clone());
let v = bytes_to_hex(transaction.v.clone());
let r = bytes_to_hex(transaction.r.clone());
let s = bytes_to_hex(transaction.s.clone());
let gas_used = transaction.gas_used;
let r#type = transaction_type_to_string(transaction.r#type);
let type_code = transaction.r#type;
let max_fee_per_gas = optional_bigint_to_string(transaction.max_fee_per_gas.clone()); // UInt256
let max_priority_fee_per_gas = optional_bigint_to_string(transaction.max_priority_fee_per_gas.clone()); // UInt256
let max_fee_per_gas = optional_bigint_to_string(transaction.max_fee_per_gas.clone(), "0"); // UInt256
let max_priority_fee_per_gas = optional_bigint_to_string(transaction.max_priority_fee_per_gas.clone(), "0"); // UInt256
let return_data = bytes_to_hex(transaction.return_data.clone()); // TO-CHECK: empty on ETH
let public_key = bytes_to_hex(transaction.public_key.clone()); // TO-CHECK: empty on ETH
let begin_ordinal = transaction.begin_ordinal;
Expand Down
2 changes: 1 addition & 1 deletion blocks/evm/substreams.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
specVersion: v0.1.0
package:
name: raw_blocks_evm
version: v0.1.1
version: v0.1.2
url: https://github.com/pinax-network/substreams-raw-blocks
doc: Raw Blocks for EVM

Expand Down
8 changes: 4 additions & 4 deletions common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ pub fn bytes_to_hex(bytes: Vec<u8>) -> String {
}
}

pub fn optional_bigint_to_string(value: Option<BigInt>) -> String {
pub fn optional_bigint_to_string(value: Option<BigInt>, default: &str) -> String {
match value {
Some(bigint) => bigint.with_decimal(0).to_string(),
None => "".to_string(),
None => default.to_string(),
}
}

Expand All @@ -39,10 +39,10 @@ pub fn optional_bigint_to_hex(value: Option<BigInt>) -> String {
}
}

pub fn optional_u64_to_string(value: Option<u64>) -> String {
pub fn optional_u64_to_string(value: Option<u64>, default: &str) -> String {
match value {
Some(uint) => uint.to_string(),
None => "".to_string(),
None => default.to_string(),
}
}

Expand Down

0 comments on commit 8c140c2

Please sign in to comment.