@@ -26,72 +26,92 @@ async function main() {
26
26
27
27
// make sure func compiler is available
28
28
const minSupportFunc = "0.2.0" ;
29
+
29
30
try {
30
31
const funcVersion = child_process
31
32
. execSync ( "func -V" )
32
33
. toString ( )
33
34
. match ( / s e m a n t i c v e r s i o n : v ( [ 0 - 9 . ] + ) / ) ?. [ 1 ] ;
34
- if ( ! semver . gte ( semver . coerce ( funcVersion ) ?? "" , minSupportFunc ) ) throw new Error ( "Nonexistent version or outdated" ) ;
35
+
36
+ if ( ! semver . gte ( semver . coerce ( funcVersion ) ?? "" , minSupportFunc ) ) {
37
+ throw new Error ( "Nonexistent version or outdated" ) ;
38
+ }
35
39
} catch ( e ) {
36
40
console . log ( `\nFATAL ERROR: 'func' with version >= ${ minSupportFunc } executable is not found, is it installed and in path?` ) ;
37
41
process . exit ( 1 ) ;
38
42
}
39
43
40
44
// make sure fift cli is available
41
45
let fiftVersion = "" ;
46
+
42
47
try {
43
48
fiftVersion = child_process . execSync ( "fift -V" ) . toString ( ) ;
44
- } catch ( e ) { }
49
+ } catch ( e ) {
50
+ console . error ( e ) ;
51
+ }
52
+
45
53
if ( ! fiftVersion . includes ( "Fift build information" ) ) {
46
54
console . log ( "\nFATAL ERROR: 'fift' executable is not found, is it installed and in path?" ) ;
47
55
process . exit ( 1 ) ;
48
56
}
49
57
50
58
// go over all the root contracts in the contracts directory
51
59
const rootContracts = glob . sync ( [ "contracts/*.fc" , "contracts/*.func" ] ) ;
60
+
52
61
for ( const rootContract of rootContracts ) {
53
62
// compile a new root contract
54
63
console . log ( `\n* Found root contract '${ rootContract } ' - let's compile it:` ) ;
55
64
const contractName = path . parse ( rootContract ) . name ;
56
65
57
66
// delete existing build artifacts
58
67
const fiftArtifact = `build/${ contractName } .fif` ;
68
+
59
69
if ( fs . existsSync ( fiftArtifact ) ) {
60
70
console . log ( ` - Deleting old build artifact '${ fiftArtifact } '` ) ;
61
71
fs . unlinkSync ( fiftArtifact ) ;
62
72
}
73
+
63
74
const mergedFuncArtifact = `build/${ contractName } .merged.fc` ;
75
+
64
76
if ( fs . existsSync ( mergedFuncArtifact ) ) {
65
77
console . log ( ` - Deleting old build artifact '${ mergedFuncArtifact } '` ) ;
66
78
fs . unlinkSync ( mergedFuncArtifact ) ;
67
79
}
80
+
68
81
const fiftCellArtifact = `build/${ contractName } .cell.fif` ;
82
+
69
83
if ( fs . existsSync ( fiftCellArtifact ) ) {
70
84
console . log ( ` - Deleting old build artifact '${ fiftCellArtifact } '` ) ;
71
85
fs . unlinkSync ( fiftCellArtifact ) ;
72
86
}
87
+
73
88
const cellArtifact = `build/${ contractName } .cell` ;
89
+
74
90
if ( fs . existsSync ( cellArtifact ) ) {
75
91
console . log ( ` - Deleting old build artifact '${ cellArtifact } '` ) ;
76
92
fs . unlinkSync ( cellArtifact ) ;
77
93
}
94
+
78
95
const hexArtifact = `build/${ contractName } .compiled.json` ;
96
+
79
97
if ( fs . existsSync ( hexArtifact ) ) {
80
98
console . log ( ` - Deleting old build artifact '${ hexArtifact } '` ) ;
81
99
fs . unlinkSync ( hexArtifact ) ;
82
100
}
83
101
84
102
// check if we have a tlb file
85
103
const tlbFile = `contracts/${ contractName } .tlb` ;
104
+
86
105
if ( fs . existsSync ( tlbFile ) ) {
87
106
console . log ( ` - TL-B file '${ tlbFile } ' found, calculating crc32 on all ops..` ) ;
88
107
const tlbContent = fs . readFileSync ( tlbFile ) . toString ( ) ;
89
- const tlbOpMessages = tlbContent . match ( / ^ ( \w + ) .* = \s * I n t e r n a l M s g B o d y $ / gm) ?? [ ] ;
108
+ const tlbOpMessages = tlbContent . match ( / ^ ( \w + ) [ \w \s : ^ ] * = \s * I n t e r n a l M s g B o d y ; ? $ / gm) ?? [ ] ;
109
+
90
110
for ( const tlbOpMessage of tlbOpMessages ) {
91
111
const crc = crc32 ( tlbOpMessage ) ;
92
112
const asQuery = `0x${ ( crc & 0x7fffffff ) . toString ( 16 ) } ` ;
93
113
const asResponse = `0x${ ( ( crc | 0x80000000 ) >>> 0 ) . toString ( 16 ) } ` ;
94
- console . log ( ` op '${ tlbOpMessage . split ( " " ) [ 0 ] } ': '${ asQuery } ' as query (&0x7fffffff), '${ asResponse } ' as response (|0x80000000)` ) ;
114
+ console . log ( ` op '${ tlbOpMessage . split ( / [ \n ] / ) [ 0 ] } ': '${ asQuery } ' as query (&0x7fffffff), '${ asResponse } ' as response (|0x80000000)` ) ;
95
115
}
96
116
} else {
97
117
console . log ( ` - Warning: TL-B file for contract '${ tlbFile } ' not found, are your op consts according to standard?` ) ;
@@ -100,11 +120,15 @@ async function main() {
100
120
// run the func compiler to create a fif file
101
121
console . log ( ` - Trying to compile '${ rootContract } ' with 'func' compiler..` ) ;
102
122
let buildErrors : string ;
123
+
103
124
try {
104
125
buildErrors = child_process . execSync ( `func -APS -o build/${ contractName } .fif ${ rootContract } 2>&1 1>node_modules/.tmpfunc` ) . toString ( ) ;
105
126
} catch ( e ) {
127
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
128
+ // @ts -ignore
106
129
buildErrors = e . stdout . toString ( ) ;
107
130
}
131
+
108
132
if ( buildErrors . length > 0 ) {
109
133
console . log ( " - OH NO! Compilation Errors! The compiler output was:" ) ;
110
134
console . log ( `\n${ buildErrors } ` ) ;
@@ -122,7 +146,7 @@ async function main() {
122
146
}
123
147
124
148
// create a temp cell.fif that will generate the cell
125
- let fiftCellSource = '" Asm.fif" include\n' ;
149
+ let fiftCellSource = "\" Asm.fif\ " include\n" ;
126
150
fiftCellSource += `${ fs . readFileSync ( fiftArtifact ) . toString ( ) } \n` ;
127
151
fiftCellSource += `boc>B "${ cellArtifact } " B>file` ;
128
152
fs . writeFileSync ( fiftCellArtifact , fiftCellSource ) ;
@@ -146,10 +170,14 @@ async function main() {
146
170
console . log ( ` - Build artifact created '${ cellArtifact } '` ) ;
147
171
}
148
172
173
+ const codeHash = Cell . fromBoc ( fs . readFileSync ( cellArtifact ) ) [ 0 ] . hash ( ) ;
174
+
149
175
fs . writeFileSync (
150
176
hexArtifact ,
151
177
JSON . stringify ( {
152
178
hex : Cell . fromBoc ( fs . readFileSync ( cellArtifact ) ) [ 0 ] . toBoc ( ) . toString ( "hex" ) ,
179
+ hash : codeHash . toString ( "hex" ) ,
180
+ hashBase64 : codeHash . toString ( "base64" ) ,
153
181
} )
154
182
) ;
155
183
@@ -168,16 +196,28 @@ async function main() {
168
196
console . log ( "" ) ;
169
197
}
170
198
171
- main ( ) ;
199
+ main ( ) . then ( ( ) => console . log ( "Success" ) ) ;
172
200
173
201
// helpers
174
202
175
203
function crc32 ( r : string ) {
176
- for ( var a , o = [ ] , c = 0 ; c < 256 ; c ++ ) {
204
+ const o = [ ] ;
205
+
206
+ for ( let a , c = 0 ; c < 256 ; c ++ ) {
177
207
a = c ;
178
- for ( let f = 0 ; f < 8 ; f ++ ) a = 1 & a ? 3988292384 ^ ( a >>> 1 ) : a >>> 1 ;
208
+
209
+ for ( let f = 0 ; f < 8 ; f ++ ) {
210
+ a = 1 & a ? 3988292384 ^ ( a >>> 1 ) : a >>> 1 ;
211
+ }
212
+
179
213
o [ c ] = a ;
180
214
}
181
- for ( var n = - 1 , t = 0 ; t < r . length ; t ++ ) n = ( n >>> 8 ) ^ o [ 255 & ( n ^ r . charCodeAt ( t ) ) ] ;
215
+
216
+ let n = - 1 ;
217
+
218
+ for ( let t = 0 ; t < r . length ; t ++ ) {
219
+ n = ( n >>> 8 ) ^ o [ 255 & ( n ^ r . charCodeAt ( t ) ) ] ;
220
+ }
221
+
182
222
return ( - 1 ^ n ) >>> 0 ;
183
223
}
0 commit comments