diff --git a/src/blockchain/blockchain.js b/src/blockchain/blockchain.js index 1273857275..9583ad83c8 100644 --- a/src/blockchain/blockchain.js +++ b/src/blockchain/blockchain.js @@ -11,8 +11,6 @@ const Personal = require('web3-eth-personal') const Web3 = require('web3') const async = require('async') -const { BN, privateToAddress, isValidPrivate, stripHexPrefix } = require('ethereumjs-util') -const crypto = require('crypto') const { EventEmitter } = require('events') const { resultToRemixTx } = require('./txResultHelper') @@ -375,7 +373,7 @@ class Blockchain { * Create a VM Account * @param {{privateKey: string, balance: string}} newAccount The new account to create */ - createVMAccount(newAccount) { + createVMAccount (newAccount) { if (this.executionContext.getProvider() !== 'vm') { throw new Error('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed') } diff --git a/src/blockchain/providers/injected.js b/src/blockchain/providers/injected.js index bd779e07ef..b3b3fa4597 100644 --- a/src/blockchain/providers/injected.js +++ b/src/blockchain/providers/injected.js @@ -1,4 +1,5 @@ const Web3 = require('web3') +const { stripHexPrefix } = require('ethereumjs-util') class InjectedProvider { @@ -10,7 +11,7 @@ class InjectedProvider { return this.executionContext.web3().eth.getAccounts(cb) } - newAccount(passwordPromptCb, cb) { + newAccount (passwordPromptCb, cb) { passwordPromptCb((passphrase) => { this.executionContext.web3().personal.newAccount(passphrase, cb) }) diff --git a/src/blockchain/providers/node.js b/src/blockchain/providers/node.js index 729f3cf8c2..c05e49efec 100644 --- a/src/blockchain/providers/node.js +++ b/src/blockchain/providers/node.js @@ -1,4 +1,5 @@ const Web3 = require('web3') +const { stripHexPrefix } = require('ethereumjs-util') class NodeProvider { @@ -14,7 +15,7 @@ class NodeProvider { return this.executionContext.web3().eth.getAccounts(cb) } - newAccount(passwordPromptCb, cb) { + newAccount (passwordPromptCb, cb) { if (!this.config.get('settings/personal-mode')) { return cb('Not running in personal mode') } @@ -26,7 +27,7 @@ class NodeProvider { resetEnvironment () { } - getBalanceInEther(address, cb) { + getBalanceInEther (address, cb) { address = stripHexPrefix(address) this.executionContext.web3().eth.getBalance(address, (err, res) => { if (err) { diff --git a/src/blockchain/providers/vm.js b/src/blockchain/providers/vm.js index f5a5f1fd3c..d1fbd1966f 100644 --- a/src/blockchain/providers/vm.js +++ b/src/blockchain/providers/vm.js @@ -1,5 +1,6 @@ const Web3 = require('web3') -const { privateToAddress, toChecksumAddress } = require('ethereumjs-util') +const { BN, privateToAddress, toChecksumAddress, isValidPrivate, stripHexPrefix } = require('ethereumjs-util') +const crypto = require('crypto') class VMProvider { @@ -43,14 +44,14 @@ class VMProvider { this.accounts[toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 } } - createVMAccount (passwordPromptCb, cb) { + createVMAccount (newAccount) { const { privateKey, balance } = newAccount this._addAccount(privateKey, balance) const privKey = Buffer.from(privateKey, 'hex') return '0x' + privateToAddress(privKey).toString('hex') } - newAccount(_passwordPromptCb, cb) { + newAccount (_passwordPromptCb, cb) { let privateKey do { privateKey = crypto.randomBytes(32)