Description
Right now StorageTransaction
holds a &mut Storage
for the entire lifetime, although it only needs &ReadonlyStorage
until the final commit()
. https://github.com/confio/cosmwasm/blob/master/src/storage.rs#L5-L12
This is fine, but for query implementations we will want to hold multiple references to the pre-message snapshot. If StorageTransaction
took &Storage
, it would work the same until commit()
, and in the meantime, we can pass multiple &ReadonlyStorage
of the pre-message snapshot to other contracts to perform queries. The change to commit
would be something like:
impl StorageTransaction {
pub fn prepare(self) -> Commit { /* ... */ }
}
struct Commit {
rep_log: Vec<Op>,
}
impl Commit() {
pub fn commit(self, store: &mut Storage) {
// this would behave as current commit.
}
}
Usage would be something like this:
let mut subtx = StorageTransaction::new(&store);
subtx.set(b"foo", b"bar");
subtx.prepare().commit(&mut store)
Or maybe this if the borrow checker requires:
let mut subtx = StorageTransaction::new(&store);
subtx.set(b"foo", b"bar");
let ops = subtx.prepare() // this will release the `&store`
ops.commit(&mut store)