From 18914407d9222e35634081618c94a9e2ba329e97 Mon Sep 17 00:00:00 2001 From: lianahus Date: Thu, 21 Jan 2021 17:20:45 +0100 Subject: [PATCH] check for valid tx hash --- apps/debugger/src/app/debugger-api.ts | 2 +- apps/remix-ide/src/app/tabs/debugger-tab.js | 2 +- apps/remix-ide/src/lib/helper.js | 4 ++++ .../debugger-ui/src/lib/debugger-ui.tsx | 18 ++++++++++++++---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/apps/debugger/src/app/debugger-api.ts b/apps/debugger/src/app/debugger-api.ts index 2627c963c1..e9654dd343 100644 --- a/apps/debugger/src/app/debugger-api.ts +++ b/apps/debugger/src/app/debugger-api.ts @@ -6,7 +6,7 @@ import type { CompilationResult } from '@remix-project/remix-solidity-ts' export const DebuggerApiMixin = (Base) => class extends Base { initDebuggerApi () { this.debugHash = null - + const self = this this.web3Provider = { sendAsync (payload, callback) { diff --git a/apps/remix-ide/src/app/tabs/debugger-tab.js b/apps/remix-ide/src/app/tabs/debugger-tab.js index 5c9467742d..3128848266 100644 --- a/apps/remix-ide/src/app/tabs/debugger-tab.js +++ b/apps/remix-ide/src/app/tabs/debugger-tab.js @@ -6,9 +6,9 @@ import * as packageJson from '../../../../../package.json' import React from 'react' // eslint-disable-line import ReactDOM from 'react-dom' import modalDialogCustom from '../ui/modal-dialog-custom' +import bleach from '../../lib/bleach' const yo = require('yo-yo') const css = require('./styles/debugger-tab-styles') -import bleach from '../../lib/bleach' const profile = { name: 'debugger', diff --git a/apps/remix-ide/src/lib/helper.js b/apps/remix-ide/src/lib/helper.js index 21f2c96961..ab7f8c743f 100644 --- a/apps/remix-ide/src/lib/helper.js +++ b/apps/remix-ide/src/lib/helper.js @@ -64,6 +64,10 @@ module.exports = { isNumeric (value) { return /^\+?(0|[1-9]\d*)$/.test(value) }, + isValidHash (hash) { // 0x prefixed, hexadecimal, 64digit + const hexValue = hash.slice(2, hash.length) + return this.is0XPrefixed(hash) && /^[0-9a-fA-F]{64}$/.test(hexValue) + }, find: find } 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 0069ee4ebe..f466cb6efa 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx @@ -8,6 +8,7 @@ import { DebuggerUIProps } from './idebugger-api' // eslint-disable-line import { Toaster } from '@remix-ui/toaster' // eslint-disable-line /* eslint-disable-next-line */ import './debugger-ui.css' +const helper = require('../../../../../apps/remix-ide/src/lib/helper') export const DebuggerUI = (props: DebuggerUIProps) => { const debuggerModule = props.debuggerAPI @@ -26,7 +27,6 @@ export const DebuggerUI = (props: DebuggerUIProps) => { debugWithGeneratedSources: false }, toastMessage: '', - currentDebugTransaction: '', validationError: '', txNumberIsEmpty: true }) @@ -144,7 +144,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => { vmDebuggerHead: false }, debugging: false, - currentDebugTransaction: '' + txNumber: '' } }) } @@ -154,9 +154,19 @@ export const DebuggerUI = (props: DebuggerUIProps) => { setState(prevState => { return { ...prevState, - currentDebugTransaction: txNumber + txNumber: txNumber } }) + if (!helper.isValidHash(txNumber)) { + setState(prevState => { + return { + ...prevState, + validationError: 'Invalid transaction hash.' + } + }) + return + } + const web3 = await debuggerModule.getDebugWeb3() let currentReceipt try { @@ -186,6 +196,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => { }, debugWithGeneratedSources: state.opt.debugWithGeneratedSources }) + debuggerInstance.debug(blockNumber, txNumber, tx, () => { listenToEvents(debuggerInstance, currentReceipt) setState(prevState => { @@ -210,7 +221,6 @@ export const DebuggerUI = (props: DebuggerUIProps) => { validationError: message } }) - console.log(message) } unLoad() })