Skip to content

Commit 7092d1e

Browse files
committed
proto: update build-proto script and regenerate the TS files
1 parent dc80c67 commit 7092d1e

File tree

13 files changed

+3604
-3578
lines changed

13 files changed

+3604
-3578
lines changed

app/scripts/build-protos.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ const protoSources = async () => {
3636
throw new Error(`go.mod did not match pattern ${POOL_VERSION_PATTERN}`);
3737
}
3838

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+
);
4042
return {
4143
lnd: `lightningnetwork/lnd/${lndVersion[1]}/lnrpc/rpc.proto`,
4244
loop: `lightninglabs/loop/${loopVersion[1]}/looprpc/client.proto`,
@@ -63,7 +65,7 @@ const download = async () => {
6365
for ([name, urlPath] of Object.entries(await protoSources())) {
6466
const url = `https://raw.githubusercontent.com/${urlPath}`;
6567
const filePath = join(appPath, '..', 'proto', `${name}.proto`);
66-
mkdirSync(dirname(filePath), {recursive: true});
68+
mkdirSync(dirname(filePath), { recursive: true });
6769
console.log(`${url}`);
6870
console.log(` -> ${filePath}`);
6971
const content = await new Promise((resolve, reject) => {
@@ -78,6 +80,26 @@ const download = async () => {
7880
}
7981
};
8082

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*(repeated)? u?int64 ((?!jstype).)*$/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+
81103
/**
82104
* Executes the `protoc` compiler to convert *.proto files into TS & JS code
83105
*/
@@ -117,11 +139,6 @@ const patch = async () => {
117139
console.log('\nPatching generated JS files');
118140

119141
for (const filename of Object.keys(filePatches)) {
120-
const patch = [
121-
'/* eslint-disable */',
122-
`var proto = { ${filePatches[filename]} };`,
123-
'',
124-
].join('\n');
125142
const path = join(
126143
appPath,
127144
'src',
@@ -132,7 +149,15 @@ const patch = async () => {
132149

133150
console.log(` - ${path}`);
134151
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');
135159
content = `${patch}\n${content}`;
160+
136161
await fs.writeFile(path, content);
137162
}
138163
};
@@ -143,6 +168,7 @@ const patch = async () => {
143168
const main = async () => {
144169
try {
145170
await download();
171+
await sanitize();
146172
await generate();
147173
await patch();
148174
} catch (error) {

0 commit comments

Comments
 (0)