type defs and execution context updated

toaster-react
aniket-engg 4 years ago committed by Aniket
parent d2f744aa4b
commit 982ba9f4a7
  1. 10
      libs/remix-lib/src/execution/eventsDecoder.ts
  2. 76
      libs/remix-lib/src/execution/execution-context.ts

@ -38,8 +38,8 @@ export class EventsDecoder {
this._decodeEvents(tx, receipt.logs, contract, contracts, cb) this._decodeEvents(tx, receipt.logs, contract, contracts, cb)
} }
_eventABI (contract) { _eventABI (contract): Record<string, unknown> {
const eventABI = {} const eventABI: Record<string, unknown> = {}
const abi = new ethers.utils.Interface(contract.abi) const abi = new ethers.utils.Interface(contract.abi)
for (const e in abi.events) { for (const e in abi.events) {
const event = abi.getEvent(e) const event = abi.getEvent(e)
@ -48,8 +48,8 @@ export class EventsDecoder {
return eventABI return eventABI
} }
_eventsABI (compiledContracts) { _eventsABI (compiledContracts): Record<string, unknown> {
const eventsABI = {} const eventsABI: Record<string, unknown> = {}
visitContracts(compiledContracts, (contract) => { visitContracts(compiledContracts, (contract) => {
eventsABI[contract.name] = this._eventABI(contract.object) eventsABI[contract.name] = this._eventABI(contract.object)
}) })
@ -72,7 +72,7 @@ export class EventsDecoder {
return null return null
} }
_stringifyBigNumber (value) { _stringifyBigNumber (value): string {
return value._isBigNumber ? value.toString() : value return value._isBigNumber ? value.toString() : value
} }

@ -4,13 +4,13 @@ import Web3 from 'web3'
import { EventManager } from '../eventManager' import { EventManager } from '../eventManager'
import { rlp, keccak, bufferToHex } from 'ethereumjs-util' import { rlp, keccak, bufferToHex } from 'ethereumjs-util'
import { Web3VmProvider } from '../web3Provider/web3VmProvider' import { Web3VmProvider } from '../web3Provider/web3VmProvider'
import { LogsManager } from './logsManager'
const EthJSVM = require('ethereumjs-vm').default const EthJSVM = require('ethereumjs-vm').default
const StateManager = require('ethereumjs-vm/dist/state/stateManager').default const StateManager = require('ethereumjs-vm/dist/state/stateManager').default
import { LogsManager } from './logsManager'
declare let ethereum: any declare let ethereum: any
let web3 let web3
if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined') { if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined') {
var injectedProvider = window['ethereum'] var injectedProvider = window['ethereum']
web3 = new Web3(injectedProvider) web3 = new Web3(injectedProvider)
@ -18,8 +18,6 @@ if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined')
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')) web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
} }
const blankWeb3 = new Web3()
const currentFork = 'muirGlacier'
/* /*
extend vm state manager and instanciate VM extend vm state manager and instanciate VM
*/ */
@ -74,33 +72,6 @@ class StateManagerCommonStorageDump extends StateManager {
} }
} }
function createVm (hardfork) {
const stateManager = new StateManagerCommonStorageDump({})
stateManager.checkpoint(() => {})
const vm = new EthJSVM({
activatePrecompiles: true,
blockchain: stateManager.blockchain,
stateManager: stateManager,
hardfork: hardfork
})
vm.blockchain.validate = false
const web3vm = new Web3VmProvider()
web3vm.setVM(vm)
return { vm, web3vm, stateManager }
}
const vms = {
/*
byzantium: createVm('byzantium'),
constantinople: createVm('constantinople'),
petersburg: createVm('petersburg'),
istanbul: createVm('istanbul'),
*/
muirGlacier: createVm('muirGlacier')
}
const mainNetGenesisHash = '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'
/* /*
trigger contextChanged, web3EndpointChanged trigger contextChanged, web3EndpointChanged
*/ */
@ -115,6 +86,9 @@ export class ExecutionContext {
txs txs
executionContext executionContext
listenOnLastBlockId listenOnLastBlockId
currentFork: string
vms
mainNetGenesisHash: string
constructor () { constructor () {
this.event = new EventManager() this.event = new EventManager()
@ -122,6 +96,17 @@ export class ExecutionContext {
this.executionContext = null this.executionContext = null
this.blockGasLimitDefault = 4300000 this.blockGasLimitDefault = 4300000
this.blockGasLimit = this.blockGasLimitDefault this.blockGasLimit = this.blockGasLimitDefault
this.currentFork = 'muirGlacier'
this.vms = {
/*
byzantium: createVm('byzantium'),
constantinople: createVm('constantinople'),
petersburg: createVm('petersburg'),
istanbul: createVm('istanbul'),
*/
muirGlacier: this.createVm('muirGlacier')
}
this.mainNetGenesisHash = '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'
this.customNetWorks = {} this.customNetWorks = {}
this.blocks = {} this.blocks = {}
this.latestBlockNumber = 0 this.latestBlockNumber = 0
@ -137,6 +122,21 @@ export class ExecutionContext {
} }
} }
createVm (hardfork) {
const stateManager = new StateManagerCommonStorageDump({})
stateManager.checkpoint(() => {})
const vm = new EthJSVM({
activatePrecompiles: true,
blockchain: stateManager.blockchain,
stateManager: stateManager,
hardfork: hardfork
})
vm.blockchain.validate = false
const web3vm = new Web3VmProvider()
web3vm.setVM(vm)
return { vm, web3vm, stateManager }
}
askPermission () { askPermission () {
// metamask // metamask
if (ethereum && typeof ethereum.enable === 'function') ethereum.enable() if (ethereum && typeof ethereum.enable === 'function') ethereum.enable()
@ -151,10 +151,10 @@ export class ExecutionContext {
} }
web3 () { web3 () {
return this.isVM() ? vms[currentFork].web3vm : web3 return this.isVM() ? this.vms[this.currentFork].web3vm : web3
} }
detectNetwork = function (callback) { detectNetwork (callback) {
if (this.isVM()) { if (this.isVM()) {
callback(null, { id: '-', name: 'VM' }) callback(null, { id: '-', name: 'VM' })
} else { } else {
@ -173,7 +173,7 @@ export class ExecutionContext {
if (id === '1') { if (id === '1') {
web3.eth.getBlock(0, (error, block) => { web3.eth.getBlock(0, (error, block) => {
if (error) console.log('cant query first block') if (error) console.log('cant query first block')
if (block && block.hash !== mainNetGenesisHash) name = 'Custom' if (block && block.hash !== this.mainNetGenesisHash) name = 'Custom'
callback(err, { id, name }) callback(err, { id, name })
}) })
} else { } else {
@ -203,11 +203,11 @@ export class ExecutionContext {
} }
blankWeb3 () { blankWeb3 () {
return blankWeb3 return new Web3()
} }
vm () { vm () {
return vms[currentFork].vm return this.vms[this.currentFork].vm
} }
setContext (context, endPointUrl, confirmCb, infoCb) { setContext (context, endPointUrl, confirmCb, infoCb) {
@ -221,8 +221,8 @@ export class ExecutionContext {
if (!infoCb) infoCb = () => {} if (!infoCb) infoCb = () => {}
if (context === 'vm') { if (context === 'vm') {
this.executionContext = context this.executionContext = context
vms[currentFork].stateManager.revert(() => { this.vms[this.currentFork].stateManager.revert(() => {
vms[currentFork].stateManager.checkpoint(() => {}) this.vms[this.currentFork].stateManager.checkpoint(() => {})
}) })
this.event.trigger('contextChanged', ['vm']) this.event.trigger('contextChanged', ['vm'])
return cb() return cb()

Loading…
Cancel
Save