@@ -3,12 +3,28 @@ import * as fs from 'fs';
3
3
import * as os from 'os' ;
4
4
import * as path from 'path' ;
5
5
6
- interface DecodeArgsOptions {
7
- target : string ;
8
- rpc_url ?: string ;
9
- default ?: boolean ;
10
- skip_resolving ?: boolean ;
11
- raw ?: boolean ;
6
+ class DecodeResult {
7
+ public name : string ;
8
+ public signature : string ;
9
+ public inputs : any [ ] ;
10
+ public decoded_inputs : any [ ] ;
11
+
12
+ constructor ( path : string ) {
13
+ // walk the directory and find the json file
14
+ const files = fs . readdirSync ( path ) ;
15
+ const jsonFile = files . find ( ( file ) => file . endsWith ( '.json' ) ) ;
16
+ if ( ! jsonFile ) {
17
+ throw new Error ( '`decoded.json` not found' ) ;
18
+ }
19
+
20
+ const data = JSON . parse ( fs . readFileSync
21
+ ( path + '/' + jsonFile , 'utf8' ) ) ;
22
+
23
+ this . name = data . name ;
24
+ this . signature = data . signature ;
25
+ this . inputs = data . inputs ;
26
+ this . decoded_inputs = data . decoded_inputs ;
27
+ }
12
28
}
13
29
14
30
class DecodeArgs {
@@ -44,7 +60,7 @@ class Decoder {
44
60
try {
45
61
const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'decoder-' ) ) ;
46
62
47
- const command = [ 'decode' , this . args . target , ] ;
63
+ const command = [ 'decode' , this . args . target , "--output" , tempDir ] ;
48
64
49
65
if ( this . args . rpc_url ) {
50
66
command . push ( '--rpc-url' , this . args . rpc_url ) ;
@@ -62,9 +78,8 @@ class Decoder {
62
78
// Execute heimdall command
63
79
execSync ( `heimdall ${ command . join ( ' ' ) } ` , { stdio : 'inherit' } ) ;
64
80
65
- // Here you would read and parse the output from `tempDir`
66
- // For now, we return null since the original code doesn't show the parsing step.
67
- return null ;
81
+ let result = new DecodeResult ( tempDir ) ;
82
+ return result
68
83
} catch ( e ) {
69
84
console . error ( "Error: " , e ) ;
70
85
return null ;
@@ -89,15 +104,15 @@ function main() {
89
104
}
90
105
91
106
const args = new DecodeArgs (
92
- "0x000000000000000000000000008dfede2ef0e61578c3bba84a7ed4b9d25795c30000000000000000000000000000000000000001431e0fae6d7217caa00000000000000000000000000000000000000000000000000000000000000000002710fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc7c0000000000000000000000000000000000000000000000a6af776004abf4e612ad000000000000000000000000000000000000000000000000000000012a05f20000000000000000000000000000000000000000000000000000000000000111700000000000000000000000001c5f545f5b46f76e440fa02dabf88fdc0b10851a00000000000000000000000000000000000000000000000000000002540be400 " ,
107
+ "0xc47f00270000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b6a6265636b65722e657468000000000000000000000000000000000000000000 " ,
93
108
"" ,
94
109
false ,
95
110
false ,
96
111
true
97
112
) ;
98
113
99
114
const decoded = new Decoder ( args ) . decode ( ) ;
100
- console . log ( "Decoded Result:" , decoded ) ;
115
+ console . log ( decoded ) ;
101
116
}
102
117
103
118
main ( ) ;
0 commit comments