UNPKG

2.72 kBPlain TextView Raw
1import { common, ECPoint, UInt160, UInt256, VMState } from '@neo-one/client-common-esnext-esm';
2import { Monitor } from '@neo-one/monitor-esnext-esm';
3import BN from 'bn.js';
4import { Action } from './action';
5import { Block } from './Block';
6import { WriteBlockchain } from './Blockchain';
7import { ContractParameter } from './contractParameter';
8import { ScriptContainer } from './ScriptContainer';
9import { Witness } from './Witness';
10
11export interface VerifyScriptOptions {
12 readonly scriptContainer: ScriptContainer;
13 readonly hash: UInt160;
14 readonly witness: Witness;
15}
16
17export interface VerifyScriptResult {
18 readonly failureMessage?: string;
19 readonly hash: UInt160;
20 readonly witness: Witness;
21 readonly actions: ReadonlyArray<Action>;
22}
23
24export type VerifyScript = (options: VerifyScriptOptions) => Promise<VerifyScriptResult>;
25
26export enum TriggerType {
27 Verification = 0x00,
28 Application = 0x10,
29}
30
31// Application
32
33export interface Script {
34 readonly code: Buffer;
35}
36
37export const NULL_ACTION = {
38 blockIndex: -1,
39 blockHash: common.ZERO_UINT256,
40 transactionIndex: -1,
41 transactionHash: common.ZERO_UINT256,
42};
43
44export interface ExecutionAction {
45 readonly blockIndex: number;
46 readonly blockHash: UInt256;
47 readonly transactionIndex: number;
48 readonly transactionHash: UInt256;
49}
50
51export 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
60export 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
73export interface VMFeatureSwitches {
74 readonly structClone: boolean;
75}
76
77export 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
93export interface VM {
94 readonly executeScripts: ExecuteScripts;
95}