Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var event = null;
for (var i = 0; i < abi.length; i++) {
var item = abi[i];
if (item.type != "event") continue;
var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")";
var hash = web3.sha3(signature);
if (hash == log.topics[0]) {
event = item;
break;
}
}
if (event != null) {
var inputs = event.inputs.map(function(input) {return input.type;});
var data = SolidityCoder.decodeParams(inputs, log.data.replace("0x", ""));
// Do something with the data. Depends on the log and what you're using the data for.
return {name:event.name , data:data};
}
return null;
}
var event = null;
for (var i = 0; i < abi.length; i++) {
var item = abi[i];
if (item.type != "event") continue;
var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")";
var hash = web3.sha3(signature);
if (hash == log.topics[0]) {
event = item;
break;
}
}
if (event != null) {
var inputs = event.inputs.map(function(input) {return input.type;});
var data = SolidityCoder.decodeParams(inputs, log.data.replace("0x", ""));
// Do something with the data. Depends on the log and what you're using the data for.
return {name:event.name , data:data};
}
return null;
}
var event = null;
for (var i = 0; i < abi.length; i++) {
var item = abi[i];
if (item.type != "event") continue;
var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")";
var hash = web3.sha3(signature);
if (hash == log.topics[0]) {
event = item;
break;
}
}
if (event != null) {
var inputs = event.inputs.map(function(input) {return input.type;});
var data = SolidityCoder.decodeParams(inputs, log.data.replace("0x", ""));
// Do something with the data. Depends on the log and what you're using the data for.
return {name:event.name , data:data};
}
return null;
}
var event = null;
for (var i = 0; i < abi.length; i++) {
var item = abi[i];
if (item.type != "event") continue;
var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")";
var hash = web3.sha3(signature);
if (hash == log.topics[0]) {
event = item;
break;
}
}
if (event != null) {
var inputs = event.inputs.map(function(input) {return input.type;});
var data = SolidityCoder.decodeParams(inputs, log.data.replace("0x", ""));
// Do something with the data. Depends on the log and what you're using the data for.
return {name:event.name , data:data};
}
return null;
}
var event = null;
for (var i = 0; i < abi.length; i++) {
var item = abi[i];
if (item.type != "event") continue;
var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")";
var hash = web3.sha3(signature);
if (hash == log.topics[0]) {
event = item;
break;
}
}
if (event != null) {
var inputs = event.inputs.map(function(input) {return input.type;});
var data = SolidityCoder.decodeParams(inputs, log.data.replace("0x", ""));
// Do something with the data. Depends on the log and what you're using the data for.
return {name:event.name , data:data};
}
return null;
}
logs.forEach(function(log) {
var event = self.known_events[log.topics[0]];
if (event == null) {
return;
}
var types = event.abi_entry.inputs.map(function(input) {
return input.indexed == true ? null : input.type;
}).filter(function(type) {
return type != null;
});
var values = SolidityCoder.decodeParams(types, log.data.replace("0x", ""));
var index = 0;
var line = " " + event.abi_entry.name + "(";
line += event.abi_entry.inputs.map(function(input) {
var value;
if (input.indexed == true) {
value = "";
} else {
value = values[index];
index += 1;
}
return input.name + ": " + value.toString();
}).join(", ");
line += ")";
self.logger.log(line);
generate(events, pathPrefix) {
for (let idx = 0; idx < events.length; idx++) {
const event = JSON.parse(events[idx]);
if (event.topics.filter(t => this.lineTopics.indexOf(t) >= 0).length > 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = data[0];
this.coverage[canonicalContractPath].l[data[1].toNumber()] += 1;
} else if (event.topics.filter(t => this.functionTopics.indexOf(t) >= 0).length > 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = data[0];
this.coverage[canonicalContractPath].f[data[1].toNumber()] += 1;
} else if (event.topics.filter(t => this.branchTopics.indexOf(t) >= 0).length > 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = data[0];
this.coverage[canonicalContractPath].b[data[1].toNumber()][data[2].toNumber()] += 1;
} else if (event.topics.filter(t => this.statementTopics.indexOf(t) >= 0).length > 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = data[0];
this.coverage[canonicalContractPath].s[data[1].toNumber()] += 1;
} else if (event.topics.filter(t => this.assertPreTopics.indexOf(t) >= 0).length > 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = data[0];
this.assertCoverage[canonicalContractPath][data[1].toNumber()].preEvents += 1;
} else if (event.topics.filter(t => this.assertPostTopics.indexOf(t) >= 0).length > 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = data[0];
this.assertCoverage[canonicalContractPath][data[1].toNumber()].postEvents += 1;
}
}