diff --git a/libs/remix-simulator/src/methods/transactions.ts b/libs/remix-simulator/src/methods/transactions.ts index 969eb0ff6f..ef72acfe09 100644 --- a/libs/remix-simulator/src/methods/transactions.ts +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -1,11 +1,16 @@ import Web3 from 'web3' import { toChecksumAddress, BN, Address } from 'ethereumjs-util' import { processTx } from './txProcess' +import { execution } from '@remix-project/remix-lib' +const TxRunnerVM = execution.TxRunnerVM +const TxRunner = execution.TxRunner export class Transactions { vmContext accounts tags + txRunnerVMInstance + txRunnerInstance constructor (vmContext) { this.vmContext = vmContext @@ -14,6 +19,30 @@ export class Transactions { init (accounts) { this.accounts = accounts + const api = { + logMessage: (msg) => { + }, + logHtmlMessage: (msg) => { + }, + config: { + getUnpersistedProperty: (key) => { + return true + }, + get: () => { + return true + } + }, + detectNetwork: (cb) => { + cb() + }, + personalMode: () => { + return false + } + } + + this.txRunnerVMInstance = new TxRunnerVM(accounts, api, _ => this.vmContext.vm()) + this.txRunnerInstance = new TxRunner(this.txRunnerVMInstance, { runAsync: false }) + this.txRunnerInstance.vmaccounts = accounts } methods () { @@ -37,7 +66,7 @@ export class Transactions { if (payload.params && payload.params.length > 0 && payload.params[0].from) { payload.params[0].from = toChecksumAddress(payload.params[0].from) } - processTx(this.vmContext, this.accounts, payload, false, (error, result) => { + processTx(this.txRunnerInstance, payload, false, (error, result) => { if (!error && result) { this.vmContext.addBlock(result.block) const hash = '0x' + result.tx.hash().toString('hex') @@ -112,7 +141,7 @@ export class Transactions { const tag = payload.params[0].timestamp // e2e reference - processTx(this.vmContext, this.accounts, payload, true, (error, result) => { + processTx(this.txRunnerInstance, payload, true, (error, result) => { if (!error && result) { this.vmContext.addBlock(result.block) const hash = '0x' + result.tx.hash().toString('hex') diff --git a/libs/remix-simulator/src/methods/txProcess.ts b/libs/remix-simulator/src/methods/txProcess.ts index d51bbf9c73..75173af309 100644 --- a/libs/remix-simulator/src/methods/txProcess.ts +++ b/libs/remix-simulator/src/methods/txProcess.ts @@ -1,7 +1,5 @@ import { execution } from '@remix-project/remix-lib' const TxExecution = execution.txExecution -const TxRunnerVM = execution.TxRunnerVM -const TxRunner = execution.TxRunner function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) { const finalCallback = function (err, result) { @@ -36,38 +34,7 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac TxExecution.createContract(from, data, value, gasLimit, txRunner, callbacks, finalCallback) } -let txRunnerVMInstance -let txRunnerInstance - -export function processTx (vmContext, accounts, payload, isCall, callback) { - const api = { - logMessage: (msg) => { - }, - logHtmlMessage: (msg) => { - }, - config: { - getUnpersistedProperty: (key) => { - return true - }, - get: () => { - return true - } - }, - detectNetwork: (cb) => { - cb() - }, - personalMode: () => { - return false - } - } - - if (!txRunnerVMInstance) { - txRunnerVMInstance = new TxRunnerVM(accounts, api, _ => vmContext.vm()) - } - if (!txRunnerInstance) { - txRunnerInstance = new TxRunner(txRunnerVMInstance, { runAsync: false }) - } - txRunnerInstance.vmaccounts = accounts +export function processTx (txRunnerInstance, payload, isCall, callback) { let { from, to, data, value, gas } = payload.params[0] gas = gas || 3000000