Skip to content

Commit ca4f566

Browse files
committed
app: fix build-protos for new swapserverrpc package
The swapserverrpc package has a few oddities which we need to address with rewrites and replaces. There seems to be a weird behavior with regex replace functions that required the replaces to be re-written into two separate ones.
1 parent e75e9bc commit ca4f566

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

app/scripts/build-protos.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ const protoSources = async () => {
4242
return {
4343
lnd: `lightningnetwork/lnd/${lndVersion[1]}/lnrpc/lightning.proto`,
4444
loop: `lightninglabs/loop/${loopVersion[1]}/looprpc/client.proto`,
45-
common: `lightninglabs/loop/${loopVersion[1]}/looprpc/common.proto`,
45+
'swapserverrpc/server': `lightninglabs/loop/${loopVersion[1]}/swapserverrpc/server.proto`,
46+
'swapserverrpc/common': `lightninglabs/loop/${loopVersion[1]}/swapserverrpc/common.proto`,
4647
trader: `lightninglabs/pool/${poolVersion[1]}/poolrpc/trader.proto`,
4748
'auctioneerrpc/auctioneer': `lightninglabs/pool/${poolVersion[1]}/auctioneerrpc/auctioneer.proto`,
4849
};
@@ -58,7 +59,11 @@ const filePatches = {
5859
patch: 'looprpc: {}',
5960
folder: 'proto',
6061
},
61-
common: {
62+
'swapserverrpc/common': {
63+
patch: 'looprpc: {}',
64+
folder: 'proto'
65+
},
66+
'swapserverrpc/server': {
6267
patch: 'looprpc: {}',
6368
folder: 'proto',
6469
},
@@ -109,12 +114,15 @@ const sanitize = async () => {
109114
);
110115
for (path of filePaths) {
111116
let content = (await fs.readFile(path)).toString();
112-
content = content.replace(/^\s*(repeated)? u?int64 ((?!jstype).)*$/gm, match => {
113-
// add the jstype descriptor
114-
return /^.*];$/.test(match)
115-
? match.replace(/\s*];$/, `, jstype = JS_STRING];`)
116-
: match.replace(/;$/, ` [jstype = JS_STRING];`);
117-
});
117+
content = content.replace(
118+
/^(\s*)(repeated )?(u?int64) (\S+) = (\d+);$/gm,
119+
'$1$2$3 $4 = $5 [jstype = JS_STRING];'
120+
);
121+
content = content.replace(
122+
/^(\s*)(repeated )?(u?int64) (\S+) = (\d+) \[((?!jstype).*)];$/gm,
123+
'$1$2$3 $4 = $5 [$6, jstype = JS_STRING];'
124+
);
125+
content = content.replace("import \"common.proto\"", "import \"swapserverrpc/common.proto\"")
118126
await fs.writeFile(path, content);
119127
}
120128
};

0 commit comments

Comments
 (0)