Extracted console logging to its own file
This commit is contained in:
parent
c1621c4029
commit
8ef2dc124f
|
@ -188,13 +188,13 @@ class Engine {
|
||||||
this.ipc.serve();
|
this.ipc.serve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.registerModule('solidity', {ipc: this.ipc});
|
this.registerModule('solidity', {ipc: this.ipc});
|
||||||
this.registerModule('vyper');
|
this.registerModule('vyper');
|
||||||
this.registerModule('profiler');
|
this.registerModule('profiler');
|
||||||
this.registerModule('fuzzer');
|
this.registerModule('fuzzer');
|
||||||
this.registerModule('deploytracker');
|
this.registerModule('deploytracker');
|
||||||
this.registerModule('specialconfigs');
|
this.registerModule('specialconfigs');
|
||||||
|
this.registerModule('console_listener', {ipc: this.ipc});
|
||||||
|
|
||||||
const ContractsManager = require('../contracts/contracts.js');
|
const ContractsManager = require('../contracts/contracts.js');
|
||||||
this.contractsManager = new ContractsManager({
|
this.contractsManager = new ContractsManager({
|
||||||
|
@ -224,40 +224,6 @@ class Engine {
|
||||||
plugins: this.plugins
|
plugins: this.plugins
|
||||||
});
|
});
|
||||||
|
|
||||||
// Console logger
|
|
||||||
// TODO: extract to its own file
|
|
||||||
let addressToContract = {};
|
|
||||||
this.ipc.on('log', (jsonObj) => {
|
|
||||||
if(jsonObj.type == 'contract-log'){
|
|
||||||
if(!addressToContract[jsonObj.address]){
|
|
||||||
let contractList = Object.keys(this.config.contractsConfig.contracts);
|
|
||||||
for(let i = 0; i < contractList.length; i++){
|
|
||||||
let cont = this.config.contractsConfig.contracts[contractList[i]];
|
|
||||||
if(!addressToContract[cont.deployedAddress.toLowerCase()]){
|
|
||||||
let funcSignatures = {};
|
|
||||||
cont.abiDefinition
|
|
||||||
.filter(func => func.type == "function")
|
|
||||||
.map(func => func.name + '(' +
|
|
||||||
(func.inputs ? func.inputs.map(input => input.type).join(',') : '') +
|
|
||||||
')')
|
|
||||||
.forEach(func => {
|
|
||||||
funcSignatures[utils.sha3(func).substring(0, 10)] = func;
|
|
||||||
});
|
|
||||||
|
|
||||||
addressToContract[cont.deployedAddress.toLowerCase()] = {
|
|
||||||
name: contractList[i],
|
|
||||||
functions: funcSignatures
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let funcHash = addressToContract[jsonObj.address].functions[jsonObj.data.substring(0, 10)];
|
|
||||||
this.logger.debug(addressToContract[jsonObj.address].name + "." + funcHash + " : " + jsonObj.transactionHash);
|
|
||||||
} else {
|
|
||||||
this.logger.info(jsonObj);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.events.on('file-event', function (fileType) {
|
this.events.on('file-event', function (fileType) {
|
||||||
clearTimeout(self.fileTimeout);
|
clearTimeout(self.fileTimeout);
|
||||||
self.fileTimeout = setTimeout(() => {
|
self.fileTimeout = setTimeout(() => {
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
const utils = require('../../utils/utils.js');
|
||||||
|
|
||||||
|
class ConsoleListener {
|
||||||
|
constructor(embark, options) {
|
||||||
|
this.logger = embark.logger;
|
||||||
|
this.ipc = options.ipc;
|
||||||
|
this.addressToContract = [];
|
||||||
|
this.contractsConfig = embark.config.contractsConfig;
|
||||||
|
this.listenForLogRequests();
|
||||||
|
}
|
||||||
|
|
||||||
|
_updateContractList(){
|
||||||
|
Object.keys(this.contractsConfig.contracts).forEach(contractName => {
|
||||||
|
let contract = this.contractsConfig.contracts[contractName];
|
||||||
|
let address = contract.deployedAddress.toLowerCase();
|
||||||
|
|
||||||
|
if(!this.addressToContract[address]){
|
||||||
|
let funcSignatures = {};
|
||||||
|
contract.abiDefinition
|
||||||
|
.filter(func => func.type == "function")
|
||||||
|
.map(func => func.name +
|
||||||
|
'(' +
|
||||||
|
(func.inputs ? func.inputs.map(input => input.type).join(',') : '') +
|
||||||
|
')')
|
||||||
|
.forEach(func => {
|
||||||
|
funcSignatures[utils.sha3(func).substring(0, 10)] = func;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.addressToContract[address] = {
|
||||||
|
name: contractName,
|
||||||
|
functions: funcSignatures
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
listenForLogRequests(){
|
||||||
|
this.ipc.on('log', (request) => {
|
||||||
|
if(request.type == 'contract-log'){
|
||||||
|
|
||||||
|
let {address, data, transactionHash} = 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}`);
|
||||||
|
} else {
|
||||||
|
this.logger.debug(request);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConsoleListener;
|
Loading…
Reference in New Issue