@@ -28,18 +28,40 @@ async function showLogs() {
28
28
//console.log("Response:", response.map(a => a.event));
29
29
30
30
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);
32
37
33
38
// decode the log data
34
39
var decodedData = web3 . eth . abi . decodeLog (
35
40
abi . filter ( abie => abie . name == e . event ) [ 0 ] . inputs ,
36
41
e . data ,
37
42
e . topics
38
- ) ) ;
39
- console . log ( decodedData ) ;
43
+ ) ;
44
+ // console.log(decodedData);
40
45
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 ( "=======" ) ;
43
65
} ) ;
44
66
}
45
67
0 commit comments