fix: record contract transaction history

This commit is contained in:
Andre Medeiros 2018-11-28 16:10:42 -05:00 committed by Iuri Matias
parent 93eca0b551
commit 435e1e6471
3 changed files with 50 additions and 3 deletions

View File

@ -16,7 +16,7 @@ class ConsoleListener {
this._listenForLogRequests(); this._listenForLogRequests();
this._registerAPI(); this._registerAPI();
this.events.on("contracts:log", this._saveLog.bind(this)); this.events.on("contracts:log", this._saveLog.bind(this));
this.events.on('outputDone', () => { this.events.on('outputDone', () => {
this.outputDone = true; this.outputDone = true;
@ -80,6 +80,19 @@ class ConsoleListener {
_listenForLogRequests() { _listenForLogRequests() {
if (this.ipc.ipcRole !== 'server') return; 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) => { this.ipc.on('log', (request) => {
if (request.type !== 'contract-log') { if (request.type !== 'contract-log') {
return this.logger.info(JSON.stringify(request)); return this.logger.info(JSON.stringify(request));

View File

@ -117,11 +117,44 @@ class ContractsManager {
try { try {
const gas = await contractObj.methods[req.body.method].apply(this, req.body.inputs).estimateGas(); 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) => { 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) { if (error) {
self.events.emit('contracts:log', contractLog);
return res.send({result: error.message}); 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) { } catch (e) {
if (funcCall === 'call' && e.message === constants.blockchain.gasAllowanceError) { if (funcCall === 'call' && e.message === constants.blockchain.gasAllowanceError) {

View File

@ -300,7 +300,8 @@ class ContractDeployer {
contract.deployedAddress = receipt.contractAddress; contract.deployedAddress = receipt.contractAddress;
contract.transactionHash = receipt.transactionHash; contract.transactionHash = receipt.transactionHash;
receipt.className = contract.className; 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); self.events.emit("deploy:contract:deployed", contract);