diff --git a/src/contract/HandlerBasedContract.ts b/src/contract/HandlerBasedContract.ts index ed2c2947..1f5b7c08 100644 --- a/src/contract/HandlerBasedContract.ts +++ b/src/contract/HandlerBasedContract.ts @@ -646,6 +646,7 @@ export class HandlerBasedContract implements Contract { const benchmark = Benchmark.measure(); if (!this.isRoot()) { + // przekazać nasz gotowiec cachedState = this.interactionState().getLessOrEqual(this.txId(), upToSortKey) as SortKeyCacheResult< EvalStateResult >; diff --git a/src/core/WarpPlugin.ts b/src/core/WarpPlugin.ts index 40eead82..3e332b02 100644 --- a/src/core/WarpPlugin.ts +++ b/src/core/WarpPlugin.ts @@ -10,7 +10,8 @@ export const knownWarpPlugins = [ 'deploy', 'contract-blacklist', 'vm2', - 'vrf' + 'vrf', + 'quickjs' ] as const; type WarpPluginPartialType = `smartweave-extension-${string}`; export type WarpKnownPluginType = (typeof knownWarpPlugins)[number]; diff --git a/src/core/modules/impl/HandlerExecutorFactory.ts b/src/core/modules/impl/HandlerExecutorFactory.ts index 1b3904d4..f884601c 100644 --- a/src/core/modules/impl/HandlerExecutorFactory.ts +++ b/src/core/modules/impl/HandlerExecutorFactory.ts @@ -16,6 +16,7 @@ import { isBrowser } from '../../../utils/utils'; import { Buffer } from 'warp-isomorphic'; import { InteractionState } from '../../../contract/states/InteractionState'; import { WarpLogger } from '../../../logging/WarpLogger'; +import { XOR } from 'utils/types/mutually-exclusive'; // 'require' to fix esbuild adding same lib in both cjs and esm format // https://github.com/evanw/esbuild/issues/1950 @@ -208,6 +209,14 @@ export class HandlerExecutorFactory implements ExecutorFactory>('quickjs'); + return await quickJsPlugin.process({ + contractSource: contractDefinition.src, + evaluationOptions, + swGlobal: swGlobal, + contractDefinition + }); } else { const contractFunction = new Function(normalizedSource); const handler = isBrowser() @@ -286,11 +295,11 @@ export interface HandlerApi { export type HandlerResult = { result: Result; state: State; - event: InteractionCompleteEvent; + event?: InteractionCompleteEvent; gasUsed?: number; }; -export type InteractionResult = HandlerResult & { +type WarpInteractionResult = HandlerResult & { type: InteractionResultType; errorMessage?: string; error?: unknown; @@ -298,6 +307,25 @@ export type InteractionResult = HandlerResult & { originalErrorMessages?: Record; }; +export type AoInteractionResult = { + Memory: string; + Error: string; + Messages: { + target: string; + data: string; + anchor: string; + tags: { name: string; value: string }[]; + }[]; + Spawns: { + data: string; + anchor: string; + tags: { name: string; value: string }[]; + }[]; + Output: Result; +}; + +export type InteractionResult = XOR, AoInteractionResult>; + export type InteractionType = 'view' | 'write'; export type ContractInteraction = { @@ -330,3 +358,18 @@ export interface VM2PluginInput { logger: WarpLogger; contractDefinition: ContractDefinition; } + +export interface QuickJsPluginInput { + contractSource: string; + evaluationOptions: EvaluationOptions; + swGlobal: SmartWeaveGlobal; + contractDefinition: ContractDefinition; + wasmMemory?: WebAssembly.Memory; +} + +export interface QuickJsOptions { + memoryLimit?: number; + maxStackSize?: number; + interruptCycles?: number; + timeout?: number; +} diff --git a/src/index.ts b/src/index.ts index 522a81cd..fff92734 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,6 +53,8 @@ export * from './contract/Signature'; export * from './contract/EvaluationOptionsEvaluator'; export * from './contract/deploy/Source'; export * from './contract/deploy/CreateContract'; +export * from './contract/states/ContractInteractionState'; +export * from './contract/states/InteractionState'; export * from './legacy/gqlResult'; export * from './legacy/smartweave-global'; diff --git a/src/utils/types/mutually-exclusive.ts b/src/utils/types/mutually-exclusive.ts new file mode 100644 index 00000000..a314dbdc --- /dev/null +++ b/src/utils/types/mutually-exclusive.ts @@ -0,0 +1,2 @@ +type Without = { [P in Exclude]?: never }; +export type XOR = T | U extends object ? (Without & U) | (Without & T) : T | U;