diff --git a/README.md b/README.md index d21795e596..b661d105a3 100644 --- a/README.md +++ b/README.md @@ -52,14 +52,13 @@ To build for standalone use in the browser, install `browserify` and check [run- - [`VM` debugging hooks](#vm-debugging-hooks) - [`vm.onStep`](#vmonstep) -### `new VM([StateTrie], [blockchain])` +### `new VM([opts])` Creates a new VM object -- `StateTrie` - The [Patricia Merkle Tree](https://github.com/wanderer/merkle-patricia-tree) that contains the state. If no trie is given the `VM` will create an in memory trie. -- `blockchain` - an instance of the [`Blockchain`](https://github.com/ethereum/ethereumjs-lib/blob/master/docs/blockchain.md). If no blockchain is given a fake blockchain will be used. - `opts` - - `state` - the state trie - - `blockchain` - an instance of ethereumjs-blockchain - - `activatePrecompiles` - create entries in the state tree for the precompiled contracts + - `stateManager` - A state manager instance (**EXPERIMENTAL** - unstable API) + - `state` - A merkle-patricia-tree instance for the state tree (ignored if `stateManager` is passed) + - `blockchain` - A blockchain object for storing/retrieving blocks (ignored if `stateManager` is passed) + - `activatePrecompiles` - Create entries in the state tree for the precompiled contracts ### `VM` methods diff --git a/lib/index.js b/lib/index.js index 69528f2bd2..9652e5f9a8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -28,21 +28,27 @@ VM.deps = { /** * @constructor * @param {Object} [opts] - * @param {Trie} [opts.state] A merkle-patricia-tree instance for the state tree - * @param {Blockchain} [opts.blockchain] A blockchain object for storing/retrieving blocks + * @param {StateManager} [opts.stateManager] A state manager instance (EXPERIMENTAL - unstable API) + * @param {Trie} [opts.state] A merkle-patricia-tree instance for the state tree (ignored if stateManager is passed) + * @param {Blockchain} [opts.blockchain] A blockchain object for storing/retrieving blocks (ignored if stateManager is passed) * @param {Boolean} [opts.activatePrecompiles] Create entries in the state tree for the precompiled contracts */ function VM (opts = {}) { - this.stateManager = new StateManager({ - trie: opts.state, - blockchain: opts.blockchain - }) + this.opts = opts + + if (opts.stateManager) { + this.stateManager = opts.stateManager + } else { + this.stateManager = new StateManager({ + trie: opts.state, + blockchain: opts.blockchain + }) + } // temporary // this is here for a gradual transition to StateManager this.blockchain = this.stateManager.blockchain this.trie = this.stateManager.trie - this.opts = opts || {} // precompiled contracts this._precompiled = {}