From 39d510cef42e5326400987db6cc91744dc22e24b Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 8 Jun 2018 15:30:20 -0400 Subject: [PATCH] Displaying status, gas and block number --- lib/core/proxy.js | 18 +++++++++++++++++- lib/modules/console_listener/index.js | 9 ++++++--- lib/utils/utils.js | 5 +++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/core/proxy.js b/lib/core/proxy.js index 8cdacef41..c4e00c567 100644 --- a/lib/core/proxy.js +++ b/lib/core/proxy.js @@ -3,6 +3,8 @@ const http = require('http'); exports.serve = function(ipc, host, port, ws){ let commList = {}; + let transactions = {}; + let receipts = {}; let proxy = httpProxy.createProxyServer({ target: { @@ -21,14 +23,23 @@ exports.serve = function(ipc, host, port, ws){ let jsonO = JSON.parse(resBody); if(commList[jsonO.id]){ commList[jsonO.id].transactionHash = jsonO.result; + transactions[jsonO.result] = {commListId: jsonO.id}; + } else if(receipts[jsonO.id]){ + commList[receipts[jsonO.id]].blockNumber = jsonO.result.blockNumber; + commList[receipts[jsonO.id]].gasUsed = jsonO.result.gasUsed; + commList[receipts[jsonO.id]].status = jsonO.result.status; + if(ipc.connected && !ipc.connecting){ - ipc.request('log', commList[jsonO.id]); + ipc.request('log', commList[receipts[jsonO.id]]); } else { ipc.connecting = true; ipc.connect((err) => { ipc.connecting = false; }); } + + delete transactions[commList[receipts[jsonO.id]].transactionHash]; + delete receipts[jsonO.id]; delete commList[jsonO.id]; } } catch(e){ @@ -50,6 +61,11 @@ exports.serve = function(ipc, host, port, ws){ address: jsonO.params[0].to, data: jsonO.params[0].data }; + } else if(jsonO.method == "eth_getTransactionReceipt"){ + if(transactions[jsonO.params[0]]){ + transactions[jsonO.params[0]].receiptId = jsonO.id; + receipts[jsonO.id] = transactions[jsonO.params[0]].commListId; + } } } }); diff --git a/lib/modules/console_listener/index.js b/lib/modules/console_listener/index.js index 8194c03ef..00cfbaf7a 100644 --- a/lib/modules/console_listener/index.js +++ b/lib/modules/console_listener/index.js @@ -38,15 +38,18 @@ class ConsoleListener { this.ipc.on('log', (request) => { if(request.type == 'contract-log'){ - let {address, data, transactionHash} = request; + let {address, data, transactionHash, blockNumber, gasUsed, status} = request; if(!this.addressToContract[address]){ this._updateContractList(); } let name = this.addressToContract[address].name; let funcHash = this.addressToContract[address].functions[data.substring(0, 10)]; - - this.logger.debug(`${name}.${funcHash} : ${transactionHash}`); + + gasUsed = utils.hexToNumber(gasUsed); + blockNumber = utils.hexToNumber(blockNumber); + + this.logger.debug(`${name}.${funcHash} : ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`); } else { this.logger.debug(request); } diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 6d92422f1..a57b3ba5b 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -185,6 +185,10 @@ function getExternalContractUrl(file) { }; } +function hexToNumber(hex){ + return Web3.utils.hexToNumber(hex); +} + function toChecksumAddress(address) { return Web3.utils.toChecksumAddress(address); } @@ -253,6 +257,7 @@ module.exports = { httpsGet: httpsGet, httpGetJson: httpGetJson, httpsGetJson: httpsGetJson, + hexToNumber: hexToNumber, runCmd: runCmd, cd: cd, sed: sed,