Implement fetching blocks data

pull/4529/head
ioedeveloper 9 months ago
parent ff7da80f29
commit 639a6cca09
  1. 9
      apps/remix-ide/src/blockchain/execution-context.js
  2. 7
      libs/remix-lib/src/execution/txRunnerVM.ts
  3. 12
      libs/remix-simulator/src/methods/transactions.ts
  4. 7
      libs/remix-simulator/src/provider.ts

@ -210,16 +210,21 @@ export class ExecutionContext {
// TODO: this won't save the state for transactions executed outside of the UI (for instance from a script execution).
const root = await this.web3().remix.getStateTrieRoot()
const db = await this.web3().remix.getStateDb()
const blocksData = await this.web3().remix.getBlocksData()
const state = {
root,
db: Object.fromEntries(db._database)
db: Object.fromEntries(db._database),
blocks: blocksData.blocks,
latestBlockNumber: blocksData.latestBlockNumber
}
const stringifyed = JSON.stringify(state, (key, value) => {
if (key === 'root') {
return bufferToHex(value)
} else if (key === 'db') {
return value
} else if (key === '') {
} else if (key === 'blocks') {
return value.map(block => bufferToHex(block))
}else if (key === '') {
return value
}
return bufferToHex(value)

@ -37,7 +37,7 @@ export class TxRunnerVM {
// has a default for now for backwards compatibility
this.getVMObject = getVMObject
this.commonContext = this.getVMObject().common
this.blockNumber = blockNumber || 0
this.blockNumber = blockNumber || 0 // TODO: this should be set to the fetched block number count
this.pendingTxs = {}
this.vmaccounts = vmaccounts
this.queusTxs = []
@ -125,7 +125,10 @@ export class TxRunnerVM {
this.blockNumber = this.blockNumber + 1
this.blockParentHash = block.hash()
this.runBlockInVm(tx, block, (err, result) => {
if (!err) this.getVMObject().vm.blockchain.putBlock(block) // look at putBlock for saving blocks
if (!err) {
this.getVMObject().vm.blockchain.putBlock(block)
this.blocks.push(block.serialize())
}
callback(err, result)
})
} else {

@ -59,7 +59,7 @@ export class Transactions {
this.txRunnerInstance = new TxRunner(this.txRunnerVMInstance, {})
this.txRunnerInstance.vmaccounts = accounts
}
methods () {
return {
eth_sendTransaction: this.eth_sendTransaction.bind(this),
@ -76,7 +76,8 @@ export class Transactions {
eth_getHashFromTagBySimulator: this.eth_getHashFromTagBySimulator.bind(this),
eth_registerCallId: this.eth_registerCallId.bind(this),
eth_getStateTrieRoot: this.eth_getStateTrieRoot.bind(this),
eth_getStateDb: this.eth_getStateDb.bind(this)
eth_getStateDb: this.eth_getStateDb.bind(this),
eth_getBlocksData: this.eth_getBlocksData.bind(this)
}
}
@ -208,6 +209,13 @@ export class Transactions {
cb(null, this.vmContext.currentVm.stateManager.getDb())
}
eth_getBlocksData (_, cb) {
cb(null, {
blocks: this.txRunnerVMInstance.blocks,
latestBlockNumber: this.txRunnerVMInstance.blockNumber
})
}
eth_call (payload, cb) {
// from might be lowercased address (web3)
if (payload.params && payload.params.length > 0 && payload.params[0].from) {

@ -195,4 +195,11 @@ class Web3TestPlugin extends Web3PluginBase {
params: []
})
}
public getBlocksData() {
return this.requestManager.send({
method: 'eth_getBlocksData',
params: []
})
}
}

Loading…
Cancel
Save