We use StorageTransaction::new(), a number of places to give us:
- ability to revert/commit changes written to a cache
- read-only access to an underlying snapshot and write access to a cache, which is needed for wasm execution (at least)
This is also called a number of places. I would simplify this by calling it primarily one place: Router.execute, which works like the "ante handler" transaction wrapper from the SDK. This also means any sub messages from WasmKeeper (which call into that) also are automatically transaction wrapped.
We can provide a helper method to make it cleaner. Something like:
as_transaction(&mut base_storage, |write_cache: &mut Storage, read_snapshot: &Storage| -> Result<T, String> {
});
It would wrap the base, return a cache and a read-only reference to base to the closure. Only on Ok, it will commit the cache to base, and it will return the Result from the closure to the caller.
We use
StorageTransaction::new(), a number of places to give us:This is also called a number of places. I would simplify this by calling it primarily one place:
Router.execute, which works like the "ante handler" transaction wrapper from the SDK. This also means any sub messages from WasmKeeper (which call into that) also are automatically transaction wrapped.We can provide a helper method to make it cleaner. Something like:
It would wrap the base, return a cache and a read-only reference to base to the closure. Only on
Ok, it will commit the cache to base, and it will return the Result from the closure to the caller.