feat: Add functions to the Kv API in order to query ranges of keys and/or values #345 - kv delete
This commit is contained in:
@@ -150,10 +150,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
|
||||
if (sortKey && !this.isRoot() && this.interactionState().has(this.txId())) {
|
||||
const result = this.interactionState().get(this.txId());
|
||||
return {
|
||||
sortKey,
|
||||
cachedValue: result as EvalStateResult<State>
|
||||
};
|
||||
return new SortKeyCacheResult<EvalStateResult<State>>(sortKey, result as EvalStateResult<State>);
|
||||
}
|
||||
|
||||
// TODO: not sure if we should synchronize on a contract instance or contractTxId
|
||||
@@ -725,10 +722,10 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
const executionContext = await this.createExecutionContextFromTx(this._contractTxId, interactionTx);
|
||||
|
||||
if (!this.isRoot() && this.interactionState().has(this.txId())) {
|
||||
evalStateResult = {
|
||||
sortKey: interactionTx.sortKey,
|
||||
cachedValue: this.interactionState().get(this.txId()) as EvalStateResult<State>
|
||||
};
|
||||
evalStateResult = new SortKeyCacheResult<EvalStateResult<State>>(
|
||||
interactionTx.sortKey,
|
||||
this.interactionState().get(this.txId()) as EvalStateResult<State>
|
||||
);
|
||||
} else {
|
||||
evalStateResult = await this.warp.stateEvaluator.eval<State>(executionContext);
|
||||
this.interactionState().update(this.txId(), evalStateResult.cachedValue);
|
||||
@@ -858,10 +855,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
async getStorageValues(keys: string[]): Promise<SortKeyCacheResult<Map<string, unknown>>> {
|
||||
const lastCached = await this.warp.stateEvaluator.getCache().getLast(this.txId());
|
||||
if (lastCached == null) {
|
||||
return {
|
||||
sortKey: null,
|
||||
cachedValue: new Map()
|
||||
};
|
||||
return new SortKeyCacheResult<Map<string, unknown>>(null, new Map());
|
||||
}
|
||||
|
||||
const storage = this.warp.kvStorageFactory(this.txId());
|
||||
@@ -872,10 +866,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
const lastValue = await storage.getLessOrEqual(key, lastCached.sortKey);
|
||||
result.set(key, lastValue == null ? null : lastValue.cachedValue);
|
||||
}
|
||||
return {
|
||||
sortKey: lastCached.sortKey,
|
||||
cachedValue: result
|
||||
};
|
||||
return new SortKeyCacheResult<Map<string, unknown>>(lastCached.sortKey, result);
|
||||
} finally {
|
||||
await storage.close();
|
||||
}
|
||||
@@ -894,7 +885,6 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
return result as HandlerBasedContract<unknown>;
|
||||
}
|
||||
|
||||
|
||||
private async maybeSyncStateWithRemoteSource(
|
||||
remoteState: SortKeyCacheResult<EvalStateResult<State>>,
|
||||
upToSortKey: string,
|
||||
|
||||
Reference in New Issue
Block a user