Skip to content

Commit 276f1e6

Browse files
committed
Update log record decoding and printing format
1 parent 87d5623 commit 276f1e6

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

tools/get_logs.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,40 @@ async function showLogs() {
2828
//console.log("Response:", response.map(a => a.event));
2929

3030
response.forEach(e => {
31-
//console.log(abi.filter(abie => abie.name == e.event)[0].inputs);
31+
const eventAbi = abi.filter(abie => abie.name == e.event)[0];
32+
const firstArg = eventAbi.inputs[0];
33+
const recArg = eventAbi.inputs[1].components;
34+
const recArgParentName = eventAbi.inputs[1].name;
35+
36+
//console.log(eventAbi);
3237

3338
// decode the log data
3439
var decodedData = web3.eth.abi.decodeLog(
3540
abi.filter(abie => abie.name == e.event)[0].inputs,
3641
e.data,
3742
e.topics
38-
));
39-
console.log(decodedData);
43+
);
44+
//console.log(decodedData);
4045

41-
//
42-
46+
console.log("=== Type:", e.event, " ===");
47+
console.log(firstArg.name, ":", web3.utils.hexToAscii(decodedData[firstArg.name]));
48+
if (recArg) {
49+
recArg.forEach(r => {
50+
var value = decodedData[recArgParentName][r.name];
51+
if (typeof(value) == typeof({})) {
52+
const subrecArg = r.components;
53+
subrecArg.forEach(sr => {
54+
var subvalue = decodedData[recArgParentName][r.name][sr.name];
55+
if (sr.type == 'bytes') { subvalue = web3.utils.hexToAscii(subvalue); }
56+
console.log(r.name + "." + sr.name, ":", subvalue);
57+
});
58+
} else {
59+
if (r.type == 'bytes') { value = web3.utils.hexToAscii(value); }
60+
console.log(r.name, ":", value);
61+
}
62+
});
63+
}
64+
console.log("=======");
4365
});
4466
}
4567

0 commit comments

Comments
 (0)