mirror of https://github.com/embarklabs/embark.git
fix: record contract transaction history
This commit is contained in:
parent
93eca0b551
commit
435e1e6471
|
@ -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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue