@@ -36,7 +36,9 @@ const protoSources = async () => {
36
36
throw new Error ( `go.mod did not match pattern ${ POOL_VERSION_PATTERN } ` ) ;
37
37
}
38
38
39
- console . log ( `Found lnd version ${ lndVersion [ 1 ] } and loop version ${ loopVersion [ 1 ] } .` ) ;
39
+ console . log (
40
+ `Found:\n LND ${ lndVersion [ 1 ] } \n Loop ${ loopVersion [ 1 ] } \n Pool ${ poolVersion [ 1 ] } ` ,
41
+ ) ;
40
42
return {
41
43
lnd : `lightningnetwork/lnd/${ lndVersion [ 1 ] } /lnrpc/rpc.proto` ,
42
44
loop : `lightninglabs/loop/${ loopVersion [ 1 ] } /looprpc/client.proto` ,
@@ -63,7 +65,7 @@ const download = async () => {
63
65
for ( [ name , urlPath ] of Object . entries ( await protoSources ( ) ) ) {
64
66
const url = `https://raw.githubusercontent.com/${ urlPath } ` ;
65
67
const filePath = join ( appPath , '..' , 'proto' , `${ name } .proto` ) ;
66
- mkdirSync ( dirname ( filePath ) , { recursive : true } ) ;
68
+ mkdirSync ( dirname ( filePath ) , { recursive : true } ) ;
67
69
console . log ( `${ url } ` ) ;
68
70
console . log ( ` -> ${ filePath } ` ) ;
69
71
const content = await new Promise ( ( resolve , reject ) => {
@@ -78,6 +80,26 @@ const download = async () => {
78
80
}
79
81
} ;
80
82
83
+ /**
84
+ * Adds "[jstype = JS_STRING]" to uint64 fields to indicate that they should be
85
+ * represented as strings to avoid Number overflow issues
86
+ */
87
+ const sanitize = async ( ) => {
88
+ const filePaths = Object . keys ( filePatches ) . map ( name =>
89
+ join ( appPath , '..' , 'proto' , `${ name } .proto` ) ,
90
+ ) ;
91
+ for ( path of filePaths ) {
92
+ let content = ( await fs . readFile ( path ) ) . toString ( ) ;
93
+ content = content . replace ( / ^ \s * ( r e p e a t e d ) ? u ? i n t 6 4 ( (? ! j s t y p e ) .) * $ / gm, match => {
94
+ // add the jstype descriptor
95
+ return / ^ .* ] ; $ / . test ( match )
96
+ ? match . replace ( / \s * ] ; $ / , `, jstype = JS_STRING];` )
97
+ : match . replace ( / ; $ / , ` [jstype = JS_STRING];` ) ;
98
+ } ) ;
99
+ await fs . writeFile ( path , content ) ;
100
+ }
101
+ } ;
102
+
81
103
/**
82
104
* Executes the `protoc` compiler to convert *.proto files into TS & JS code
83
105
*/
@@ -117,11 +139,6 @@ const patch = async () => {
117
139
console . log ( '\nPatching generated JS files' ) ;
118
140
119
141
for ( const filename of Object . keys ( filePatches ) ) {
120
- const patch = [
121
- '/* eslint-disable */' ,
122
- `var proto = { ${ filePatches [ filename ] } };` ,
123
- '' ,
124
- ] . join ( '\n' ) ;
125
142
const path = join (
126
143
appPath ,
127
144
'src' ,
@@ -132,7 +149,15 @@ const patch = async () => {
132
149
133
150
console . log ( ` - ${ path } ` ) ;
134
151
let content = await fs . readFile ( path ) ;
152
+
153
+ // apply the webpack patch
154
+ const patch = [
155
+ '/* eslint-disable */' ,
156
+ `var proto = { ${ filePatches [ filename ] } };` ,
157
+ '' ,
158
+ ] . join ( '\n' ) ;
135
159
content = `${ patch } \n${ content } ` ;
160
+
136
161
await fs . writeFile ( path , content ) ;
137
162
}
138
163
} ;
@@ -143,6 +168,7 @@ const patch = async () => {
143
168
const main = async ( ) => {
144
169
try {
145
170
await download ( ) ;
171
+ await sanitize ( ) ;
146
172
await generate ( ) ;
147
173
await patch ( ) ;
148
174
} catch ( error ) {
0 commit comments