remove uneeded execution-context reference

pull/747/head
yann300 4 years ago
parent c77a3e109b
commit 165bc81cd0
  1. 33
      libs/remix-simulator/src/methods/transactions.ts
  2. 35
      libs/remix-simulator/src/methods/txProcess.ts

@ -1,11 +1,16 @@
import Web3 from 'web3' import Web3 from 'web3'
import { toChecksumAddress, BN, Address } from 'ethereumjs-util' import { toChecksumAddress, BN, Address } from 'ethereumjs-util'
import { processTx } from './txProcess' import { processTx } from './txProcess'
import { execution } from '@remix-project/remix-lib'
const TxRunnerVM = execution.TxRunnerVM
const TxRunner = execution.TxRunner
export class Transactions { export class Transactions {
vmContext vmContext
accounts accounts
tags tags
txRunnerVMInstance
txRunnerInstance
constructor (vmContext) { constructor (vmContext) {
this.vmContext = vmContext this.vmContext = vmContext
@ -14,6 +19,30 @@ export class Transactions {
init (accounts) { init (accounts) {
this.accounts = 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 () { methods () {
@ -37,7 +66,7 @@ export class Transactions {
if (payload.params && payload.params.length > 0 && payload.params[0].from) { if (payload.params && payload.params.length > 0 && payload.params[0].from) {
payload.params[0].from = toChecksumAddress(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) { if (!error && result) {
this.vmContext.addBlock(result.block) this.vmContext.addBlock(result.block)
const hash = '0x' + result.tx.hash().toString('hex') const hash = '0x' + result.tx.hash().toString('hex')
@ -112,7 +141,7 @@ export class Transactions {
const tag = payload.params[0].timestamp // e2e reference 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) { if (!error && result) {
this.vmContext.addBlock(result.block) this.vmContext.addBlock(result.block)
const hash = '0x' + result.tx.hash().toString('hex') const hash = '0x' + result.tx.hash().toString('hex')

@ -1,7 +1,5 @@
import { execution } from '@remix-project/remix-lib' import { execution } from '@remix-project/remix-lib'
const TxExecution = execution.txExecution const TxExecution = execution.txExecution
const TxRunnerVM = execution.TxRunnerVM
const TxRunner = execution.TxRunner
function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) { function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) {
const finalCallback = function (err, result) { 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) TxExecution.createContract(from, data, value, gasLimit, txRunner, callbacks, finalCallback)
} }
let txRunnerVMInstance export function processTx (txRunnerInstance, payload, isCall, callback) {
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
let { from, to, data, value, gas } = payload.params[0] let { from, to, data, value, gas } = payload.params[0]
gas = gas || 3000000 gas = gas || 3000000

Loading…
Cancel
Save