fix: update get_block_storage_changes to correctly emit previous value (#280)
Before this commit we were using the latest `ContractSlot` for both previous and new value. This is not correct because if the value changed twice we would have the middle value emitted as "previous". For example if a value was changed like this in a single transaction 1 -> 10 -> 2 we would have `new_value=2` and `previous_values=10` while the previous value was actually 1. Co-authored-by: zizou <111426680+flopell@users.noreply.github.com>
This commit is contained in:
34
substreams/Cargo.lock
generated
34
substreams/Cargo.lock
generated
@@ -250,7 +250,7 @@ dependencies = [
|
||||
"num-bigint",
|
||||
"substreams",
|
||||
"substreams-ethereum",
|
||||
"tycho-substreams 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tycho-substreams 0.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1758,22 +1758,6 @@ dependencies = [
|
||||
"substreams-ethereum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tycho-substreams"
|
||||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"ethabi 18.0.0",
|
||||
"hex",
|
||||
"itertools 0.12.1",
|
||||
"num-bigint",
|
||||
"prost 0.11.9",
|
||||
"rstest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"substreams",
|
||||
"substreams-ethereum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tycho-substreams"
|
||||
version = "0.5.0"
|
||||
@@ -1791,6 +1775,22 @@ dependencies = [
|
||||
"substreams-ethereum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tycho-substreams"
|
||||
version = "0.5.1"
|
||||
dependencies = [
|
||||
"ethabi 18.0.0",
|
||||
"hex",
|
||||
"itertools 0.12.1",
|
||||
"num-bigint",
|
||||
"prost 0.11.9",
|
||||
"rstest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"substreams",
|
||||
"substreams-ethereum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.17.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tycho-substreams"
|
||||
version = "0.5.0"
|
||||
version = "0.5.1"
|
||||
edition = "2021"
|
||||
description = "Tycho substreams development kit, contains tycho-indexer block changes model and helper functions for common indexing tasks."
|
||||
repository = "https://github.com/propeller-heads/tycho-protocol-sdk/tree/main/substreams/crates/tycho-substreams"
|
||||
|
||||
@@ -54,14 +54,18 @@ pub fn get_block_storage_changes(block: ð::v2::Block) -> Vec<TransactionStora
|
||||
// Collect latest change per slot
|
||||
let mut latest_changes: HashMap<Vec<u8>, ContractSlot> = HashMap::new();
|
||||
for change in changes {
|
||||
latest_changes.insert(
|
||||
change.key.clone(),
|
||||
ContractSlot {
|
||||
latest_changes
|
||||
.entry(change.key.clone())
|
||||
.and_modify(|slot| {
|
||||
// Only update the latest value, previous value stays the first seen
|
||||
// one.
|
||||
slot.value = change.new_value.clone();
|
||||
})
|
||||
.or_insert(ContractSlot {
|
||||
slot: change.key,
|
||||
value: change.new_value,
|
||||
previous_value: change.old_value,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
StorageChanges { address, slots: latest_changes.into_values().collect() }
|
||||
|
||||
Reference in New Issue
Block a user