Skip to content

Commit

Permalink
Revert "v1.4.46-beta.0"
Browse files Browse the repository at this point in the history
This reverts commit 967f89c.
  • Loading branch information
asiaziola committed Nov 4, 2024
1 parent 967f89c commit b586678
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
13 changes: 11 additions & 2 deletions src/core/modules/StateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ export class EvalStateResult<State> {
constructor(
readonly state: State,
readonly validity: Record<string, boolean>,
readonly errorMessages: Record<string, string>,
readonly events?: InteractionCompleteEvent[]
readonly errorMessages: Record<string, string>
) {}
}

Expand Down Expand Up @@ -263,6 +262,16 @@ export interface EvaluationOptions {
strictEvolve: boolean;
}

// https://github.com/nodejs/node/issues/40678 duh...
export class CustomEvent<T = unknown> extends Event {
readonly detail: T;

constructor(message, data) {
super(message, data);
this.detail = data.detail;
}
}

export class InteractionCompleteEvent<Input = unknown, T = unknown> {
constructor(
readonly contractTxId: string,
Expand Down
27 changes: 12 additions & 15 deletions src/core/modules/impl/DefaultStateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,7 +44,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
): Promise<SortKeyCacheResult<EvalStateResult<State>>> {
return this.doReadState(
executionContext.sortedInteractions,
new EvalStateResult<State>(executionContext.contractDefinition.initState, {}, {}, []),
new EvalStateResult<State>(executionContext.contractDefinition.initState, {}, {}),
executionContext
);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
);

Expand Down Expand Up @@ -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,
Expand All @@ -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 })
);
}
}

Expand Down Expand Up @@ -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<State>(currentState, validity, errorMessages, events);
const evalStateResult = new EvalStateResult<State>(currentState, validity, errorMessages);

// state could have been fully retrieved from cache
// or there were no interactions below requested sort key
Expand Down

0 comments on commit b586678

Please sign in to comment.