Skip to content

Commit

Permalink
Support external statemanager in VM constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
axic authored and holgerd77 committed Feb 2, 2018
1 parent 4684a8f commit 9191f40
Showing 1 changed file with 13 additions and 7 deletions.
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
* @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

0 comments on commit 9191f40

Please sign in to comment.