diff --git a/package.json b/package.json index e0bdcf9c..74071bc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "warp-contracts", - "version": "1.4.46-beta.0", + "version": "1.4.45", "description": "An implementation of the SmartWeave smart contract protocol.", "types": "./lib/types/index.d.ts", "main": "./lib/cjs/index.js", @@ -106,7 +106,6 @@ "stream-buffers": "^3.0.2", "unzipit": "^1.4.0", "warp-arbundles": "^1.0.4", - "warp-contracts": "^1.4.45", "warp-isomorphic": "^1.0.7", "warp-wasm-metering": "1.0.1" }, diff --git a/src/core/modules/StateEvaluator.ts b/src/core/modules/StateEvaluator.ts index 603dbe78..f04229ce 100644 --- a/src/core/modules/StateEvaluator.ts +++ b/src/core/modules/StateEvaluator.ts @@ -97,8 +97,7 @@ export class EvalStateResult { constructor( readonly state: State, readonly validity: Record, - readonly errorMessages: Record, - readonly events?: InteractionCompleteEvent[] + readonly errorMessages: Record ) {} } @@ -263,6 +262,16 @@ export interface EvaluationOptions { strictEvolve: boolean; } +// https://github.com/nodejs/node/issues/40678 duh... +export class CustomEvent extends Event { + readonly detail: T; + + constructor(message, data) { + super(message, data); + this.detail = data.detail; + } +} + export class InteractionCompleteEvent { constructor( readonly contractTxId: string, diff --git a/src/core/modules/impl/DefaultStateEvaluator.ts b/src/core/modules/impl/DefaultStateEvaluator.ts index 46904467..91f27af3 100644 --- a/src/core/modules/impl/DefaultStateEvaluator.ts +++ b/src/core/modules/impl/DefaultStateEvaluator.ts @@ -8,7 +8,7 @@ import { GQLNodeInterface, GQLTagInterface } from '../../../legacy/gqlResult'; import { Benchmark } from '../../../logging/Benchmark'; import { LoggerFactory } from '../../../logging/LoggerFactory'; import { indent } from '../../../utils/utils'; -import { EvalStateResult, StateEvaluator } from '../StateEvaluator'; +import { EvalStateResult, StateEvaluator, CustomEvent } from '../StateEvaluator'; import { AbortError, ContractInteraction, HandlerApi, InteractionResult } from './HandlerExecutorFactory'; import { TagsParser } from './TagsParser'; import { VrfPluginFunctions } from '../../WarpPlugin'; @@ -44,7 +44,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { ): Promise>> { return this.doReadState( executionContext.sortedInteractions, - new EvalStateResult(executionContext.contractDefinition.initState, {}, {}, []), + new EvalStateResult(executionContext.contractDefinition.initState, {}, {}), executionContext ); } @@ -61,7 +61,6 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { let currentSortKey = null; const validity = baseState.validity; const errorMessages = baseState.errorMessages; - const events = []; // TODO: opt - reuse wasm handlers executionContext?.handler.initState(currentState); @@ -98,11 +97,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { currentSortKey = missingInteraction.sortKey; contract .interactionState() - .setInitial( - contract.txId(), - new EvalStateResult(currentState, validity, errorMessages, events), - currentSortKey - ); + .setInitial(contract.txId(), new EvalStateResult(currentState, validity, errorMessages), currentSortKey); const singleInteractionBenchmark = Benchmark.measure(); if (missingInteraction.vrf) { @@ -171,7 +166,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { this.logger.warn(`Skipping contract in internal write, reason ${e.subtype || e.name}`); errorMessages[missingInteraction.id] = e; if (canBeCached(missingInteraction)) { - const toCache = new EvalStateResult(currentState, validity, errorMessages, events); + const toCache = new EvalStateResult(currentState, validity, errorMessages); lastConfirmedTxState = { tx: missingInteraction, state: toCache @@ -202,7 +197,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { writingContractState.cachedValue.errorMessages[missingInteraction.id]; } - const toCache = new EvalStateResult(currentState, validity, errorMessages, events); + const toCache = new EvalStateResult(currentState, validity, errorMessages); if (canBeCached(missingInteraction)) { lastConfirmedTxState = { tx: missingInteraction, @@ -249,7 +244,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { const result = await executionContext.handler.handle( executionContext, - new EvalStateResult(currentState, validity, errorMessages, events), + new EvalStateResult(currentState, validity, errorMessages), interactionData ); @@ -279,7 +274,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { currentState = result.state; - const toCache = new EvalStateResult(currentState, validity, errorMessages, events); + const toCache = new EvalStateResult(currentState, validity, errorMessages); if (canBeCached(missingInteraction)) { lastConfirmedTxState = { tx: missingInteraction, @@ -289,7 +284,9 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { const event = result.event; if (event) { - events.push(event); + warp.eventTarget.dispatchEvent( + new CustomEvent(isValidInteraction ? 'interactionCompleted' : 'interactionFailed', { detail: event }) + ); } } @@ -339,11 +336,11 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { } } else { // if that's an inner contract call - only update the state in the uncommitted states - const interactionState = new EvalStateResult(currentState, validity, errorMessages, events); + const interactionState = new EvalStateResult(currentState, validity, errorMessages); contract.interactionState().update(contract.txId(), interactionState, currentSortKey); } } - const evalStateResult = new EvalStateResult(currentState, validity, errorMessages, events); + const evalStateResult = new EvalStateResult(currentState, validity, errorMessages); // state could have been fully retrieved from cache // or there were no interactions below requested sort key