UNPKG

4.57 kBTypeScriptView Raw
1import Blockchain from 'ethereumjs-blockchain';
2import Common from 'ethereumjs-common';
3import { StateManager } from './state';
4import { RunCodeOpts } from './runCode';
5import { RunCallOpts } from './runCall';
6import { RunTxOpts, RunTxResult } from './runTx';
7import { RunBlockOpts, RunBlockResult } from './runBlock';
8import { EVMResult, ExecResult } from './evm/evm';
9import { OpcodeList } from './evm/opcodes';
10import PStateManager from './state/promisified';
11declare const AsyncEventEmitter: any;
12/**
13 * Options for instantiating a [[VM]].
14 */
15export interface VMOpts {
16 /**
17 * The chain the VM operates on
18 */
19 chain?: string;
20 /**
21 * Hardfork rules to be used
22 */
23 hardfork?: string;
24 /**
25 * A [[StateManager]] instance to use as the state store (Beta API)
26 */
27 stateManager?: StateManager;
28 /**
29 * A [merkle-patricia-tree](https://github.com/ethereumjs/merkle-patricia-tree) instance for the state tree (ignored if stateManager is passed)
30 * @deprecated
31 */
32 state?: any;
33 /**
34 * A [blockchain](https://github.com/ethereumjs/ethereumjs-blockchain) object for storing/retrieving blocks
35 */
36 blockchain?: Blockchain;
37 /**
38 * If true, create entries in the state tree for the precompiled contracts, saving some gas the
39 * first time each of them is called.
40 *
41 * If this parameter is false, the first call to each of them has to pay an extra 25000 gas
42 * for creating the account.
43 *
44 * Setting this to true has the effect of precompiled contracts' gas costs matching mainnet's from
45 * the very first call, which is intended for testing networks.
46 */
47 activatePrecompiles?: boolean;
48 /**
49 * Allows unlimited contract sizes while debugging. By setting this to `true`, the check for contract size limit of 24KB (see [EIP-170](https://git.io/vxZkK)) is bypassed
50 */
51 allowUnlimitedContractSize?: boolean;
52 common?: Common;
53}
54/**
55 * Execution engine which can be used to run a blockchain, individual
56 * blocks, individual transactions, or snippets of EVM bytecode.
57 *
58 * This class is an AsyncEventEmitter, please consult the README to learn how to use it.
59 */
60export default class VM extends AsyncEventEmitter {
61 opts: VMOpts;
62 _common: Common;
63 stateManager: StateManager;
64 blockchain: Blockchain;
65 allowUnlimitedContractSize: boolean;
66 _opcodes: OpcodeList;
67 readonly _emit: (topic: string, data: any) => Promise<void>;
68 readonly pStateManager: PStateManager;
69 /**
70 * Instantiates a new [[VM]] Object.
71 * @param opts - Default values for the options are:
72 * - `chain`: 'mainnet'
73 * - `hardfork`: 'petersburg' [supported: 'byzantium', 'constantinople', 'petersburg', 'istanbul' (DRAFT) (will throw on unsupported)]
74 * - `activatePrecompiles`: false
75 * - `allowUnlimitedContractSize`: false [ONLY set to `true` during debugging]
76 */
77 constructor(opts?: VMOpts);
78 /**
79 * Processes blocks and adds them to the blockchain.
80 *
81 * This method modifies the state.
82 *
83 * @param blockchain - A [blockchain](https://github.com/ethereum/ethereumjs-blockchain) object to process
84 */
85 runBlockchain(blockchain: any): Promise<void>;
86 /**
87 * Processes the `block` running all of the transactions it contains and updating the miner's account
88 *
89 * This method modifies the state. If `generate` is `true`, the state modifications will be
90 * reverted if an exception is raised. If it's `false`, it won't revert if the block's header is
91 * invalid. If an error is thrown from an event handler, the state may or may not be reverted.
92 *
93 * @param opts - Default values for options:
94 * - `generate`: false
95 */
96 runBlock(opts: RunBlockOpts): Promise<RunBlockResult>;
97 /**
98 * Process a transaction. Run the vm. Transfers eth. Checks balances.
99 *
100 * This method modifies the state. If an error is thrown, the modifications are reverted, except
101 * when the error is thrown from an event handler. In the latter case the state may or may not be
102 * reverted.
103 */
104 runTx(opts: RunTxOpts): Promise<RunTxResult>;
105 /**
106 * runs a call (or create) operation.
107 *
108 * This method modifies the state.
109 */
110 runCall(opts: RunCallOpts): Promise<EVMResult>;
111 /**
112 * Runs EVM code.
113 *
114 * This method modifies the state.
115 */
116 runCode(opts: RunCodeOpts): Promise<ExecResult>;
117 /**
118 * Returns a copy of the [[VM]] instance.
119 */
120 copy(): VM;
121}
122export {};
123
\No newline at end of file