move execution-context

pull/747/head
yann300 4 years ago
parent aefc8975b2
commit c77a3e109b
  1. 4
      apps/remix-ide/src/blockchain/blockchain.js
  2. 39
      apps/remix-ide/src/blockchain/execution-context.js
  3. 3
      libs/remix-lib/src/execution/txListener.ts
  4. 2
      libs/remix-lib/src/index.ts
  5. 3
      libs/remix-lib/test/txFormat.ts

@ -7,7 +7,7 @@ const TxRunner = remixLib.execution.TxRunner
const TxRunnerWeb3 = remixLib.execution.TxRunnerWeb3
const txHelper = remixLib.execution.txHelper
const EventManager = remixLib.EventManager
const executionContext = remixLib.execution.executionContext
const { ExecutionContext } = require('./execution-context')
const Web3 = require('web3')
const async = require('async')
@ -23,7 +23,7 @@ class Blockchain {
// NOTE: the config object will need to be refactored out in remix-lib
constructor (config) {
this.event = new EventManager()
this.executionContext = executionContext
this.executionContext = new ExecutionContext()
this.events = new EventEmitter()
this.config = config

@ -1,19 +1,17 @@
/* global ethereum */
'use strict'
import Web3 from 'web3'
import { EventManager } from '../eventManager'
import EventManager from '../lib/events'
import { rlp, keccak, bufferToHex } from 'ethereumjs-util'
import { Web3VmProvider } from '../web3Provider/web3VmProvider'
import VM from '@ethereumjs/vm'
import Common from '@ethereumjs/common'
import StateManager from '@ethereumjs/vm/dist/state/stateManager'
import { StorageDump } from '@ethereumjs/vm/dist/state/interface'
declare let ethereum: any
let web3
if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined') {
var injectedProvider = window['ethereum']
if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined') {
var injectedProvider = window.ethereum
web3 = new Web3(injectedProvider)
} else {
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
@ -24,12 +22,13 @@ if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined')
*/
class StateManagerCommonStorageDump extends StateManager {
/*
* dictionary containing keccak(b) as key and b as value. used to get the initial value from its hash
*/
keyHashes: { [key: string]: string }
constructor () {
super()
/*
* dictionary containing keccak(b) as key and b as value. used to get the initial value from its hash.
* type: { [key: string]: string }
*/
this.keyHashes = {}
}
@ -46,7 +45,7 @@ class StateManagerCommonStorageDump extends StateManager {
console.log(e)
throw e
}
return new Promise<StorageDump>((resolve, reject) => {
return new Promise((resolve, reject) => {
try {
const storage = {}
const stream = trie.createReadStream()
@ -66,14 +65,14 @@ class StateManagerCommonStorageDump extends StateManager {
})
}
async getStateRoot (force: boolean = false): Promise<Buffer> {
async getStateRoot (force = false) {
await this._cache.flush()
const stateRoot = this._trie.root
return stateRoot
}
async setStateRoot (stateRoot: Buffer): Promise<void> {
async setStateRoot (stateRoot) {
await this._cache.flush()
if (stateRoot === this._trie.EMPTY_TRIE_ROOT) {
@ -98,20 +97,6 @@ class StateManagerCommonStorageDump extends StateManager {
trigger contextChanged, web3EndpointChanged
*/
export class ExecutionContext {
event
blockGasLimitDefault: number
blockGasLimit: number
customNetWorks
blocks
latestBlockNumber
txs
executionContext: string
listenOnLastBlockId
currentFork: string
vms
mainNetGenesisHash: string
customWeb3: { [key: string]: Web3 }
constructor () {
this.event = new EventManager()
this.executionContext = null
@ -171,7 +156,7 @@ export class ExecutionContext {
return this.executionContext === 'vm'
}
setWeb3 (context: string, web3: Web3) {
setWeb3 (context, web3) {
this.customWeb3[context] = web3
}

@ -4,7 +4,6 @@ import { ethers } from 'ethers'
import { toBuffer } from 'ethereumjs-util'
import { EventManager } from '../eventManager'
import { compareByteCode } from '../util'
import { ExecutionContext } from './execution-context'
import { decodeResponse } from './txFormat'
import { getFunction, getReceiveInterface, getConstructorInterface, visitContracts, makeFullTypeDefinition } from './txHelper'
@ -40,7 +39,7 @@ export class TxListener {
constructor (opt, executionContext) {
this.event = new EventManager()
// has a default for now for backwards compatability
this.executionContext = executionContext || new ExecutionContext()
this.executionContext = executionContext
this._api = opt.api
this._resolvedTransactions = {}
this._resolvedContracts = {}

@ -13,7 +13,6 @@ import * as txFormat from './execution/txFormat'
import { TxListener } from './execution/txListener'
import { TxRunner } from './execution/txRunner'
import { LogsManager } from './execution/logsManager'
import { ExecutionContext } from './execution/execution-context'
import * as typeConversion from './execution/typeConversion'
import { TxRunnerVM } from './execution/txRunnerVM'
import { TxRunnerWeb3 } from './execution/txRunnerWeb3'
@ -40,7 +39,6 @@ function modules () {
EventsDecoder: EventsDecoder,
txExecution: txExecution,
txHelper: txHelper,
executionContext: new ExecutionContext(),
txFormat: txFormat,
txListener: TxListener,
TxRunner: TxRunner,

@ -5,8 +5,6 @@ import * as txHelper from '../src/execution/txHelper'
import { hexToIntArray } from '../src/util'
let compiler = require('solc')
import { compilerInput } from '../src/helpers/compilerHelper'
import { ExecutionContext } from '../src/execution/execution-context'
const executionContext = new ExecutionContext()
const solidityVersion = 'v0.6.0+commit.26b70077'
/* tape *********************************************************** */
@ -151,7 +149,6 @@ function testInvalidTupleInput (st, params) {
/* tape *********************************************************** */
tape('ContractParameters - (TxFormat.buildData) - link Libraries', function (t) {
executionContext.setContext('vm', null, null, null)
const compileData = compiler.compile(compilerInput(deploySimpleLib))
const fakeDeployedContracts = {

Loading…
Cancel
Save