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-lib/src/init.ts

48 lines
1.2 KiB

9 years ago
'use strict'
import Web3, { Web3PluginBase } from 'web3'
1 year ago
import {toNumber} from 'web3-utils'
7 years ago
1 year ago
export function extendWeb3 (web3) {
if(!web3.debug){
web3.registerPlugin(new Web3DebugPlugin())
}
}
export function loadWeb3 (url = 'http://localhost:8545') {
const web3 = new Web3()
web3.setProvider(new Web3.providers.HttpProvider(url))
1 year ago
extendWeb3(web3)
return web3
}
7 years ago
class Web3DebugPlugin extends Web3PluginBase {
public pluginNamespace = 'debug'
public preimage(key, cb) {
this.requestManager.send({
method: 'debug_preimage',
params: [key]
})
1 year ago
.then(result => cb(null, result))
.catch(error => cb(error))
4 years ago
}
public traceTransaction(txHash, options, cb) {
this.requestManager.send({
method: 'debug_traceTransaction',
params: [txHash, options]
})
1 year ago
.then(result => cb(null, result))
.catch(error => cb(error))
9 years ago
}
public storageRangeAt(txBlockHash, txIndex, address, start, maxSize, cb) {
this.requestManager.send({
method: 'debug_storageRangeAt',
1 year ago
params: [txBlockHash, toNumber(txIndex), address, start, maxSize]
4 years ago
})
1 year ago
.then(result => cb(null, result))
.catch(error => cb(error))
4 years ago
}
}