pass executionContext as a param

pull/5370/head
Iuri Matias 5 years ago
parent a05767013c
commit ebf8063f16
  1. 3
      remix-debug/src/cmdline/contextManager.js
  2. 5
      remix-debug/src/cmdline/index.js
  3. 29
      remix-lib/src/execution/txListener.js
  4. 38
      remix-lib/src/execution/txRunner.js
  5. 56
      remix-lib/src/universalDapp.js
  6. 2
      remix-simulator/src/methods/txProcess.js

@ -1,13 +1,12 @@
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
var executionContext = remixLib.execution.executionContext
var Web3Providers = remixLib.vm.Web3Providers var Web3Providers = remixLib.vm.Web3Providers
var DummyProvider = remixLib.vm.DummyProvider var DummyProvider = remixLib.vm.DummyProvider
var init = remixLib.init var init = remixLib.init
class ContextManager { class ContextManager {
constructor () { constructor (executionContext) {
this.executionContext = executionContext this.executionContext = executionContext
this.web3 = this.executionContext.web3() this.web3 = this.executionContext.web3()
this.event = new EventManager() this.event = new EventManager()

@ -2,10 +2,13 @@ var Web3 = require('web3')
var Debugger = require('../debugger/debugger.js') var Debugger = require('../debugger/debugger.js')
var ContextManager = require('./contextManager.js') var ContextManager = require('./contextManager.js')
var EventManager = require('events') var EventManager = require('events')
var remixLib = require('remix-lib')
var executionContext = remixLib.execution.executionContext
class CmdLine { class CmdLine {
constructor () { constructor () {
this.executionContext = executionContext
this.events = new EventManager() this.events = new EventManager()
this.lineColumnPos = null this.lineColumnPos = null
this.rawLocation = null this.rawLocation = null
@ -30,7 +33,7 @@ class CmdLine {
initDebugger (cb) { initDebugger (cb) {
const self = this const self = this
this.contextManager = new ContextManager() this.contextManager = new ContextManager(this.executionContext)
this.debugger = new Debugger({ this.debugger = new Debugger({
web3: this.contextManager.getWeb3(), web3: this.contextManager.getWeb3(),

@ -5,7 +5,7 @@ var ethJSUtil = require('ethereumjs-util')
var EventManager = require('../eventManager') var EventManager = require('../eventManager')
var codeUtil = require('../util') var codeUtil = require('../util')
var executionContext = require('./execution-context') var defaultExecutionContext = require('./execution-context')
var txFormat = require('./txFormat') var txFormat = require('./txFormat')
var txHelper = require('./txHelper') var txHelper = require('./txHelper')
@ -17,8 +17,10 @@ var txHelper = require('./txHelper')
* *
*/ */
class TxListener { class TxListener {
constructor (opt) { constructor (opt, executionContext) {
this.event = new EventManager() this.event = new EventManager()
// has a default for now for backwards compatability
this.executionContext = executionContext || defaultExecutionContext
this._api = opt.api this._api = opt.api
this._resolvedTransactions = {} this._resolvedTransactions = {}
this._resolvedContracts = {} this._resolvedContracts = {}
@ -26,7 +28,7 @@ class TxListener {
this._listenOnNetwork = false this._listenOnNetwork = false
this._loopId = null this._loopId = null
this.init() this.init()
executionContext.event.register('contextChanged', (context) => { this.executionContext.event.register('contextChanged', (context) => {
if (this._isListening) { if (this._isListening) {
this.stopListening() this.stopListening()
this.startListening() this.startListening()
@ -39,15 +41,16 @@ class TxListener {
// in VM mode // in VM mode
// in web3 mode && listen remix txs only // in web3 mode && listen remix txs only
if (!this._isListening) return // we don't listen if (!this._isListening) return // we don't listen
if (this._loopId && executionContext.getProvider() !== 'vm') return // we seems to already listen on a "web3" network if (this._loopId && this.executionContext.getProvider() !== 'vm') return // we seems to already listen on a "web3" network
var call = { var call = {
from: from, from: from,
to: to, to: to,
input: data, input: data,
hash: txResult.transactionHash ? txResult.transactionHash : 'call' + (from || '') + to + data, hash: txResult.transactionHash ? txResult.transactionHash : 'call' + (from || '') + to + data,
isCall: true, isCall: true,
returnValue: executionContext.isVM() ? txResult.result.execResult.returnValue : ethJSUtil.toBuffer(txResult.result), returnValue: this.executionContext.isVM() ? txResult.result.execResult.returnValue : ethJSUtil.toBuffer(txResult.result),
envMode: executionContext.getProvider() envMode: this.executionContext.getProvider()
} }
addExecutionCosts(txResult, call) addExecutionCosts(txResult, call)
@ -65,12 +68,12 @@ class TxListener {
// in VM mode // in VM mode
// in web3 mode && listen remix txs only // in web3 mode && listen remix txs only
if (!this._isListening) return // we don't listen if (!this._isListening) return // we don't listen
if (this._loopId && executionContext.getProvider() !== 'vm') return // we seems to already listen on a "web3" network if (this._loopId && this.executionContext.getProvider() !== 'vm') return // we seems to already listen on a "web3" network
executionContext.web3().eth.getTransaction(txResult.transactionHash, (error, tx) => { this.executionContext.web3().eth.getTransaction(txResult.transactionHash, (error, tx) => {
if (error) return console.log(error) if (error) return console.log(error)
addExecutionCosts(txResult, tx) addExecutionCosts(txResult, tx)
tx.envMode = executionContext.getProvider() tx.envMode = this.executionContext.getProvider()
tx.status = txResult.result.status // 0x0 or 0x1 tx.status = txResult.result.status // 0x0 or 0x1
this._resolve([tx], () => { this._resolve([tx], () => {
}) })
@ -120,7 +123,7 @@ class TxListener {
startListening () { startListening () {
this.init() this.init()
this._isListening = true this._isListening = true
if (this._listenOnNetwork && executionContext.getProvider() !== 'vm') { if (this._listenOnNetwork && this.executionContext.getProvider() !== 'vm') {
this._startListenOnNetwork() this._startListenOnNetwork()
} }
} }
@ -142,7 +145,7 @@ class TxListener {
_startListenOnNetwork () { _startListenOnNetwork () {
this._loopId = setInterval(() => { this._loopId = setInterval(() => {
var currentLoopId = this._loopId var currentLoopId = this._loopId
executionContext.web3().eth.getBlockNumber((error, blockNumber) => { this.executionContext.web3().eth.getBlockNumber((error, blockNumber) => {
if (this._loopId === null) return if (this._loopId === null) return
if (error) return console.log(error) if (error) return console.log(error)
if (currentLoopId === this._loopId && (!this.lastBlock || blockNumber > this.lastBlock)) { if (currentLoopId === this._loopId && (!this.lastBlock || blockNumber > this.lastBlock)) {
@ -163,7 +166,7 @@ class TxListener {
} }
_manageBlock (blockNumber) { _manageBlock (blockNumber) {
executionContext.web3().eth.getBlock(blockNumber, true, (error, result) => { this.executionContext.web3().eth.getBlock(blockNumber, true, (error, result) => {
if (!error) { if (!error) {
this._newBlock(Object.assign({type: 'web3'}, result)) this._newBlock(Object.assign({type: 'web3'}, result))
} }
@ -240,7 +243,7 @@ class TxListener {
// first check known contract, resolve against the `runtimeBytecode` if not known // first check known contract, resolve against the `runtimeBytecode` if not known
contractName = this._resolvedContracts[tx.to] contractName = this._resolvedContracts[tx.to]
if (!contractName) { if (!contractName) {
executionContext.web3().eth.getCode(tx.to, (error, code) => { this.executionContext.web3().eth.getCode(tx.to, (error, code) => {
if (error) return cb(error) if (error) return cb(error)
if (code) { if (code) {
var contractName = this._tryResolveContract(code, contracts, false) var contractName = this._tryResolveContract(code, contracts, false)

@ -3,16 +3,18 @@ var EthJSTX = require('ethereumjs-tx').Transaction
var EthJSBlock = require('ethereumjs-block') var EthJSBlock = require('ethereumjs-block')
var ethJSUtil = require('ethereumjs-util') var ethJSUtil = require('ethereumjs-util')
var BN = ethJSUtil.BN var BN = ethJSUtil.BN
var executionContext = require('./execution-context') var defaultExecutionContext = require('./execution-context')
var EventManager = require('../eventManager') var EventManager = require('../eventManager')
class TxRunner { class TxRunner {
constructor (vmaccounts, api) { constructor (vmaccounts, api, executionContext) {
this.event = new EventManager() this.event = new EventManager()
// has a default for now for backwards compatability
this.executionContext = executionContext || defaultExecutionContext
this._api = api this._api = api
this.blockNumber = 0 this.blockNumber = 0
this.runAsync = true this.runAsync = true
if (executionContext.isVM()) { if (this.executionContext.isVM()) {
// this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. // this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block.
this.blockNumber = 0 // The VM is running in Homestead mode, which started at this block. this.blockNumber = 0 // The VM is running in Homestead mode, which started at this block.
this.runAsync = false // We have to run like this cause the VM Event Manager does not support running multiple txs at the same time. this.runAsync = false // We have to run like this cause the VM Event Manager does not support running multiple txs at the same time.
@ -32,18 +34,18 @@ class TxRunner {
} }
_executeTx (tx, gasPrice, api, promptCb, callback) { _executeTx (tx, gasPrice, api, promptCb, callback) {
if (gasPrice) tx.gasPrice = executionContext.web3().utils.toHex(gasPrice) if (gasPrice) tx.gasPrice = this.executionContext.web3().toHex(gasPrice)
if (api.personalMode()) { if (api.personalMode()) {
promptCb( promptCb(
(value) => { (value) => {
this._sendTransaction(executionContext.web3().personal.sendTransaction, tx, value, callback) this._sendTransaction(this.executionContext.web3().personal.sendTransaction, tx, value, callback)
}, },
() => { () => {
return callback('Canceled by user.') return callback('Canceled by user.')
} }
) )
} else { } else {
this._sendTransaction(executionContext.web3().eth.sendTransaction, tx, null, callback) this._sendTransaction(this.executionContext.web3().eth.sendTransaction, tx, null, callback)
} }
} }
@ -83,7 +85,7 @@ class TxRunner {
data = '0x' + data data = '0x' + data
} }
if (!executionContext.isVM()) { if (!this.executionContext.isVM()) {
self.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, confirmationCb, gasEstimationForceSend, promptCb, callback) self.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, confirmationCb, gasEstimationForceSend, promptCb, callback)
} else { } else {
try { try {
@ -101,7 +103,7 @@ class TxRunner {
return callback('Invalid account selected') return callback('Invalid account selected')
} }
executionContext.vm().stateManager.getAccount(Buffer.from(from.replace('0x', ''), 'hex'), (err, res) => { this.executionContext.vm().stateManager.getAccount(Buffer.from(from.replace('0x', ''), 'hex'), (err, res) => {
if (err) { if (err) {
callback('Account not found') callback('Account not found')
} else { } else {
@ -132,9 +134,9 @@ class TxRunner {
++self.blockNumber ++self.blockNumber
this.runBlockInVm(tx, block, callback) this.runBlockInVm(tx, block, callback)
} else { } else {
executionContext.vm().stateManager.checkpoint(() => { this.executionContext.vm().stateManager.checkpoint(() => {
this.runBlockInVm(tx, block, (err, result) => { this.runBlockInVm(tx, block, (err, result) => {
executionContext.vm().stateManager.revert(() => { this.executionContext.vm().stateManager.revert(() => {
callback(err, result) callback(err, result)
}) })
}) })
@ -145,14 +147,14 @@ class TxRunner {
} }
runBlockInVm (tx, block, callback) { runBlockInVm (tx, block, callback) {
executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then(function (results) { this.executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then(function (results) {
let result = results.results[0] let result = results.results[0]
if (result) { if (result) {
const status = result.execResult.exceptionError ? 0 : 1 const status = result.execResult.exceptionError ? 0 : 1
result.status = `0x${status}` result.status = `0x${status}`
} }
executionContext.addBlock(block) this.executionContext.addBlock(block)
executionContext.trackTx('0x' + tx.hash().toString('hex'), block) this.executionContext.trackTx('0x' + tx.hash().toString('hex'), block)
callback(null, { callback(null, {
result: result, result: result,
transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash())) transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash()))
@ -168,14 +170,14 @@ class TxRunner {
if (useCall) { if (useCall) {
tx.gas = gasLimit tx.gas = gasLimit
return executionContext.web3().eth.call(tx, function (error, result) { return this.executionContext.web3().eth.call(tx, function (error, result) {
callback(error, { callback(error, {
result: result, result: result,
transactionHash: result ? result.transactionHash : null transactionHash: result ? result.transactionHash : null
}) })
}) })
} }
executionContext.web3().eth.estimateGas(tx, function (err, gasEstimation) { this.executionContext.web3().eth.estimateGas(tx, function (err, gasEstimation) {
gasEstimationForceSend(err, () => { gasEstimationForceSend(err, () => {
// callback is called whenever no error // callback is called whenever no error
tx.gas = !gasEstimation ? gasLimit : gasEstimation tx.gas = !gasEstimation ? gasLimit : gasEstimation
@ -197,7 +199,7 @@ class TxRunner {
}) })
}) })
}, () => { }, () => {
var blockGasLimit = executionContext.currentblockGasLimit() var blockGasLimit = self.executionContext.currentblockGasLimit()
// NOTE: estimateGas very likely will return a large limit if execution of the code failed // NOTE: estimateGas very likely will return a large limit if execution of the code failed
// we want to be able to run the code in order to debug and find the cause for the failure // we want to be able to run the code in order to debug and find the cause for the failure
if (err) return callback(err) if (err) return callback(err)
@ -218,7 +220,7 @@ class TxRunner {
async function tryTillReceiptAvailable (txhash, done) { async function tryTillReceiptAvailable (txhash, done) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
executionContext.web3().eth.getTransactionReceipt(txhash, async (err, receipt) => { this.executionContext.web3().eth.getTransactionReceipt(txhash, async (err, receipt) => {
if (err || !receipt) { if (err || !receipt) {
// Try again with a bit of delay if error or if result still null // Try again with a bit of delay if error or if result still null
await pause() await pause()
@ -232,7 +234,7 @@ async function tryTillReceiptAvailable (txhash, done) {
async function tryTillTxAvailable (txhash, done) { async function tryTillTxAvailable (txhash, done) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
executionContext.web3().eth.getTransaction(txhash, async (err, tx) => { this.executionContext.web3().eth.getTransaction(txhash, async (err, tx) => {
if (err || !tx) { if (err || !tx) {
// Try again with a bit of delay if error or if result still null // Try again with a bit of delay if error or if result still null
await pause() await pause()

@ -6,27 +6,29 @@ const { EventEmitter } = require('events')
const TxRunner = require('./execution/txRunner') const TxRunner = require('./execution/txRunner')
const txHelper = require('./execution/txHelper') const txHelper = require('./execution/txHelper')
const EventManager = require('./eventManager') const EventManager = require('./eventManager')
const executionContext = require('./execution/execution-context') const defaultExecutionContext = require('./execution/execution-context')
const { resultToRemixTx } = require('./helpers/txResultHelper') const { resultToRemixTx } = require('./helpers/txResultHelper')
module.exports = class UniversalDApp { module.exports = class UniversalDApp {
constructor (config) { constructor (config, executionContext) {
this.events = new EventEmitter() this.events = new EventEmitter()
this.event = new EventManager() this.event = new EventManager()
// has a default for now for backwards compatability
this.executionContext = executionContext || defaultExecutionContext
this.config = config this.config = config
this.txRunner = new TxRunner({}, { this.txRunner = new TxRunner({}, {
config: config, config: config,
detectNetwork: (cb) => { detectNetwork: (cb) => {
executionContext.detectNetwork(cb) this.executionContext.detectNetwork(cb)
}, },
personalMode: () => { personalMode: () => {
return executionContext.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false return this.executionContext.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false
} }
}) }, this.executionContext)
this.accounts = {} this.accounts = {}
executionContext.event.register('contextChanged', this.resetEnvironment.bind(this)) this.executionContext.event.register('contextChanged', this.resetEnvironment.bind(this))
} }
// TODO : event should be triggered by Udapp instead of TxListener // TODO : event should be triggered by Udapp instead of TxListener
@ -39,7 +41,7 @@ module.exports = class UniversalDApp {
resetEnvironment () { resetEnvironment () {
this.accounts = {} this.accounts = {}
if (executionContext.isVM()) { if (this.executionContext.isVM()) {
this._addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511', '0x56BC75E2D63100000') this._addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511', '0x56BC75E2D63100000')
this._addAccount('2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c', '0x56BC75E2D63100000') this._addAccount('2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c', '0x56BC75E2D63100000')
this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', '0x56BC75E2D63100000') this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', '0x56BC75E2D63100000')
@ -52,14 +54,14 @@ module.exports = class UniversalDApp {
config: this.config, config: this.config,
// TODO: to refactor, TxRunner already has access to executionContext // TODO: to refactor, TxRunner already has access to executionContext
detectNetwork: (cb) => { detectNetwork: (cb) => {
executionContext.detectNetwork(cb) this.executionContext.detectNetwork(cb)
}, },
personalMode: () => { personalMode: () => {
return executionContext.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false return this.executionContext.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false
} }
}) }, this.executionContext)
this.txRunner.event.register('transactionBroadcasted', (txhash) => { this.txRunner.event.register('transactionBroadcasted', (txhash) => {
executionContext.detectNetwork((error, network) => { this.executionContext.detectNetwork((error, network) => {
if (error || !network) return if (error || !network) return
this.event.trigger('transactionBroadcasted', [txhash, network.name]) this.event.trigger('transactionBroadcasted', [txhash, network.name])
}) })
@ -76,7 +78,7 @@ module.exports = class UniversalDApp {
*/ */
createVMAccount (newAccount) { createVMAccount (newAccount) {
const { privateKey, balance } = newAccount const { privateKey, balance } = newAccount
if (executionContext.getProvider() !== 'vm') { 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') throw new Error('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed')
} }
this._addAccount(privateKey, balance) this._addAccount(privateKey, balance)
@ -85,12 +87,12 @@ module.exports = class UniversalDApp {
} }
newAccount (password, passwordPromptCb, cb) { newAccount (password, passwordPromptCb, cb) {
if (!executionContext.isVM()) { if (!this.executionContext.isVM()) {
if (!this.config.get('settings/personal-mode')) { if (!this.config.get('settings/personal-mode')) {
return cb('Not running in personal mode') return cb('Not running in personal mode')
} }
passwordPromptCb((passphrase) => { passwordPromptCb((passphrase) => {
executionContext.web3().personal.newAccount(passphrase, cb) this.executionContext.web3().personal.newAccount(passphrase, cb)
}) })
} else { } else {
let privateKey let privateKey
@ -104,7 +106,7 @@ module.exports = class UniversalDApp {
/** Add an account to the list of account (only for Javascript VM) */ /** Add an account to the list of account (only for Javascript VM) */
_addAccount (privateKey, balance) { _addAccount (privateKey, balance) {
if (!executionContext.isVM()) { if (!this.executionContext.isVM()) {
throw new Error('_addAccount() cannot be called in non-VM mode') throw new Error('_addAccount() cannot be called in non-VM mode')
} }
@ -113,7 +115,7 @@ module.exports = class UniversalDApp {
const address = privateToAddress(privateKey) const address = privateToAddress(privateKey)
// FIXME: we don't care about the callback, but we should still make this proper // FIXME: we don't care about the callback, but we should still make this proper
let stateManager = executionContext.vm().stateManager let stateManager = this.executionContext.vm().stateManager
stateManager.getAccount(address, (error, account) => { stateManager.getAccount(address, (error, account) => {
if (error) return console.log(error) if (error) return console.log(error)
account.balance = balance || '0xf00000000000000001' account.balance = balance || '0xf00000000000000001'
@ -129,7 +131,7 @@ module.exports = class UniversalDApp {
/** Return the list of accounts */ /** Return the list of accounts */
getAccounts (cb) { getAccounts (cb) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const provider = executionContext.getProvider() const provider = this.executionContext.getProvider()
switch (provider) { switch (provider) {
case 'vm': { case 'vm': {
if (!this.accounts) { if (!this.accounts) {
@ -143,13 +145,13 @@ module.exports = class UniversalDApp {
break break
case 'web3': { case 'web3': {
if (this.config.get('settings/personal-mode')) { if (this.config.get('settings/personal-mode')) {
return executionContext.web3().personal.getListAccounts((error, accounts) => { return this.executionContext.web3().personal.getListAccounts((error, accounts) => {
if (cb) cb(error, accounts) if (cb) cb(error, accounts)
if (error) return reject(error) if (error) return reject(error)
resolve(accounts) resolve(accounts)
}) })
} else { } else {
executionContext.web3().eth.getAccounts((error, accounts) => { this.executionContext.web3().eth.getAccounts((error, accounts) => {
if (cb) cb(error, accounts) if (cb) cb(error, accounts)
if (error) return reject(error) if (error) return reject(error)
resolve(accounts) resolve(accounts)
@ -158,7 +160,7 @@ module.exports = class UniversalDApp {
} }
break break
case 'injected': { case 'injected': {
executionContext.web3().eth.getAccounts((error, accounts) => { this.executionContext.web3().eth.getAccounts((error, accounts) => {
if (cb) cb(error, accounts) if (cb) cb(error, accounts)
if (error) return reject(error) if (error) return reject(error)
resolve(accounts) resolve(accounts)
@ -172,8 +174,8 @@ module.exports = class UniversalDApp {
getBalance (address, cb) { getBalance (address, cb) {
address = stripHexPrefix(address) address = stripHexPrefix(address)
if (!executionContext.isVM()) { if (!this.executionContext.isVM()) {
executionContext.web3().eth.getBalance(address, (err, res) => { this.executionContext.web3().eth.getBalance(address, (err, res) => {
if (err) { if (err) {
cb(err) cb(err)
} else { } else {
@ -185,7 +187,7 @@ module.exports = class UniversalDApp {
return cb('No accounts?') return cb('No accounts?')
} }
executionContext.vm().stateManager.getAccount(Buffer.from(address, 'hex'), (err, res) => { this.executionContext.vm().stateManager.getAccount(Buffer.from(address, 'hex'), (err, res) => {
if (err) { if (err) {
cb('Account not found') cb('Account not found')
} else { } else {
@ -201,7 +203,7 @@ module.exports = class UniversalDApp {
if (error) { if (error) {
callback(error) callback(error)
} else { } else {
callback(null, executionContext.web3().utils.fromWei(balance, 'ether')) callback(null, this.executionContext.web3().fromWei(balance, 'ether'))
} }
}) })
} }
@ -240,7 +242,7 @@ module.exports = class UniversalDApp {
} }
context () { context () {
return (executionContext.isVM() ? 'memory' : 'blockchain') return (this.executionContext.isVM() ? 'memory' : 'blockchain')
} }
getABI (contract) { getABI (contract) {
@ -266,7 +268,7 @@ module.exports = class UniversalDApp {
*/ */
sendTransaction (tx) { sendTransaction (tx) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
executionContext.detectNetwork((error, network) => { this.executionContext.detectNetwork((error, network) => {
if (error) return reject(error) if (error) return reject(error)
if (network.name === 'Main' && network.id === '1') { if (network.name === 'Main' && network.id === '1') {
return reject(new Error('It is not allowed to make this action against mainnet')) return reject(new Error('It is not allowed to make this action against mainnet'))
@ -334,7 +336,7 @@ module.exports = class UniversalDApp {
if (err) return next(err) if (err) return next(err)
if (!address) return next('No accounts available') if (!address) return next('No accounts available')
if (executionContext.isVM() && !self.accounts[address]) { if (self.executionContext.isVM() && !self.accounts[address]) {
return next('Invalid account selected') return next('Invalid account selected')
} }
next(null, address, value, gasLimit) next(null, address, value, gasLimit)

@ -65,7 +65,7 @@ function processTx (executionContext, accounts, payload, isCall, callback) {
// let txRunner = new TxRunner(accounts, api) // let txRunner = new TxRunner(accounts, api)
if (!txRunnerInstance) { if (!txRunnerInstance) {
txRunnerInstance = new TxRunner(accounts, api) txRunnerInstance = new TxRunner(accounts, api, executionContext)
} }
txRunnerInstance.vmaccounts = accounts txRunnerInstance.vmaccounts = accounts
let { from, to, data, value, gas } = payload.params[0] let { from, to, data, value, gas } = payload.params[0]

Loading…
Cancel
Save