@@ -149,7 +149,8 @@ export class HandlerBasedContract<State> implements Contract<State> {
149
149
async readState (
150
150
sortKeyOrBlockHeight ?: string | number ,
151
151
interactions ?: GQLNodeInterface [ ] ,
152
- signal ?: AbortSignal
152
+ signal ?: AbortSignal ,
153
+ state ?: SortKeyCacheResult < EvalStateResult < State > >
153
154
) : Promise < SortKeyCacheResult < EvalStateResult < State > > > {
154
155
this . logger . info ( 'Read state for' , {
155
156
contractTxId : this . _contractTxId ,
@@ -181,7 +182,8 @@ export class HandlerBasedContract<State> implements Contract<State> {
181
182
sortKey ,
182
183
false ,
183
184
interactions ,
184
- signal
185
+ signal ,
186
+ state
185
187
) ;
186
188
this . logger . info ( 'Execution Context' , {
187
189
srcTxId : executionContext . contractDefinition ?. srcTxId ,
@@ -221,9 +223,10 @@ export class HandlerBasedContract<State> implements Contract<State> {
221
223
async readStateFor (
222
224
sortKey : string ,
223
225
interactions : GQLNodeInterface [ ] ,
224
- signal ?: AbortSignal
226
+ signal ?: AbortSignal ,
227
+ state ?: SortKeyCacheResult < EvalStateResult < State > >
225
228
) : Promise < SortKeyCacheResult < EvalStateResult < State > > > {
226
- return this . readState ( sortKey , interactions , signal ) ;
229
+ return this . readState ( sortKey , interactions , signal , state ) ;
227
230
}
228
231
229
232
async readStateBatch (
@@ -635,7 +638,8 @@ export class HandlerBasedContract<State> implements Contract<State> {
635
638
upToSortKey ?: string ,
636
639
forceDefinitionLoad = false ,
637
640
interactions ?: GQLNodeInterface [ ] ,
638
- signal ?: AbortSignal
641
+ signal ?: AbortSignal ,
642
+ state ?: SortKeyCacheResult < EvalStateResult < State > >
639
643
) : Promise < ExecutionContext < State , HandlerApi < State > > > {
640
644
const { definitionLoader, interactionsLoader, stateEvaluator } = this . warp ;
641
645
let cachedState : SortKeyCacheResult < EvalStateResult < State > > ;
@@ -646,7 +650,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
646
650
EvalStateResult < State >
647
651
> ;
648
652
}
649
- cachedState = cachedState || ( await stateEvaluator . latestAvailableState < State > ( contractTxId , upToSortKey ) ) ;
653
+ cachedState = state || cachedState || ( await stateEvaluator . latestAvailableState < State > ( contractTxId , upToSortKey ) ) ;
650
654
if ( upToSortKey && this . evaluationOptions ( ) . strictSortKey && cachedState ?. sortKey != upToSortKey ) {
651
655
throw new Error ( `State not cached at the exact required ${ upToSortKey } sortKey` ) ;
652
656
}
0 commit comments