fix indentation
This commit is contained in:
parent
86ba7e3803
commit
deb54e535c
|
@ -1,92 +1,92 @@
|
||||||
const utils = require('../../utils/utils.js');
|
const utils = require('../../utils/utils.js');
|
||||||
|
|
||||||
class ConsoleListener {
|
class ConsoleListener {
|
||||||
constructor(embark, options) {
|
constructor(embark, options) {
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.ipc = options.ipc;
|
this.ipc = options.ipc;
|
||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.addressToContract = [];
|
this.addressToContract = [];
|
||||||
this.contractsConfig = embark.config.contractsConfig;
|
this.contractsConfig = embark.config.contractsConfig;
|
||||||
this.contractsDeployed = false;
|
this.contractsDeployed = false;
|
||||||
this._listenForLogRequests();
|
this._listenForLogRequests();
|
||||||
|
|
||||||
this.events.on("contractsDeployed", () => {
|
this.events.on("contractsDeployed", () => {
|
||||||
this.contractsDeployed = true;
|
this.contractsDeployed = true;
|
||||||
this._updateContractList();
|
this._updateContractList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateContractList(){
|
_updateContractList() {
|
||||||
this.events.request("contracts:list", (_err, contractsList) => {
|
this.events.request("contracts:list", (_err, contractsList) => {
|
||||||
if(_err) {
|
if (_err) {
|
||||||
this.logger.error(__("no contracts found"));
|
this.logger.error(__("no contracts found"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
contractsList.forEach(contract => {
|
contractsList.forEach(contract => {
|
||||||
if(!contract.deployedAddress) return;
|
if (!contract.deployedAddress) return;
|
||||||
|
|
||||||
let address = contract.deployedAddress.toLowerCase();
|
|
||||||
if(!this.addressToContract[address]){
|
|
||||||
let funcSignatures = {};
|
|
||||||
contract.abiDefinition
|
|
||||||
.filter(func => func.type == "function")
|
|
||||||
.map(func => {
|
|
||||||
const name = func.name +
|
|
||||||
'(' +
|
|
||||||
(func.inputs ? func.inputs.map(input => input.type).join(',') : '') +
|
|
||||||
')';
|
|
||||||
funcSignatures[utils.sha3(name).substring(0, 10)] = {
|
|
||||||
name,
|
|
||||||
abi: func,
|
|
||||||
functionName: func.name
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addressToContract[address] = {
|
let address = contract.deployedAddress.toLowerCase();
|
||||||
name: contract.className,
|
if (!this.addressToContract[address]) {
|
||||||
functions: funcSignatures
|
let funcSignatures = {};
|
||||||
};
|
contract.abiDefinition
|
||||||
}
|
.filter(func => func.type === "function")
|
||||||
|
.map(func => {
|
||||||
|
const name = func.name +
|
||||||
|
'(' +
|
||||||
|
(func.inputs ? func.inputs.map(input => input.type).join(',') : '') +
|
||||||
|
')';
|
||||||
|
funcSignatures[utils.sha3(name).substring(0, 10)] = {
|
||||||
|
name,
|
||||||
|
abi: func,
|
||||||
|
functionName: func.name
|
||||||
|
};
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_listenForLogRequests(){
|
this.addressToContract[address] = {
|
||||||
if(this.ipc.ipcRole !== 'server') return;
|
name: contract.className,
|
||||||
this.ipc.on('log', (request) => {
|
functions: funcSignatures
|
||||||
if(request.type == 'contract-log'){
|
};
|
||||||
if(!this.contractsDeployed) return;
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let {address, data, transactionHash, blockNumber, gasUsed, status} = request;
|
_listenForLogRequests() {
|
||||||
if(!this.addressToContract[address]){
|
if (this.ipc.ipcRole !== 'server') return;
|
||||||
this._updateContractList();
|
this.ipc.on('log', (request) => {
|
||||||
}
|
if (request.type === 'contract-log') {
|
||||||
if(!this.addressToContract[address]) return;
|
if (!this.contractsDeployed) return;
|
||||||
|
|
||||||
|
let {address, data, transactionHash, blockNumber, gasUsed, status} = request;
|
||||||
|
if (!this.addressToContract[address]) {
|
||||||
|
this._updateContractList();
|
||||||
|
}
|
||||||
|
if (!this.addressToContract[address]) return;
|
||||||
|
|
||||||
|
|
||||||
const name = this.addressToContract[address].name;
|
const name = this.addressToContract[address].name;
|
||||||
const func = this.addressToContract[address].functions[data.substring(0, 10)];
|
const func = this.addressToContract[address].functions[data.substring(0, 10)];
|
||||||
const functionName = func.functionName;
|
const functionName = func.functionName;
|
||||||
|
|
||||||
const decodedParameters = utils.decodeParams(func.abi.inputs, data.substring(10));
|
const decodedParameters = utils.decodeParams(func.abi.inputs, data.substring(10));
|
||||||
let paramString = "";
|
let paramString = "";
|
||||||
if(func.abi.inputs){
|
if (func.abi.inputs) {
|
||||||
func.abi.inputs.forEach((input) => {
|
func.abi.inputs.forEach((input) => {
|
||||||
let quote = input.type.indexOf("int") == -1 ? '"' : '';
|
let quote = input.type.indexOf("int") === -1 ? '"' : '';
|
||||||
paramString += quote + decodedParameters[input.name] + quote + ", ";
|
paramString += quote + decodedParameters[input.name] + quote + ", ";
|
||||||
});
|
});
|
||||||
paramString = paramString.substring(0, paramString.length - 2);
|
paramString = paramString.substring(0, paramString.length - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
gasUsed = utils.hexToNumber(gasUsed);
|
gasUsed = utils.hexToNumber(gasUsed);
|
||||||
blockNumber = utils.hexToNumber(blockNumber);
|
blockNumber = utils.hexToNumber(blockNumber);
|
||||||
|
|
||||||
this.logger.info(`Blockchain>`.underline + ` ${name}.${functionName}(${paramString})`.bold + ` | ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`);
|
this.logger.info(`Blockchain>`.underline + ` ${name}.${functionName}(${paramString})`.bold + ` | ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`);
|
||||||
} else {
|
} else {
|
||||||
this.logger.info(JSON.stringify(request));
|
this.logger.info(JSON.stringify(request));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ConsoleListener;
|
module.exports = ConsoleListener;
|
||||||
|
|
Loading…
Reference in New Issue