diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 09ca8a05a2..973e267683 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -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 diff --git a/libs/remix-lib/src/execution/execution-context.ts b/apps/remix-ide/src/blockchain/execution-context.js similarity index 90% rename from libs/remix-lib/src/execution/execution-context.ts rename to apps/remix-ide/src/blockchain/execution-context.js index 7644081040..df2d9421bb 100644 --- a/libs/remix-lib/src/execution/execution-context.ts +++ b/apps/remix-ide/src/blockchain/execution-context.js @@ -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((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 { + async getStateRoot (force = false) { await this._cache.flush() const stateRoot = this._trie.root return stateRoot } - async setStateRoot (stateRoot: Buffer): Promise { + 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 } diff --git a/libs/remix-lib/src/execution/txListener.ts b/libs/remix-lib/src/execution/txListener.ts index 967b8ee3a8..2ec85c3fc9 100644 --- a/libs/remix-lib/src/execution/txListener.ts +++ b/libs/remix-lib/src/execution/txListener.ts @@ -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 = {} diff --git a/libs/remix-lib/src/index.ts b/libs/remix-lib/src/index.ts index afcd0beae6..ae3864a8c9 100644 --- a/libs/remix-lib/src/index.ts +++ b/libs/remix-lib/src/index.ts @@ -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, diff --git a/libs/remix-lib/test/txFormat.ts b/libs/remix-lib/test/txFormat.ts index 2ab4a59b63..8bff069fc2 100644 --- a/libs/remix-lib/test/txFormat.ts +++ b/libs/remix-lib/test/txFormat.ts @@ -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 = {