From fe52493e505d9a6c2c44be55da9d540d9e329aee Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 10 Aug 2021 18:01:09 +0200 Subject: [PATCH] force using local node --- apps/debugger/src/app/debugger-api.ts | 1 + apps/debugger/src/app/debugger.ts | 3 +- libs/remix-debug/src/Ethdebugger.ts | 20 +++---- libs/remix-debug/src/debugger/debugger.ts | 19 +++--- libs/remix-debug/src/trace/traceManager.ts | 3 +- .../debugger-ui/src/lib/debugger-ui.tsx | 58 ++++++++++--------- .../debugger-ui/src/lib/idebugger-api.ts | 3 +- 7 files changed, 53 insertions(+), 54 deletions(-) diff --git a/apps/debugger/src/app/debugger-api.ts b/apps/debugger/src/app/debugger-api.ts index 0f99518e78..8528759d14 100644 --- a/apps/debugger/src/app/debugger-api.ts +++ b/apps/debugger/src/app/debugger-api.ts @@ -16,6 +16,7 @@ export const DebuggerApiMixin = (Base) => class extends Base { } } this._web3 = new Web3(this.web3Provider) + remixDebug.init.extendWeb3(this._web3) this.offsetToLineColumnConverter = { async offsetToLineColumn (rawLocation, file, sources, asts) { diff --git a/apps/debugger/src/app/debugger.ts b/apps/debugger/src/app/debugger.ts index 4c14f6a3d2..95712fb2ac 100644 --- a/apps/debugger/src/app/debugger.ts +++ b/apps/debugger/src/app/debugger.ts @@ -23,6 +23,7 @@ export class DebuggerClientApi extends DebuggerApiMixin(PluginClient) { fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => Promise getFile: (path: string) => Promise setFile: (path: string, content: string) => Promise - getDebugWeb3: () => any // returns an instance of web3.js + getDebugWeb3: () => any // returns an instance of web3.js, if applicable (mainet, goerli, ...) it returns a reference to a node from devops (so we are sure debug endpoint is available) + web3: () => any // returns an instance of web3.js } diff --git a/libs/remix-debug/src/Ethdebugger.ts b/libs/remix-debug/src/Ethdebugger.ts index 3c492e1812..0026c97ee9 100644 --- a/libs/remix-debug/src/Ethdebugger.ts +++ b/libs/remix-debug/src/Ethdebugger.ts @@ -33,7 +33,6 @@ export class Ethdebugger { storageResolver callTree breakpointManager - statusMessage constructor (opts) { this.compilationResult = opts.compilationResult || function (contractAddress) { return null } @@ -151,22 +150,19 @@ export class Ethdebugger { this.event.trigger('traceUnloaded') } - debug (tx) { + async debug (tx) { if (this.traceManager.isLoading) { return } tx.to = tx.to || contractCreationToken('0') this.tx = tx - this.traceManager.resolveTrace(tx).then(async (result) => { - this.setCompilationResult(await this.compilationResult(tx.to)) - this.event.trigger('newTraceLoaded', [this.traceManager.trace]) - if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) { - this.breakpointManager.jumpNextBreakpoint(false) - } - this.storageResolver = new StorageResolver({ web3: this.traceManager.web3 }) - }).catch((error) => { - this.statusMessage = error ? error.message : 'Trace not loaded' - }) + await this.traceManager.resolveTrace(tx) + this.setCompilationResult(await this.compilationResult(tx.to)) + this.event.trigger('newTraceLoaded', [this.traceManager.trace]) + if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) { + this.breakpointManager.jumpNextBreakpoint(false) + } + this.storageResolver = new StorageResolver({ web3: this.traceManager.web3 }) } } diff --git a/libs/remix-debug/src/debugger/debugger.ts b/libs/remix-debug/src/debugger/debugger.ts index 11395026b3..411ab442ab 100644 --- a/libs/remix-debug/src/debugger/debugger.ts +++ b/libs/remix-debug/src/debugger/debugger.ts @@ -100,9 +100,9 @@ export class Debugger { } debug (blockNumber, txNumber, tx, loadingCb): Promise { - const web3 = this.debugger.web3 - return new Promise((resolve, reject) => { + const web3 = this.debugger.web3 + if (this.debugger.traceManager.isLoading) { return resolve() } @@ -111,8 +111,7 @@ export class Debugger { if (!tx.to) { tx.to = contractCreationToken('0') } - this.debugTx(tx, loadingCb) - return resolve() + return this.debugTx(tx, loadingCb).then(resolve).catch(reject) } try { @@ -120,23 +119,21 @@ export class Debugger { return web3.eth.getTransaction(txNumber, (_error, tx) => { if (_error) return reject(_error) if (!tx) return reject(new Error('cannot find transaction ' + txNumber)) - this.debugTx(tx, loadingCb) - return resolve() + return this.debugTx(tx, loadingCb).then(resolve).catch(reject) }) } web3.eth.getTransactionFromBlock(blockNumber, txNumber, (_error, tx) => { if (_error) return reject(_error) if (!tx) return reject(new Error('cannot find transaction ' + blockNumber + ' ' + txNumber)) - this.debugTx(tx, loadingCb) - return resolve() + return this.debugTx(tx, loadingCb).then(resolve).catch(reject) }) } catch (e) { - return reject(e.message) + return reject(e) } }) } - debugTx (tx, loadingCb) { + async debugTx (tx, loadingCb) { this.step_manager = new DebuggerStepManager(this.debugger, this.debugger.traceManager) this.debugger.codeManager.event.register('changed', this, (code, address, instIndex) => { @@ -162,7 +159,7 @@ export class Debugger { }) loadingCb() - this.debugger.debug(tx) + await this.debugger.debug(tx) } unload () { diff --git a/libs/remix-debug/src/trace/traceManager.ts b/libs/remix-debug/src/trace/traceManager.ts index 49ba500889..1c72ac96eb 100644 --- a/libs/remix-debug/src/trace/traceManager.ts +++ b/libs/remix-debug/src/trace/traceManager.ts @@ -30,9 +30,8 @@ export class TraceManager { this.init() if (!this.web3) throw new Error('web3 not loaded') this.isLoading = true + const result = await this.getTrace(tx.hash) try { - const result = await this.getTrace(tx.hash) - if (result['structLogs'].length > 0) { this.trace = result['structLogs'] diff --git a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx index 7adc8a9312..ac802457e2 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx @@ -15,7 +15,6 @@ export const DebuggerUI = (props: DebuggerUIProps) => { const debuggerModule = props.debuggerAPI const [state, setState] = useState({ isActive: false, - statusMessage: '', debugger: null, currentReceipt: { contractAddress: null, @@ -25,7 +24,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => { txNumber: '', debugging: false, opt: { - debugWithGeneratedSources: false + debugWithGeneratedSources: false, + debugWithLocalNode: false }, toastMessage: '', validationError: '', @@ -132,7 +132,6 @@ export const DebuggerUI = (props: DebuggerUIProps) => { return { ...prevState, isActive: false, - statusMessage: '', debugger: null, currentReceipt: { contractAddress: null, @@ -166,7 +165,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => { return } - const web3 = await debuggerModule.getDebugWeb3() + const web3 = state.opt.debugWithLocalNode ? await debuggerModule.web3() : await debuggerModule.getDebugWeb3() try { const networkId = await web3.eth.net.getId() _paq.push(['trackEvent', 'debugger', 'startDebugging', networkId]) @@ -211,33 +210,31 @@ export const DebuggerUI = (props: DebuggerUIProps) => { debugWithGeneratedSources: state.opt.debugWithGeneratedSources }) - debuggerInstance.debug(blockNumber, txNumber, tx, () => { - listenToEvents(debuggerInstance, currentReceipt) - setState(prevState => { - return { - ...prevState, - blockNumber, - txNumber, - debugging: true, - currentReceipt, - debugger: debuggerInstance, - toastMessage: `debugging ${txNumber}`, - validationError: '' - } - }) - }).catch((error) => { - if (JSON.stringify(error) !== '{}') { - let message = 'Error: ' + JSON.stringify(error) - message = message.split('\\"').join('\'') + try { + await debuggerInstance.debug(blockNumber, txNumber, tx, () => { + listenToEvents(debuggerInstance, currentReceipt) setState(prevState => { return { ...prevState, - validationError: message + blockNumber, + txNumber, + debugging: true, + currentReceipt, + debugger: debuggerInstance, + toastMessage: `debugging ${txNumber}`, + validationError: '' } }) - } + }) + } catch (error) { unLoad() - }) + setState(prevState => { + return { + ...prevState, + validationError: error.message || error + } + }) + } } const debug = (txHash) => { @@ -277,18 +274,25 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
{ setState(prevState => { - return { ...prevState, opt: { debugWithGeneratedSources: checked } } + return { ...prevState, opt: { ...prevState.opt, debugWithGeneratedSources: checked } } }) }} type="checkbox" title="Debug with generated sources" />
+
+ { + setState(prevState => { + return { ...prevState, opt: { ...prevState.opt, debugWithLocalNode: checked } } + }) + }} type="checkbox" title="Force the debugger to use the current local node" /> + +
{ state.validationError && {state.validationError} } { state.debugging && } { state.debugging && } - { state.debugging &&
{ state.statusMessage }
} { state.debugging && } ) diff --git a/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts b/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts index e2d62d37fc..4e31ce7360 100644 --- a/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts +++ b/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts @@ -62,6 +62,7 @@ export interface IDebuggerApi { fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => Promise getFile: (path: string) => Promise setFile: (path: string, content: string) => Promise - getDebugWeb3: () => any // returns an instance of web3.js + getDebugWeb3: () => any // returns an instance of web3.js, if applicable (mainet, goerli, ...) it returns a reference to a node from devops (so we are sure debug endpoint is available) + web3: () => any // returns an instance of web3.js showMessage (title: string, message: string): void }