diff --git a/apps/remix-ide/src/app/tabs/debugger-tab.js b/apps/remix-ide/src/app/tabs/debugger-tab.js
index a4f574131a..8d357acc65 100644
--- a/apps/remix-ide/src/app/tabs/debugger-tab.js
+++ b/apps/remix-ide/src/app/tabs/debugger-tab.js
@@ -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
+ const onReady = (api) => { this.api = api }
+ return
}
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
+ }
+ }
+ }
}
diff --git a/libs/remix-debug/src/Ethdebugger.ts b/libs/remix-debug/src/Ethdebugger.ts
index 30431a568f..071ff4c74e 100644
--- a/libs/remix-debug/src/Ethdebugger.ts
+++ b/libs/remix-debug/src/Ethdebugger.ts
@@ -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) {
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 8fa8698093..6ea07f3d5e 100644
--- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx
+++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx
@@ -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(null)
const debuggerTopRef = useRef(null)
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 1b0d19c3d4..ae688027d2 100644
--- a/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts
+++ b/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts
@@ -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
}
diff --git a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts
index a6ddf990fa..b2c5c55b52 100644
--- a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts
+++ b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts
@@ -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) {