Skip to content

Commit 53cb014

Browse files
committed
devtools/blindedpath: add --simple-output for use from python.
Normal output is suitable for feeding to devtools/onion, but for python tests we want something simpler. Ideally, we'd simply generate blinded paths in pyln. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 3884bc3 commit 53cb014

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

devtools/blindedpath.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <string.h>
2020
#include <unistd.h>
2121

22+
static bool simpleout = false;
23+
2224
/* Tal wrappers for opt. */
2325
static void *opt_allocfn(size_t size)
2426
{
@@ -99,6 +101,8 @@ int main(int argc, char **argv)
99101
"Show this message");
100102
opt_register_noarg("--first-node", opt_set_bool, &first,
101103
"Don't try to tweak key to unwrap onion");
104+
opt_register_noarg("--simple-output", opt_set_bool, &simpleout,
105+
"Output values without prefixes, one per line");
102106
opt_register_version();
103107

104108
opt_parse(&argc, argv, opt_log_stderr_exit);
@@ -158,8 +162,12 @@ int main(int argc, char **argv)
158162
}
159163

160164
/* Print initial blinding factor */
161-
printf("Blinding: %s\n",
162-
type_to_string(tmpctx, struct pubkey, &pk_e[0]));
165+
if (simpleout)
166+
printf("%s\n",
167+
type_to_string(tmpctx, struct pubkey, &pk_e[0]));
168+
else
169+
printf("Blinding: %s\n",
170+
type_to_string(tmpctx, struct pubkey, &pk_e[0]));
163171

164172
for (size_t i = 0; i < num - 1; i++) {
165173
u8 *p;
@@ -192,16 +200,28 @@ int main(int argc, char **argv)
192200
towire_onionmsg_payload(&p, outer);
193201
ret = bigsize_put(buf, tal_bytelen(p));
194202

195-
/* devtools/onion wants length explicitly prepended */
196-
printf("%s/%.*s%s ",
197-
type_to_string(tmpctx, struct pubkey, &b[i]),
198-
ret * 2,
199-
tal_hexstr(tmpctx, buf, ret),
200-
tal_hex(tmpctx, p));
203+
if (simpleout) {
204+
printf("%s\n%s\n",
205+
type_to_string(tmpctx, struct pubkey,
206+
&b[i]),
207+
tal_hex(tmpctx, outer->enctlv->enctlv));
208+
} else {
209+
/* devtools/onion wants length explicitly prepended */
210+
printf("%s/%.*s%s ",
211+
type_to_string(tmpctx, struct pubkey,
212+
&b[i]),
213+
ret * 2,
214+
tal_hexstr(tmpctx, buf, ret),
215+
tal_hex(tmpctx, p));
216+
}
201217
}
202218
/* No payload for last node */
203-
printf("%s/00\n",
204-
type_to_string(tmpctx, struct pubkey, &b[num-1]));
219+
if (simpleout)
220+
printf("%s\n",
221+
type_to_string(tmpctx, struct pubkey, &b[num-1]));
222+
else
223+
printf("%s/00\n",
224+
type_to_string(tmpctx, struct pubkey, &b[num-1]));
205225
} else if (streq(argv[1], "unwrap")) {
206226
struct privkey privkey;
207227
struct pubkey blinding;

0 commit comments

Comments
 (0)