From 7bef3013e3959f831aa6185a5278d61096bd6880 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 2 Mar 2018 09:52:47 +0100 Subject: [PATCH] add debug node ref --- remix-core/src/storage/mappingPreimages.js | 2 +- remix-core/src/storage/storageResolver.js | 2 +- remix-core/src/trace/traceRetriever.js | 2 +- remix-debugger/src/ui/Ethdebugger.js | 10 ++++++++++ remix-lib/src/global.js | 3 ++- remix-lib/src/init.js | 16 ++++++++++++++-- 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/remix-core/src/storage/mappingPreimages.js b/remix-core/src/storage/mappingPreimages.js index b55b5f4cc2..522b83ec8c 100644 --- a/remix-core/src/storage/mappingPreimages.js +++ b/remix-core/src/storage/mappingPreimages.js @@ -44,7 +44,7 @@ async function decodeMappingsKeys (storage, callback) { */ function getPreimage (key) { return new Promise((resolve, reject) => { - global.web3.debug.preimage(key.indexOf('0x') === 0 ? key : '0x' + key, function (error, preimage) { + global.web3Debug.debug.preimage(key.indexOf('0x') === 0 ? key : '0x' + key, function (error, preimage) { if (error) { resolve(null) } else { diff --git a/remix-core/src/storage/storageResolver.js b/remix-core/src/storage/storageResolver.js index 9f0bb5b8bc..368a6f1e84 100644 --- a/remix-core/src/storage/storageResolver.js +++ b/remix-core/src/storage/storageResolver.js @@ -146,7 +146,7 @@ function storageRangeWeb3Call (tx, address, start, maxSize, callback) { if (traceHelper.isContractCreation(address)) { callback(null, {}, null) } else { - global.web3.debug.storageRangeAt( + global.web3Debug.debug.storageRangeAt( tx.blockHash, tx.transactionIndex === undefined ? tx.hash : tx.transactionIndex, address, start, diff --git a/remix-core/src/trace/traceRetriever.js b/remix-core/src/trace/traceRetriever.js index 4c2fb38101..895daad471 100644 --- a/remix-core/src/trace/traceRetriever.js +++ b/remix-core/src/trace/traceRetriever.js @@ -12,7 +12,7 @@ TraceRetriever.prototype.getTrace = function (txHash, callback) { disableStack: false, fullStorage: false } - global.web3.debug.traceTransaction(txHash, options, function (error, result) { + global.web3Debug.debug.traceTransaction(txHash, options, function (error, result) { callback(error, result) }) } diff --git a/remix-debugger/src/ui/Ethdebugger.js b/remix-debugger/src/ui/Ethdebugger.js index ba6aa7c71f..b799c0cc59 100644 --- a/remix-debugger/src/ui/Ethdebugger.js +++ b/remix-debugger/src/ui/Ethdebugger.js @@ -6,6 +6,8 @@ var TraceManager = remixCore.trace.TraceManager var VmDebugger = require('./VmDebugger') var remixLib = require('remix-lib') var global = remixLib.global +var init = remixLib.init +var executionContext = remixLib.execution.executionContext var EventManager = remixLib.EventManager var yo = require('yo-yo') var csjs = require('csjs-inject') @@ -97,6 +99,14 @@ Ethdebugger.prototype.switchProvider = function (type) { console.log('provider ' + type + ' not defined') } else { global.web3 = obj + executionContext.detectNetwork((error, network) => { + if (error || !network) { + global.web3Debug = obj + } else { + var webDebugNode = init.web3DebugNode(network.name) + global.web3Debug = !webDebugNode ? obj : webDebugNode + } + }) self.event.trigger('providerChanged', [type]) } }) diff --git a/remix-lib/src/global.js b/remix-lib/src/global.js index f710f7fb66..9344a577cf 100644 --- a/remix-lib/src/global.js +++ b/remix-lib/src/global.js @@ -1,3 +1,4 @@ module.exports = { - web3: null + web3: null, + web3Debug: null // this node should support the debug endpoint } diff --git a/remix-lib/src/init.js b/remix-lib/src/init.js index 4ab21588c0..1de7097093 100644 --- a/remix-lib/src/init.js +++ b/remix-lib/src/init.js @@ -2,9 +2,10 @@ var Web3 = require('web3') module.exports = { - loadWeb3: function () { + loadWeb3: function (url) { + if (!url) url = 'http://localhost:8545' var web3 = new Web3() - web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) + web3.setProvider(new web3.providers.HttpProvider(url)) this.extend(web3) return web3 }, @@ -17,6 +18,13 @@ module.exports = { web3.setProvider(new web3.providers.HttpProvider(url)) }, + web3DebugNode: function (network) { + if (web3DebugNodes[network]) { + return this.loadWeb3(web3DebugNodes[network]) + } + return null + }, + extend: function (web3) { if (!web3._extend) { return @@ -58,3 +66,7 @@ module.exports = { } } } + +var web3DebugNodes = { + 'Main': 'https://mainnet.infura.io/remix' +}