Skip to content

Commit

Permalink
add method for getting storage changes after a snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
joonazan committed May 8, 2024
1 parent b3e07ec commit b9c2e44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/modified_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ impl ModifiedWorld {
self.storage_changes.as_ref()
}

pub fn get_storage_changes_after(
&self,
snapshot: &Snapshot,
) -> BTreeMap<(H160, U256), (Option<U256>, U256)> {
self.storage_changes.changes_after(snapshot.storage_changes)
}

pub(crate) fn record_event(&mut self, event: Event) {
self.events.push(event);
}
Expand Down
14 changes: 14 additions & 0 deletions src/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ impl<K: Ord + Clone, V: Clone> RollbackableMap<K, V> {
self.old_entries.push((key.clone(), old_value.clone()));
old_value
}

pub(crate) fn changes_after(
&self,
snapshot: <Self as Rollback>::Snapshot,
) -> BTreeMap<K, (Option<V>, V)> {
let mut changes = BTreeMap::new();
for (key, old_value) in self.old_entries[snapshot..].iter().rev() {
changes
.entry(key.clone())
.and_modify(|(old, _)| *old = old_value.clone())
.or_insert((old_value.clone(), self.map.get(key).unwrap().clone()));
}
changes
}
}

impl<K: Ord, V> Rollback for RollbackableMap<K, V> {
Expand Down

0 comments on commit b9c2e44

Please sign in to comment.