add global context value in popup while debugging

pull/3199/head
yann300 2 years ago committed by Aniket
parent 58c205b8de
commit a79ce971a3
  1. 44
      apps/remix-ide/src/app/tabs/debugger-tab.js
  2. 2
      libs/remix-debug/src/Ethdebugger.ts
  3. 12
      libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx
  4. 7
      libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts
  5. 22
      libs/remix-ui/editor/src/lib/providers/hoverProvider.ts

@ -1,3 +1,4 @@
import Web3 from 'web3'
import { DebuggerUI } from '@remix-ui/debugger-ui' // eslint-disable-line
import { DebuggerApiMixin } from '@remixproject/debugger-plugin' // eslint-disable-line
import { ViewPlugin } from '@remixproject/engine-web'
@ -10,7 +11,7 @@ const css = require('./styles/debugger-tab-styles')
const profile = {
name: 'debugger',
displayName: 'Debugger',
methods: ['debug', 'getTrace', 'decodeLocalVariable', 'decodeStateVariable'],
methods: ['debug', 'getTrace', 'decodeLocalVariable', 'decodeStateVariable', 'globalContext'],
events: [],
icon: 'assets/img/debuggerLogo.webp',
description: 'Debug transactions',
@ -51,7 +52,8 @@ export class DebuggerTab extends DebuggerApiMixin(ViewPlugin) {
this.on('fetchAndCompile', 'sourceVerificationNotAvailable', () => {
this.call('notification', 'toast', sourceVerificationNotAvailableToastMsg())
})
return <div className="overflow-hidden px-1" id='debugView'><DebuggerUI debuggerAPI={this} /></div>
const onReady = (api) => { this.api = api }
return <div className="overflow-hidden px-1" id='debugView'><DebuggerUI debuggerAPI={this} onReady={onReady} /></div>
}
showMessage (title, message) {
@ -75,4 +77,42 @@ export class DebuggerTab extends DebuggerApiMixin(ViewPlugin) {
if (!this.debuggerBackend) return null
return await this.debuggerBackend.debugger.decodeStateVariableByIdAtCurrentStep(this.debuggerBackend.step_manager.currentStepIndex, variableId)
}
async globalContext () {
if (this.api?.globalContext) {
const { tx, block } = await this.api.globalContext()
const blockContext = {
'chainid': tx.chainId,
'coinbase': block.miner,
'difficulty': block.difficulty,
'gaslimit': block.gasLimit,
'number': block.number,
'timestamp': block.timestamp,
}
if (block.baseFeePerGas) {
blockContext['basefee'] = Web3.utils.toBN(block.baseFeePerGas).toString(10) + ` Wei (${block.baseFeePerGas})`
}
const msg = {
'sender': tx.from,
'sig': tx.input.substring(0, 10),
'value': tx.value + ' Wei'
}
const txOrigin = {
'origin': tx.from
}
return {
block: blockContext,
msg,
tx: txOrigin
}
} else {
return {
block: null,
msg: null,
tx: null
}
}
}
}

@ -119,7 +119,7 @@ export class Ethdebugger {
const state = await this.decodeStateAt(step, variable)
return state[variable[0].name]
}
return { value: '' }
return null
}
async decodeLocalsAt (step, sourceLocation, callback) {

@ -37,6 +37,18 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
sourceLocationStatus: ''
})
if (props.onReady) {
props.onReady({
globalContext: () => {
return {
block: state.currentBlock,
tx: state.currentTransaction,
receipt: state.currentReceipt
}
}
})
}
const panelsRef = useRef<HTMLDivElement>(null)
const debuggerTopRef = useRef(null)

@ -55,6 +55,11 @@ export interface IDebuggerApi {
onStopDebugging (): void // called when debug stops
}
type globalContextFunction = () => { block, tx, receipt }
type onReadyParams = {
globalContext: globalContextFunction
}
export interface DebuggerUIProps {
debuggerAPI: IDebuggerApi
debuggerAPI: IDebuggerApi,
onReady?: (functions: onReadyParams) => void
}

@ -146,6 +146,28 @@ export class RemixHoverProvider implements languages.HoverProvider {
getDocs(nodeAtPosition)
// getScope(nodeAtPosition)
try {
if (nodeAtPosition?.name === 'msg') {
const global = await this.props.plugin.call('debugger', 'globalContext')
if (global !== null && global[nodeAtPosition?.name]) {
contents.push({
value: `${nodeAtPosition.name} = ${JSON.stringify(global[nodeAtPosition?.name], null, '\t')}`
})
}
}
} catch (e) {}
try {
if (nodeAtPosition?.expression?.name === 'msg' && nodeAtPosition?.memberName) {
const global = await this.props.plugin.call('debugger', 'globalContext')
if (global !== null && global[nodeAtPosition?.expression?.name][nodeAtPosition.memberName] && global[nodeAtPosition?.expression?.name][nodeAtPosition.memberName]) {
contents.push({
value: `${nodeAtPosition.memberName} = ${global[nodeAtPosition?.expression?.name][nodeAtPosition.memberName]}`
})
}
}
} catch (e) {}
try {
const decodedVar = await this.props.plugin.call('debugger', 'decodeLocalVariable', nodeAtPosition.id)
if (decodedVar !== null && decodedVar.type) {

Loading…
Cancel
Save