@@ -119,8 +119,8 @@ export class WasmModule {
119119 ) ;
120120 }
121121
122- getContractStorage ( contractAddress : string ) {
123- const existing = this . chain . store . getIn ( [
122+ getContractStorage ( contractAddress : string , storage = this . chain . store ) {
123+ const existing = storage . getIn ( [
124124 'wasm' ,
125125 'contractStorage' ,
126126 contractAddress ,
@@ -135,8 +135,8 @@ export class WasmModule {
135135 ) ;
136136 }
137137
138- getCodeInfo ( codeId : number ) : CodeInfo {
139- return this . chain . store . getIn ( [ 'wasm' , 'codes' , codeId ] ) as CodeInfo ;
138+ getCodeInfo ( codeId : number , storage = this . chain . store ) : CodeInfo {
139+ return storage . getIn ( [ 'wasm' , 'codes' , codeId ] ) as CodeInfo ;
140140 }
141141
142142 setContractInfo ( contractAddress : string , contractInfo : ContractInfo ) {
@@ -146,8 +146,8 @@ export class WasmModule {
146146 ) ;
147147 }
148148
149- getContractInfo ( contractAddress : string ) {
150- return this . chain . store . getIn ( [
149+ getContractInfo ( contractAddress : string , storage = this . chain . store ) {
150+ return storage . getIn ( [
151151 'wasm' ,
152152 'contracts' ,
153153 contractAddress ,
@@ -637,6 +637,31 @@ export class WasmModule {
637637 return fromRustResult ( vm . query ( env , queryMsg ) . json as RustResult < string > )
638638 . andThen ( v => Ok ( fromBinary ( v ) ) ) ;
639639 }
640+
641+ queryTrace (
642+ trace : TraceLog ,
643+ queryMsg : any ,
644+ ) : Result < any , string > {
645+ let { contractAddress, storeSnapshot } = trace ;
646+ let vm = this . vms [ contractAddress ] ;
647+ if ( ! vm ) throw new Error ( `No VM for contract ${ contractAddress } ` ) ;
648+
649+ // time travel
650+ const currBackend = vm . backend ;
651+ const storage = new BasicKVIterStorage ( this . getContractStorage ( contractAddress , storeSnapshot ) ) ;
652+ vm . backend = {
653+ ...vm . backend ,
654+ storage,
655+ } ;
656+
657+ try {
658+ return this . query ( contractAddress , queryMsg ) ;
659+ }
660+ // reset time travel
661+ finally {
662+ vm . backend = currBackend ;
663+ }
664+ }
640665
641666 buildAppResponse (
642667 contract : string ,
0 commit comments