|
|
@ -2,6 +2,8 @@ import Web3, { FMT_BYTES, FMT_NUMBER, LegacySendAsyncProvider } from 'web3' |
|
|
|
import { fromWei, toBigInt } from 'web3-utils' |
|
|
|
import { fromWei, toBigInt } from 'web3-utils' |
|
|
|
import { privateToAddress, hashPersonalMessage, isHexString } from '@ethereumjs/util' |
|
|
|
import { privateToAddress, hashPersonalMessage, isHexString } from '@ethereumjs/util' |
|
|
|
import { extend, JSONRPCRequestPayload, JSONRPCResponseCallback } from '@remix-project/remix-simulator' |
|
|
|
import { extend, JSONRPCRequestPayload, JSONRPCResponseCallback } from '@remix-project/remix-simulator' |
|
|
|
|
|
|
|
import {toBuffer} from '@ethereumjs/util' |
|
|
|
|
|
|
|
import { Block } from '@ethereumjs/block' |
|
|
|
import { ExecutionContext } from '../execution-context' |
|
|
|
import { ExecutionContext } from '../execution-context' |
|
|
|
|
|
|
|
|
|
|
|
export class VMProvider { |
|
|
|
export class VMProvider { |
|
|
@ -27,7 +29,7 @@ export class VMProvider { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async resetEnvironment (stringifiedStateDb?: string) { |
|
|
|
async resetEnvironment (stringifiedState?: string) { |
|
|
|
if (this.worker) this.worker.terminate() |
|
|
|
if (this.worker) this.worker.terminate() |
|
|
|
this.worker = new Worker(new URL('./worker-vm', import.meta.url)) |
|
|
|
this.worker = new Worker(new URL('./worker-vm', import.meta.url)) |
|
|
|
const provider = this.executionContext.getProviderObject() |
|
|
|
const provider = this.executionContext.getProviderObject() |
|
|
@ -74,13 +76,35 @@ export class VMProvider { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.worker.postMessage({ |
|
|
|
if (stringifiedState) { |
|
|
|
cmd: 'init', |
|
|
|
try { |
|
|
|
fork: this.executionContext.getCurrentFork(), |
|
|
|
const blockchainState = JSON.parse(stringifiedState) |
|
|
|
nodeUrl: provider?.options['nodeUrl'], |
|
|
|
const blocks: Block[] = blockchainState.blocks.map(block => Block.fromRLPSerializedBlock(toBuffer(block))) |
|
|
|
blockNumber: provider?.options['blockNumber'], |
|
|
|
const blockNumber = toBigInt(blockchainState.latestBlockNumber).toString(10) |
|
|
|
stateDb: stringifiedStateDb |
|
|
|
const stateDb = {
|
|
|
|
}) |
|
|
|
root: toBuffer(blockchainState.root), |
|
|
|
|
|
|
|
db: new Map(Object.entries(blockchainState.db)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.worker.postMessage({ |
|
|
|
|
|
|
|
cmd: 'init', |
|
|
|
|
|
|
|
fork: this.executionContext.getCurrentFork(), |
|
|
|
|
|
|
|
nodeUrl: provider?.options['nodeUrl'], |
|
|
|
|
|
|
|
blockNumber, |
|
|
|
|
|
|
|
stateDb, |
|
|
|
|
|
|
|
blocks |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
console.error(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.worker.postMessage({ |
|
|
|
|
|
|
|
cmd: 'init', |
|
|
|
|
|
|
|
fork: this.executionContext.getCurrentFork(), |
|
|
|
|
|
|
|
nodeUrl: provider?.options['nodeUrl'], |
|
|
|
|
|
|
|
blockNumber: provider?.options['blockNumber'] |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|