From 63b70bf6d3a04a72c3dcab877a7262ca72a535f4 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 11 Aug 2021 13:40:21 +0530 Subject: [PATCH] get hardhat logs for tx hash method --- apps/remix-ide/src/blockchain/blockchain.js | 2 ++ libs/remix-lib/src/web3Provider/web3VmProvider.ts | 5 ++++- libs/remix-simulator/src/methods/transactions.ts | 6 ++++++ libs/remix-simulator/src/provider.ts | 9 +++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index 0ef7a888d4..4f5e0ffac7 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -487,6 +487,8 @@ class Blockchain { let execResult let returnValue = null if (isVM) { + const hhlogs = await this.web3().eth.getHHLogsForTx(txResult.transactionHash) + console.log('hhLogs--2->', hhlogs) execResult = await this.web3().eth.getExecutionResultFromSimulator(txResult.transactionHash) if (execResult) { // if it's not the VM, we don't have return value. We only have the transaction, and it does not contain the return value. diff --git a/libs/remix-lib/src/web3Provider/web3VmProvider.ts b/libs/remix-lib/src/web3Provider/web3VmProvider.ts index 6e5eeb5571..923c4cf90d 100644 --- a/libs/remix-lib/src/web3Provider/web3VmProvider.ts +++ b/libs/remix-lib/src/web3Provider/web3VmProvider.ts @@ -11,6 +11,7 @@ export class Web3VmProvider { vmTraces txs txsReceipt + hhLogs processingHash processingAddress processingIndex @@ -43,6 +44,7 @@ export class Web3VmProvider { this.vmTraces = {} this.txs = {} this.txsReceipt = {} + this.hhLogs = {} this.processingHash = null this.processingAddress = null this.processingIndex = null @@ -218,7 +220,8 @@ export class Web3VmProvider { const iface = new ethers.utils.Interface([`function log${ConsoleLogs[fnselector]} view`]) const functionDesc = iface.getFunction(`log${ConsoleLogs[fnselector]}`) const consoleArgs = iface.decodeFunctionData(functionDesc, '0x' + payload) - console.log(consoleArgs) + this.hhLogs[this.processingHash] = this.hhLogs[this.processingHash] ? this.hhLogs[this.processingHash] : [] + this.hhLogs[this.processingHash].push(consoleArgs) } if (step.op === 'CREATE' || step.op === 'CALL') { diff --git a/libs/remix-simulator/src/methods/transactions.ts b/libs/remix-simulator/src/methods/transactions.ts index 2ea3d11d54..fe8c17a275 100644 --- a/libs/remix-simulator/src/methods/transactions.ts +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -57,6 +57,7 @@ export class Transactions { eth_getTransactionByBlockHashAndIndex: this.eth_getTransactionByBlockHashAndIndex.bind(this), eth_getTransactionByBlockNumberAndIndex: this.eth_getTransactionByBlockNumberAndIndex.bind(this), eth_getExecutionResultFromSimulator: this.eth_getExecutionResultFromSimulator.bind(this), + eth_getHHLogsForTx: this.eth_getHHLogsForTx.bind(this), eth_getHashFromTagBySimulator: this.eth_getHashFromTagBySimulator.bind(this) } } @@ -83,6 +84,11 @@ export class Transactions { cb(null, this.vmContext.exeResults[txHash]) } + eth_getHHLogsForTx (payload, cb) { + const txHash = payload.params[0] + cb(null, this.vmContext.currentVm.web3vm.hhLogs[txHash]) + } + eth_getTransactionReceipt (payload, cb) { this.vmContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => { if (error) { diff --git a/libs/remix-simulator/src/provider.ts b/libs/remix-simulator/src/provider.ts index 152976227a..3bbdadaa82 100644 --- a/libs/remix-simulator/src/provider.ts +++ b/libs/remix-simulator/src/provider.ts @@ -103,6 +103,15 @@ export function extend (web3) { })) } + if (!(web3.eth && web3.eth.getHHLogsForTx)) { + methods.push(new web3.extend.Method({ + name: 'getHHLogsForTx', + call: 'eth_getHHLogsForTx', + inputFormatter: [null], + params: 1 + })) + } + if (!(web3.eth && web3.eth.getHashFromTagBySimulator)) { methods.push(new web3.extend.Method({ name: 'getHashFromTagBySimulator',