Skip to content

Commit

Permalink
Update schema
Browse files Browse the repository at this point in the history
ref: #1
  • Loading branch information
DenisCarriere committed Aug 17, 2024
1 parent 141ee47 commit 7fad07a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
3 changes: 1 addition & 2 deletions blocks/evm/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ CREATE TABLE IF NOT EXISTS transactions
gas_price DEFAULT '' COMMENT 'UInt256',
gas_limit UInt64,
value DEFAULT '' COMMENT 'UInt256',
input String,
data String,
v String,
r String COMMENT 'EVM Hash',
s String COMMENT 'EVM Hash',
Expand Down Expand Up @@ -294,7 +294,6 @@ CREATE TABLE IF NOT EXISTS gas_changes
ordinal UInt64 COMMENT 'Block global ordinal',
old_value UInt64,
new_value UInt64,
delta_value String DEFAULT '' COMMENT 'Int128',
reason LowCardinality(String),
reason_code UInt32,
)
Expand Down
2 changes: 1 addition & 1 deletion blocks/evm/src/balance_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn balance_change_reason_to_string(reason: i32) -> String {
pub fn insert_balance_change_row(row: &mut TableChange, balance_change: &BalanceChange) {
let address = bytes_to_hex(&balance_change.address);
let new_balance = optional_bigint_to_string(balance_change.new_value.clone(), "0");
let old_balance = optional_bigint_to_string(balance_change.old_value.clone(), "0");
let old_balance: String = optional_bigint_to_string(balance_change.old_value.clone(), "0");
let amount = 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
3 changes: 0 additions & 3 deletions blocks/evm/src/gas_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ pub fn gas_change_reason_to_string(reason: i32) -> String {
pub fn insert_gas_change(tables: &mut DatabaseChanges, clock: &Clock, gas_change: &GasChange) {
let old_value = gas_change.old_value;
let new_value = gas_change.new_value;
let delta_value = new_value as i128 - old_value as i128;

let reason = gas_change_reason_to_string(gas_change.reason);
let reason_code = gas_change.reason;
let ordinal = gas_change.ordinal;
Expand All @@ -54,7 +52,6 @@ pub fn insert_gas_change(tables: &mut DatabaseChanges, clock: &Clock, gas_change
.change("reason_code", ("", reason_code.to_string().as_str()))
.change("old_value", ("", old_value.to_string().as_str()))
.change("new_value", ("", new_value.to_string().as_str()))
.change("delta_value", ("", delta_value.to_string().as_str()))
.change("ordinal", ("", ordinal.to_string().as_str()));

insert_timestamp(row, clock, false);
Expand Down
4 changes: 4 additions & 0 deletions blocks/evm/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub fn insert_log(tables: &mut DatabaseChanges, clock: &Clock, log: &Log, transa
let topic3 = extract_topic(&topics, 3);
let data = bytes_to_hex(&log.data.to_vec());

// Missing
// - blob_gas_price
// - blob_gas_used

let keys = logs_keys(&clock, &tx_hash, &index);
let row = tables
.push_change_composite("logs", keys, 0, table_change::Operation::Create)
Expand Down
8 changes: 6 additions & 2 deletions blocks/evm/src/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ pub fn insert_trace_row(row: &mut TableChange, call: &Call) {
let executed_code = call.executed_code;
let gas_consumed = call.gas_consumed;
let gas_limit = call.gas_limit;
let index = call.index; // or `subtraces`?
let input = bytes_to_hex(&call.input);
let index = call.index; // or `sub_traces`?
let input = bytes_to_hex(&call.input); // TO-DO: fallback to 0x?
let parent_index = call.parent_index;
let state_reverted = call.state_reverted;
let status_failed = call.status_failed;
Expand All @@ -104,6 +104,10 @@ pub fn insert_trace_row(row: &mut TableChange, call: &Call) {
let failure_reason = &call.failure_reason;
let return_data = bytes_to_hex(&call.return_data);

// missing?
// - output
// - refund_address

row.change("address", ("", address.as_str()))
.change("begin_ordinal", ("", begin_ordinal.to_string().as_str()))
.change("call_type", ("", call_type.as_str()))
Expand Down
4 changes: 2 additions & 2 deletions blocks/evm/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn insert_transaction(tables: &mut DatabaseChanges, clock: &Clock, transacti
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(), "0"); // UInt256
let input = bytes_to_hex(&transaction.input); // TO-DO: change to 0x? rename to `data`? https://github.com/pinax-network/substreams-raw-blocks/issues/1
let data = bytes_to_hex(&transaction.input); // TO-DO: change to 0x? https://github.com/pinax-network/substreams-raw-blocks/issues/1
let v = bytes_to_hex(&transaction.v);
let r = bytes_to_hex(&transaction.r);
let s = bytes_to_hex(&transaction.s);
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn insert_transaction(tables: &mut DatabaseChanges, clock: &Clock, transacti
.change("gas_price", ("", gas_price.to_string().as_str()))
.change("gas_limit", ("", gas_limit.to_string().as_str()))
.change("value", ("", value.as_str()))
.change("input", ("", input.as_str()))
.change("data", ("", data.as_str()))
.change("v", ("", v.as_str()))
.change("r", ("", r.as_str()))
.change("s", ("", s.as_str()))
Expand Down

0 comments on commit 7fad07a

Please sign in to comment.