Skip to content

Commit

Permalink
fix: dumb fix by a dumb guy
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedziwiatr committed Nov 4, 2023
1 parent 49688e8 commit be24b1c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/core/modules/impl/handler/JsHandlerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,16 @@ export class JsHandlerApi<State> extends AbstractContractHandler<State> {

try {
await this.swGlobal.kv.open();
await this.swGlobal.kv.begin();
if (interaction.interactionType === 'write') {
await this.swGlobal.kv.begin();
}

const handlerResult = await Promise.race([timeoutPromise, this.contractFunction(stateClone, interaction)]);

if (handlerResult && (handlerResult.state !== undefined || handlerResult.result !== undefined)) {
await this.swGlobal.kv.commit();
if (interaction.interactionType === 'write') {
await this.swGlobal.kv.commit();
}

let interactionEvent: InteractionCompleteEvent = null;

Expand Down Expand Up @@ -177,7 +181,9 @@ export class JsHandlerApi<State> extends AbstractContractHandler<State> {
// Will be caught below as unexpected exception.
throw new Error(`Unexpected result from contract: ${JSON.stringify(handlerResult)}`);
} catch (err) {
await this.swGlobal.kv.rollback();
if (interaction.interactionType === 'write') {
await this.swGlobal.kv.rollback();
}
switch (err.name) {
case KnownErrors.ContractError:
return {
Expand Down

0 comments on commit be24b1c

Please sign in to comment.