remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/libs/remix-debug/src/init.ts

71 lines
1.8 KiB

'use strict'
import Web3, { Web3PluginBase } from 'web3'
4 years ago
export function loadWeb3 (url) {
if (!url) url = 'http://localhost:8545'
const web3 = new Web3()
web3.setProvider(new Web3.providers.HttpProvider(url))
web3.registerPlugin(new Web3DebugPlugin(web3))
4 years ago
return web3
}
4 years ago
export function extendWeb3 (web3) {
web3.registerPlugin(new Web3DebugPlugin(web3))
4 years ago
}
4 years ago
export function setProvider (web3, url) {
web3.setProvider(new web3.providers.HttpProvider(url))
}
4 years ago
export function web3DebugNode (network) {
const web3DebugNodes = {
Main: 'https://rpc.archivenode.io/e50zmkroshle2e2e50zm0044i7ao04ym',
Rinkeby: 'https://remix-rinkeby.ethdevops.io',
Ropsten: 'https://remix-ropsten.ethdevops.io',
2 years ago
Goerli: 'https://remix-goerli.ethdevops.io',
Sepolia: 'https://remix-sepolia.ethdevops.io'
4 years ago
}
if (web3DebugNodes[network]) {
return loadWeb3(web3DebugNodes[network])
}
return null
}
class Web3DebugPlugin extends Web3PluginBase {
public pluginNamespace = 'debug'
private _web3;
constructor(web3) {
super()
this._web3 = web3;
4 years ago
}
public preimage(key, cb) {
this._web3.requestManager.send({
method: 'debug_preimage',
params: [key]
})
.then(result => cb(null, result))
.catch(error => cb(error))
4 years ago
}
public traceTransaction(txHash, options, cb) {
this._web3.requestManager.send({
method: 'debug_traceTransaction',
params: [txHash, options]
})
.then(result => cb(null, result))
.catch(error => cb(error))
4 years ago
}
public storageRangeAt(txBlockHash, txIndex, address, start, maxSize, cb) {
this._web3.requestManager.send({
method: 'debug_storageRangeAt',
params: [txBlockHash, txIndex, address, start, maxSize]
4 years ago
})
.then(result => cb(null, result))
.catch(error => cb(error))
}
}