From 435e1e6471b6737e2477bd78d01776f43cedd264 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Wed, 28 Nov 2018 16:10:42 -0500 Subject: [PATCH] fix: record contract transaction history --- src/lib/modules/console_listener/index.js | 15 +++++++- src/lib/modules/contracts_manager/index.js | 35 ++++++++++++++++++- .../modules/deployment/contract_deployer.js | 3 +- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/lib/modules/console_listener/index.js b/src/lib/modules/console_listener/index.js index 274774701..6cfda686d 100644 --- a/src/lib/modules/console_listener/index.js +++ b/src/lib/modules/console_listener/index.js @@ -16,7 +16,7 @@ class ConsoleListener { this._listenForLogRequests(); this._registerAPI(); - + this.events.on("contracts:log", this._saveLog.bind(this)); this.events.on('outputDone', () => { this.outputDone = true; @@ -80,6 +80,19 @@ class ConsoleListener { _listenForLogRequests() { if (this.ipc.ipcRole !== 'server') return; + this.events.on('deploy:contract:receipt', receipt => { + this.events.emit('contracts:log', { + name: receipt.className, + functionName: 'constructor', + paramString: '', + address: receipt.contractAddress, + status: receipt.status, + gasUsed: receipt.gasUsed, + blockNumber: receipt.blockNumber, + transactionHash: receipt.transactionHash + }); + }); + this.ipc.on('log', (request) => { if (request.type !== 'contract-log') { return this.logger.info(JSON.stringify(request)); diff --git a/src/lib/modules/contracts_manager/index.js b/src/lib/modules/contracts_manager/index.js index 264fe9437..6bde1416f 100644 --- a/src/lib/modules/contracts_manager/index.js +++ b/src/lib/modules/contracts_manager/index.js @@ -117,11 +117,44 @@ class ContractsManager { try { const gas = await contractObj.methods[req.body.method].apply(this, req.body.inputs).estimateGas(); contractObj.methods[req.body.method].apply(this, req.body.inputs)[funcCall]({from: account, gasPrice: req.body.gasPrice, gas: Math.floor(gas)}, (error, result) => { + const paramString = abi.inputs.map((input, idx) => { + const quote = input.type.indexOf("int") === -1 ? '"' : ''; + return quote + req.body.inputs[idx] + quote; + }).join(', '); + + let contractLog = { + name: req.body.contractName, + functionName: req.body.method, + paramString: paramString, + address: contract.deployedAddress, + status: '0x0' + }; + if (error) { + self.events.emit('contracts:log', contractLog); return res.send({result: error.message}); } - res.send({result}); + if(funcCall === 'call') { + contractLog.status = '0x1'; + self.events.emit('contracts:log', contractLog); + return res.send({result}); + } + + self.events.request("blockchain:get", web3 => { + web3.eth.getTransaction(result, (err, tx) => { + contractLog = Object.assign(contractLog, { + data: tx.input, + status: '0x1', + gasUsed: tx.gas, + blockNumber: tx.blockNumber, + transactionHash: tx.hash + }); + + self.events.emit('contracts:log', contractLog); + res.send({result}); + }); + }); }); } catch (e) { if (funcCall === 'call' && e.message === constants.blockchain.gasAllowanceError) { diff --git a/src/lib/modules/deployment/contract_deployer.js b/src/lib/modules/deployment/contract_deployer.js index 182c3885a..80d10f463 100644 --- a/src/lib/modules/deployment/contract_deployer.js +++ b/src/lib/modules/deployment/contract_deployer.js @@ -300,7 +300,8 @@ class ContractDeployer { contract.deployedAddress = receipt.contractAddress; contract.transactionHash = receipt.transactionHash; receipt.className = contract.className; - self.events.emit("deploy:contract:receipt", receipt); + + if(receipt) self.events.emit("deploy:contract:receipt", receipt); self.events.emit("deploy:contract:deployed", contract);