1 | import { common, ECPoint, UInt160, UInt256, VMState } from '@neo-one/client-common-esnext-esm';
|
2 | import { Monitor } from '@neo-one/monitor-esnext-esm';
|
3 | import BN from 'bn.js';
|
4 | import { Action } from './action';
|
5 | import { Block } from './Block';
|
6 | import { WriteBlockchain } from './Blockchain';
|
7 | import { ContractParameter } from './contractParameter';
|
8 | import { ScriptContainer } from './ScriptContainer';
|
9 | import { Witness } from './Witness';
|
10 |
|
11 | export interface VerifyScriptOptions {
|
12 | readonly scriptContainer: ScriptContainer;
|
13 | readonly hash: UInt160;
|
14 | readonly witness: Witness;
|
15 | }
|
16 |
|
17 | export interface VerifyScriptResult {
|
18 | readonly failureMessage?: string;
|
19 | readonly hash: UInt160;
|
20 | readonly witness: Witness;
|
21 | readonly actions: ReadonlyArray<Action>;
|
22 | }
|
23 |
|
24 | export type VerifyScript = (options: VerifyScriptOptions) => Promise<VerifyScriptResult>;
|
25 |
|
26 | export enum TriggerType {
|
27 | Verification = 0x00,
|
28 | Application = 0x10,
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 | export interface Script {
|
34 | readonly code: Buffer;
|
35 | }
|
36 |
|
37 | export const NULL_ACTION = {
|
38 | blockIndex: -1,
|
39 | blockHash: common.ZERO_UINT256,
|
40 | transactionIndex: -1,
|
41 | transactionHash: common.ZERO_UINT256,
|
42 | };
|
43 |
|
44 | export interface ExecutionAction {
|
45 | readonly blockIndex: number;
|
46 | readonly blockHash: UInt256;
|
47 | readonly transactionIndex: number;
|
48 | readonly transactionHash: UInt256;
|
49 | }
|
50 |
|
51 | export interface ExecuteScriptsResult {
|
52 | readonly state: VMState;
|
53 | readonly stack: ReadonlyArray<ContractParameter>;
|
54 | readonly stackAlt: ReadonlyArray<ContractParameter>;
|
55 | readonly gasConsumed: BN;
|
56 | readonly gasCost: BN;
|
57 | readonly errorMessage?: string;
|
58 | }
|
59 |
|
60 | export interface VMListeners {
|
61 | readonly onNotify?: (
|
62 | options: {
|
63 | readonly args: ReadonlyArray<ContractParameter>;
|
64 | readonly scriptHash: UInt160;
|
65 | },
|
66 | ) => void;
|
67 |
|
68 | readonly onLog?: (options: { readonly message: string; readonly scriptHash: UInt160 }) => void;
|
69 | readonly onMigrateContract?: (options: { readonly from: UInt160; readonly to: UInt160 }) => void;
|
70 | readonly onSetVotes?: (options: { readonly address: UInt160; readonly votes: ReadonlyArray<ECPoint> }) => void;
|
71 | }
|
72 |
|
73 | export interface VMFeatureSwitches {
|
74 | readonly structClone: boolean;
|
75 | }
|
76 |
|
77 | export type ExecuteScripts = (
|
78 | input: {
|
79 | readonly monitor: Monitor;
|
80 | readonly scripts: ReadonlyArray<Script>;
|
81 | readonly blockchain: WriteBlockchain;
|
82 | readonly scriptContainer: ScriptContainer;
|
83 | readonly triggerType: TriggerType;
|
84 | readonly action: ExecutionAction;
|
85 | readonly gas: BN;
|
86 | readonly listeners?: VMListeners;
|
87 | readonly skipWitnessVerify?: boolean;
|
88 | readonly persistingBlock?: Block;
|
89 | readonly vmFeatures: VMFeatureSwitches;
|
90 | },
|
91 | ) => Promise<ExecuteScriptsResult>;
|
92 |
|
93 | export interface VM {
|
94 | readonly executeScripts: ExecuteScripts;
|
95 | }
|