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.
77 lines
1.8 KiB
77 lines
1.8 KiB
9 years ago
|
'use strict'
|
||
5 years ago
|
const Web3 = require('web3')
|
||
7 years ago
|
|
||
9 years ago
|
module.exports = {
|
||
7 years ago
|
loadWeb3: function (url) {
|
||
|
if (!url) url = 'http://localhost:8545'
|
||
5 years ago
|
const web3 = new Web3()
|
||
7 years ago
|
web3.setProvider(new web3.providers.HttpProvider(url))
|
||
7 years ago
|
this.extend(web3)
|
||
|
return web3
|
||
|
},
|
||
|
|
||
|
extendWeb3: function (web3) {
|
||
|
this.extend(web3)
|
||
|
},
|
||
|
|
||
|
setProvider: function (web3, url) {
|
||
|
web3.setProvider(new web3.providers.HttpProvider(url))
|
||
|
},
|
||
|
|
||
7 years ago
|
web3DebugNode: function (network) {
|
||
|
if (web3DebugNodes[network]) {
|
||
|
return this.loadWeb3(web3DebugNodes[network])
|
||
|
}
|
||
|
return null
|
||
|
},
|
||
|
|
||
9 years ago
|
extend: function (web3) {
|
||
5 years ago
|
if (!web3.extend) {
|
||
8 years ago
|
return
|
||
|
}
|
||
9 years ago
|
// DEBUG
|
||
5 years ago
|
const methods = []
|
||
8 years ago
|
if (!(web3.debug && web3.debug.preimage)) {
|
||
5 years ago
|
methods.push(new web3.extend.Method({
|
||
8 years ago
|
name: 'preimage',
|
||
|
call: 'debug_preimage',
|
||
|
inputFormatter: [null],
|
||
|
params: 1
|
||
|
}))
|
||
|
}
|
||
|
|
||
8 years ago
|
if (!(web3.debug && web3.debug.traceTransaction)) {
|
||
5 years ago
|
methods.push(new web3.extend.Method({
|
||
8 years ago
|
name: 'traceTransaction',
|
||
|
call: 'debug_traceTransaction',
|
||
|
inputFormatter: [null, null],
|
||
|
params: 2
|
||
|
}))
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
if (!(web3.debug && web3.debug.storageRangeAt)) {
|
||
5 years ago
|
methods.push(new web3.extend.Method({
|
||
8 years ago
|
name: 'storageRangeAt',
|
||
|
call: 'debug_storageRangeAt',
|
||
8 years ago
|
inputFormatter: [null, null, null, null, null],
|
||
|
params: 5
|
||
8 years ago
|
}))
|
||
|
}
|
||
|
if (methods.length > 0) {
|
||
5 years ago
|
web3.extend({
|
||
8 years ago
|
property: 'debug',
|
||
|
methods: methods,
|
||
|
properties: []
|
||
|
})
|
||
|
}
|
||
9 years ago
|
}
|
||
|
}
|
||
7 years ago
|
|
||
5 years ago
|
const web3DebugNodes = {
|
||
5 years ago
|
'Main': 'https://gethmainnet.komputing.org',
|
||
5 years ago
|
'Rinkeby': 'https://remix-rinkeby.ethdevops.io',
|
||
|
'Ropsten': 'https://remix-ropsten.ethdevops.io',
|
||
|
'Goerli': 'https://remix-goerli.ethdevops.io',
|
||
|
'Kovan': 'https://remix-kovan.ethdevops.io'
|
||
7 years ago
|
}
|