Skip to content

Commit

Permalink
v1.4.45-warpy.1
Browse files Browse the repository at this point in the history
  • Loading branch information
asiaziola committed Nov 4, 2024
1 parent 4135acd commit 10a6cd7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"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: 2 additions & 11 deletions src/core/modules/StateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export class EvalStateResult<State> {
constructor(
readonly state: State,
readonly validity: Record<string, boolean>,
readonly errorMessages: Record<string, string>
readonly errorMessages: Record<string, string>,
readonly events?: InteractionCompleteEvent[]
) {}
}

Expand Down Expand Up @@ -262,16 +263,6 @@ 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: 15 additions & 12 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, CustomEvent } from '../StateEvaluator';
import { EvalStateResult, StateEvaluator } 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,6 +61,7 @@ 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 @@ -97,7 +98,11 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
currentSortKey = missingInteraction.sortKey;
contract
.interactionState()
.setInitial(contract.txId(), new EvalStateResult(currentState, validity, errorMessages), currentSortKey);
.setInitial(
contract.txId(),
new EvalStateResult(currentState, validity, errorMessages, events),
currentSortKey
);
const singleInteractionBenchmark = Benchmark.measure();

if (missingInteraction.vrf) {
Expand Down Expand Up @@ -166,7 +171,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);
const toCache = new EvalStateResult(currentState, validity, errorMessages, events);
lastConfirmedTxState = {
tx: missingInteraction,
state: toCache
Expand Down Expand Up @@ -197,7 +202,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
writingContractState.cachedValue.errorMessages[missingInteraction.id];
}

const toCache = new EvalStateResult(currentState, validity, errorMessages);
const toCache = new EvalStateResult(currentState, validity, errorMessages, events);
if (canBeCached(missingInteraction)) {
lastConfirmedTxState = {
tx: missingInteraction,
Expand Down Expand Up @@ -244,7 +249,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {

const result = await executionContext.handler.handle(
executionContext,
new EvalStateResult(currentState, validity, errorMessages),
new EvalStateResult(currentState, validity, errorMessages, events),
interactionData
);

Expand Down Expand Up @@ -274,7 +279,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {

currentState = result.state;

const toCache = new EvalStateResult(currentState, validity, errorMessages);
const toCache = new EvalStateResult(currentState, validity, errorMessages, events);
if (canBeCached(missingInteraction)) {
lastConfirmedTxState = {
tx: missingInteraction,
Expand All @@ -284,9 +289,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {

const event = result.event;
if (event) {
warp.eventTarget.dispatchEvent(
new CustomEvent(isValidInteraction ? 'interactionCompleted' : 'interactionFailed', { detail: event })
);
events.push(event);
}
}

Expand Down Expand Up @@ -336,11 +339,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);
const interactionState = new EvalStateResult(currentState, validity, errorMessages, events);
contract.interactionState().update(contract.txId(), interactionState, currentSortKey);
}
}
const evalStateResult = new EvalStateResult<State>(currentState, validity, errorMessages);
const evalStateResult = new EvalStateResult<State>(currentState, validity, errorMessages, events);

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

0 comments on commit 10a6cd7

Please sign in to comment.