|
|
|
@ -1,16 +1,16 @@ |
|
|
|
|
'use strict' |
|
|
|
|
import Web3 from 'web3' |
|
|
|
|
import Web3, { Web3PluginBase } from 'web3' |
|
|
|
|
|
|
|
|
|
export function loadWeb3 (url) { |
|
|
|
|
if (!url) url = 'http://localhost:8545' |
|
|
|
|
const web3 = new Web3() |
|
|
|
|
web3.setProvider(new Web3.providers.HttpProvider(url)) |
|
|
|
|
extend(web3) |
|
|
|
|
web3.registerPlugin(new Web3DebugPlugin(web3)) |
|
|
|
|
return web3 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function extendWeb3 (web3) { |
|
|
|
|
extend(web3) |
|
|
|
|
web3.registerPlugin(new Web3DebugPlugin(web3)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function setProvider (web3, url) { |
|
|
|
@ -31,43 +31,40 @@ export function web3DebugNode (network) { |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function extend (web3) { |
|
|
|
|
if (!web3.extend) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
// DEBUG
|
|
|
|
|
const methods = [] |
|
|
|
|
if (!(web3.debug && web3.debug.preimage)) { |
|
|
|
|
methods.push(new web3.extend.Method({ |
|
|
|
|
name: 'preimage', |
|
|
|
|
call: 'debug_preimage', |
|
|
|
|
inputFormatter: [null], |
|
|
|
|
params: 1 |
|
|
|
|
})) |
|
|
|
|
class Web3DebugPlugin extends Web3PluginBase { |
|
|
|
|
public pluginNamespace = 'debug' |
|
|
|
|
|
|
|
|
|
private _web3; |
|
|
|
|
|
|
|
|
|
constructor(web3) { |
|
|
|
|
super() |
|
|
|
|
this._web3 = web3; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(web3.debug && web3.debug.traceTransaction)) { |
|
|
|
|
methods.push(new web3.extend.Method({ |
|
|
|
|
name: 'traceTransaction', |
|
|
|
|
call: 'debug_traceTransaction', |
|
|
|
|
inputFormatter: [null, null], |
|
|
|
|
params: 2 |
|
|
|
|
})) |
|
|
|
|
public preimage(key, cb) { |
|
|
|
|
this._web3.requestManager.send({ |
|
|
|
|
method: 'debug_preimage', |
|
|
|
|
params: [key] |
|
|
|
|
}) |
|
|
|
|
.then(result => cb(null, result)) |
|
|
|
|
.catch(error => cb(error)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(web3.debug && web3.debug.storageRangeAt)) { |
|
|
|
|
methods.push(new web3.extend.Method({ |
|
|
|
|
name: 'storageRangeAt', |
|
|
|
|
call: 'debug_storageRangeAt', |
|
|
|
|
inputFormatter: [null, null, null, null, null], |
|
|
|
|
params: 5 |
|
|
|
|
})) |
|
|
|
|
public traceTransaction(txHash, options, cb) { |
|
|
|
|
this._web3.requestManager.send({ |
|
|
|
|
method: 'debug_traceTransaction', |
|
|
|
|
params: [txHash, options] |
|
|
|
|
}) |
|
|
|
|
.then(result => cb(null, result)) |
|
|
|
|
.catch(error => cb(error)) |
|
|
|
|
} |
|
|
|
|
if (methods.length > 0) { |
|
|
|
|
web3.extend({ |
|
|
|
|
property: 'debug', |
|
|
|
|
methods: methods, |
|
|
|
|
properties: [] |
|
|
|
|
|
|
|
|
|
public storageRangeAt(txBlockHash, txIndex, address, start, maxSize, cb) { |
|
|
|
|
this._web3.requestManager.send({ |
|
|
|
|
method: 'debug_storageRangeAt', |
|
|
|
|
params: [txBlockHash, txIndex, address, start, maxSize] |
|
|
|
|
}) |
|
|
|
|
.then(result => cb(null, result)) |
|
|
|
|
.catch(error => cb(error)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|