Commit fc5f3829 authored by yann300's avatar yann300

display global variables while debugging

parent 7f7276c6
...@@ -41,6 +41,7 @@ export class Blocks { ...@@ -41,6 +41,7 @@ export class Blocks {
} }
const b = { const b = {
baseFeePerGas: '0x01',
number: this.toHex(block.header.number), number: this.toHex(block.header.number),
hash: this.toHex(block.hash()), hash: this.toHex(block.hash()),
parentHash: this.toHex(block.header.parentHash), parentHash: this.toHex(block.header.parentHash),
...@@ -73,6 +74,7 @@ export class Blocks { ...@@ -73,6 +74,7 @@ export class Blocks {
const block = this.vmContext.blocks[payload.params[0]] const block = this.vmContext.blocks[payload.params[0]]
const b = { const b = {
baseFeePerGas: '0x01',
number: this.toHex(block.header.number), number: this.toHex(block.header.number),
hash: this.toHex(block.hash()), hash: this.toHex(block.hash()),
parentHash: this.toHex(block.header.parentHash), parentHash: this.toHex(block.header.parentHash),
......
...@@ -193,6 +193,7 @@ export class Transactions { ...@@ -193,6 +193,7 @@ export class Transactions {
blockNumber: '0x' + txBlock.header.number.toString('hex'), blockNumber: '0x' + txBlock.header.number.toString('hex'),
from: receipt.from, from: receipt.from,
gas: Web3.utils.toHex(receipt.gas), gas: Web3.utils.toHex(receipt.gas),
chainId: '0xb',
// 'gasPrice': '2000000000000', // 0x123 // 'gasPrice': '2000000000000', // 0x123
gasPrice: '0x4a817c800', // 20000000000 gasPrice: '0x4a817c800', // 20000000000
hash: receipt.transactionHash, hash: receipt.transactionHash,
...@@ -239,6 +240,7 @@ export class Transactions { ...@@ -239,6 +240,7 @@ export class Transactions {
blockNumber: '0x' + txBlock.header.number.toString('hex'), blockNumber: '0x' + txBlock.header.number.toString('hex'),
from: receipt.from, from: receipt.from,
gas: Web3.utils.toHex(receipt.gas), gas: Web3.utils.toHex(receipt.gas),
chainId: '0xb',
// 'gasPrice': '2000000000000', // 0x123 // 'gasPrice': '2000000000000', // 0x123
gasPrice: '0x4a817c800', // 20000000000 gasPrice: '0x4a817c800', // 20000000000
hash: receipt.transactionHash, hash: receipt.transactionHash,
...@@ -282,6 +284,7 @@ export class Transactions { ...@@ -282,6 +284,7 @@ export class Transactions {
from: receipt.from, from: receipt.from,
gas: Web3.utils.toHex(receipt.gas), gas: Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123 // 'gasPrice': '2000000000000', // 0x123
chainId: '0xb',
gasPrice: '0x4a817c800', // 20000000000 gasPrice: '0x4a817c800', // 20000000000
hash: receipt.transactionHash, hash: receipt.transactionHash,
input: receipt.input, input: receipt.input,
......
...@@ -18,6 +18,7 @@ describe('blocks', () => { ...@@ -18,6 +18,7 @@ describe('blocks', () => {
const block = await web3.eth.getBlock(0) const block = await web3.eth.getBlock(0)
const expectedBlock = { const expectedBlock = {
baseFeePerGas: '0x01',
difficulty: '69762765929000', difficulty: '69762765929000',
extraData: '0x0', extraData: '0x0',
gasLimit: 8000000, gasLimit: 8000000,
......
...@@ -20,6 +20,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => { ...@@ -20,6 +20,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
contractAddress: null, contractAddress: null,
to: null to: null
}, },
currentBlock: null,
currentTransaction: null,
blockNumber: null, blockNumber: null,
txNumber: '', txNumber: '',
debugging: false, debugging: false,
...@@ -137,6 +139,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => { ...@@ -137,6 +139,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
contractAddress: null, contractAddress: null,
to: null to: null
}, },
currentBlock: null,
currentTransaction: null,
blockNumber: null, blockNumber: null,
ready: { ready: {
vmDebugger: false, vmDebugger: false,
...@@ -182,8 +186,12 @@ export const DebuggerUI = (props: DebuggerUIProps) => { ...@@ -182,8 +186,12 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
console.error(e) console.error(e)
} }
let currentReceipt let currentReceipt
let currentBlock
let currentTransaction
try { try {
currentReceipt = await web3.eth.getTransactionReceipt(txNumber) currentReceipt = await web3.eth.getTransactionReceipt(txNumber)
currentBlock = await web3.eth.getBlock(currentReceipt.blockHash)
currentTransaction = await web3.eth.getTransaction(txNumber)
} catch (e) { } catch (e) {
setState(prevState => { setState(prevState => {
return { return {
...@@ -220,6 +228,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => { ...@@ -220,6 +228,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
txNumber, txNumber,
debugging: true, debugging: true,
currentReceipt, currentReceipt,
currentBlock,
currentTransaction,
debugger: debuggerInstance, debugger: debuggerInstance,
toastMessage: `debugging ${txNumber}`, toastMessage: `debugging ${txNumber}`,
validationError: '' validationError: ''
...@@ -293,7 +303,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => { ...@@ -293,7 +303,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
{ state.debugging && <StepManager stepManager={ stepManager } /> } { state.debugging && <StepManager stepManager={ stepManager } /> }
{ state.debugging && <VmDebuggerHead vmDebugger={ vmDebugger } /> } { state.debugging && <VmDebuggerHead vmDebugger={ vmDebugger } /> }
</div> </div>
{ state.debugging && <VmDebugger vmDebugger={ vmDebugger } /> } { state.debugging && <VmDebugger vmDebugger={ vmDebugger } currentBlock={ state.currentBlock } currentReceipt={ state.currentReceipt } currentTransaction={ state.currentTransaction } /> }
</div> </div>
) )
} }
......
import React from 'react' // eslint-disable-line
import DropdownPanel from './dropdown-panel' // eslint-disable-line
import { BN } from 'ethereumjs-util'
export const GlobalVariables = ({ block, receipt, tx }) => {
console.log(block, receipt, tx)
// see https://docs.soliditylang.org/en/latest/units-and-global-variables.html#block-and-transaction-properties
const globals = {
'block.basefee': (new BN(block.baseFeePerGas.replace('0x', ''), 'hex')).toString(10) + ` Wei (${block.baseFeePerGas})`,
'block.chainid': tx.chainId,
'block.coinbase': block.miner,
'block.difficulty': block.difficulty,
'block.gaslimit': block.gasLimit,
'block.number': block.number,
'block.timestamp': block.timestamp,
'msg.sender': tx.from,
'msg.sig': tx.input.substring(0, 10),
'msg.value': tx.value + ' Wei',
'tx.origin': tx.from
}
return (
<div id='globalvariable' data-id='globalvariable'>
<DropdownPanel hexHighlight={false} bodyStyle={{ fontFamily: 'monospace' }} dropdownName='Global Variables' calldata={globals || {}} />
</div>
)
}
export default GlobalVariables
...@@ -15,6 +15,7 @@ export const VmDebuggerHead = ({ vmDebugger: { registerEvent, triggerEvent } }) ...@@ -15,6 +15,7 @@ export const VmDebuggerHead = ({ vmDebugger: { registerEvent, triggerEvent } })
'remaining gas': '-', 'remaining gas': '-',
'loaded address': '-' 'loaded address': '-'
}) })
const [solidityState, setSolidityState] = useState({ const [solidityState, setSolidityState] = useState({
calldata: null, calldata: null,
message: null message: null
......
...@@ -6,8 +6,9 @@ import StackPanel from './stack-panel' // eslint-disable-line ...@@ -6,8 +6,9 @@ import StackPanel from './stack-panel' // eslint-disable-line
import StoragePanel from './storage-panel' // eslint-disable-line import StoragePanel from './storage-panel' // eslint-disable-line
import ReturnValuesPanel from './dropdown-panel' // eslint-disable-line import ReturnValuesPanel from './dropdown-panel' // eslint-disable-line
import FullStoragesChangesPanel from './full-storages-changes' // eslint-disable-line import FullStoragesChangesPanel from './full-storages-changes' // eslint-disable-line
import GlobalVariables from './global-variables' // eslint-disable-line
export const VmDebugger = ({ vmDebugger: { registerEvent } }) => { export const VmDebugger = ({ vmDebugger: { registerEvent }, currentBlock, currentReceipt, currentTransaction }) => {
const [calldataPanel, setCalldataPanel] = useState(null) const [calldataPanel, setCalldataPanel] = useState(null)
const [memoryPanel, setMemoryPanel] = useState(null) const [memoryPanel, setMemoryPanel] = useState(null)
const [callStackPanel, setCallStackPanel] = useState(null) const [callStackPanel, setCallStackPanel] = useState(null)
...@@ -58,6 +59,7 @@ export const VmDebugger = ({ vmDebugger: { registerEvent } }) => { ...@@ -58,6 +59,7 @@ export const VmDebugger = ({ vmDebugger: { registerEvent } }) => {
<StoragePanel calldata={storagePanel.calldata} header={storagePanel.header} /> <StoragePanel calldata={storagePanel.calldata} header={storagePanel.header} />
<CallstackPanel calldata={callStackPanel} /> <CallstackPanel calldata={callStackPanel} />
<CalldataPanel calldata={calldataPanel} /> <CalldataPanel calldata={calldataPanel} />
<GlobalVariables block={currentBlock} receipt={currentReceipt} tx={currentTransaction} />
<ReturnValuesPanel dropdownName='Return Value' calldata={returnValuesPanel || {}} /> <ReturnValuesPanel dropdownName='Return Value' calldata={returnValuesPanel || {}} />
<FullStoragesChangesPanel calldata={fullStoragesChangesPanel} /> <FullStoragesChangesPanel calldata={fullStoragesChangesPanel} />
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment