Skip to content

Commit

Permalink
add back version
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Mar 5, 2025
1 parent e7c4e0f commit a2442e0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
7 changes: 1 addition & 6 deletions clickhouse/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ CREATE TABLE IF NOT EXISTS balance_changes (
old_balance UInt256,
new_balance UInt256,

-- transfer --
`from` FixedString(40),
`to` FixedString(40),
value UInt256,

-- indexing --
version UInt64,
version UInt64, -- latest version of the balance change (block_num << 32 + storage_ordinal)

-- debug --
balance_change_type Int32
Expand Down
6 changes: 1 addition & 5 deletions clickhouse/src/db_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ pub fn db_out(events: Events) -> Result<DatabaseChanges, Error> {
.set("owner", balance_change.owner)
.set("old_balance", balance_change.old_balance)
.set("new_balance", balance_change.new_balance)
// -- transfer --
.set("from", balance_change.from)
.set("to", balance_change.to)
.set("value", balance_change.value)
// -- indexing --
.set("version", balance_change.version.to_string())
.set("version", balance_change.version)
// -- debug --
.set("balance_change_type", balance_change.balance_change_type.to_string());
}
Expand Down
2 changes: 1 addition & 1 deletion erc20-balances-transfers/src/algorithms/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn get_keccak_address<'a>(keccak_address_map: &'a HashMap<Hash, Address>, st
let keccak_address = keccak_address_map.get(&storage_change.key);
match keccak_address {
Some(address) => Some(address.clone()),
None => {
_ => {
log::info!("storage change does not match any owner address key={}", Hex(&storage_change.key));
None
}
Expand Down
6 changes: 4 additions & 2 deletions erc20-balances-transfers/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pub fn to_balance_change<'a>(
trx: &'a TransactionTrace,
call: &'a Call,
log: &'a Log,
transfer: &'a TransferAbi,
owner: Address,
storage_change: &'a StorageChange,
change_type: BalanceChangeType,
Expand Down Expand Up @@ -95,6 +94,9 @@ pub fn to_balance_change<'a>(
old_balance: old_balance.to_string(),
new_balance: new_balance.to_string(),

// -- indexing --
version: index_to_version(clock, storage_change),

// -- debug --
balance_change_type: change_type as i32,
}
Expand Down Expand Up @@ -128,7 +130,7 @@ pub fn insert_events<'a>(clock: &'a Clock, block: &'a Block, events: &mut Events
keccak_address_map.extend(addresses_for_storage_keys(call)); // memoize
let balance_changes = iter_balance_changes_algorithms(trx, call, &transfer, &keccak_address_map);
for (owner, storage_change, change_type) in balance_changes {
let balance_change = to_balance_change(clock, trx, call, log, &transfer, owner, storage_change, change_type);
let balance_change = to_balance_change(clock, trx, call, log, owner, storage_change, change_type);

// insert balance change event
events.balance_changes.push(balance_change);
Expand Down
5 changes: 5 additions & 0 deletions erc20-balances-transfers/src/pb/erc20.types.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ pub struct BalanceChange {
pub old_balance: ::prost::alloc::string::String,
#[prost(string, tag="23")]
pub new_balance: ::prost::alloc::string::String,
/// -- indexing --
///
/// latest version of the balance change (block_num << 32 + storage_ordinal)
#[prost(uint64, tag="30")]
pub version: u64,
/// -- debug --
///
/// type enum isn't supported yet as a leaf node
Expand Down
2 changes: 1 addition & 1 deletion erc20-balances-transfers/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use substreams_ethereum::pb::eth::v2::StorageChange;
pub fn clock_to_date(clock: &Clock) -> String {
match clock.timestamp.expect("timestamp missing").to_string().split('T').next() {
Some(date) => date.to_string(),
None => "".to_string(),
_ => "".to_string(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions proto/v1/erc20.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ message BalanceChange {
string old_balance = 22;
string new_balance = 23;

// -- indexing --
uint64 version = 30; // latest version of the balance change (block_num << 32 + storage_ordinal)

// -- debug --
int32 balance_change_type = 99; // type enum isn't supported yet as a leaf node
}
Expand Down

0 comments on commit a2442e0

Please sign in to comment.