Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support external statemanager in VM constructor #264

Merged
merged 2 commits into from
Feb 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 13 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down