MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

devtools/onion.c:335–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333}
334
335int main(int argc, char **argv)
336{
337 setup_locale();
338 const char *method;
339 u8 *assocdata = NULL;
340 struct node_id rendezvous_id;
341 memset(&rendezvous_id, 0, sizeof(struct node_id));
342
343 secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY |
344 SECP256K1_CONTEXT_SIGN);
345
346 opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn);
347 opt_register_arg("--assoc-data", opt_set_ad, opt_show_ad, &assocdata,
348 "Associated data (usu. payment_hash of payment)");
349 opt_register_arg("--rendezvous-id", opt_set_node_id, NULL,
350 &rendezvous_id, "Node ID of the rendez-vous node");
351 opt_register_noarg("--help|-h", opt_usage_and_exit,
352 "\n\n\tdecode <onion_file> <privkey>\n"
353 "\tgenerate <pubkey1> <pubkey2> ...\n"
354 "\tgenerate <pubkey1>[/hopdata|/tlv] <pubkey2>[/hopdata|/tlv]\n"
355 "\tgenerate <privkey1>[/hopdata|/tlv] <privkey2>[/hopdata|/tlv]\n"
356 "\truntest <test-filename>\n\n", "Show this message\n\n"
357 "\texample:\n"
358 "\t> onion generate 02c18e7ff9a319983e85094b8c957da5c1230ecb328c1f1c7e88029f1fec2046f8/00000000000000000000000000000f424000000138000000000000000000000000 --assoc-data 44ee26f01e54665937b892f6afbfdfb88df74bcca52d563f088668cf4490aacd > onion.dat\n"
359 "\t> onion decode onion.dat 78302c8edb1b94e662464e99af721054b6ab9d577d3189f933abde57709c5cb8 --assoc-data 44ee26f01e54665937b892f6afbfdfb88df74bcca52d563f088668cf4490aacd\n");
360 opt_register_version();
361
362 opt_early_parse(argc, argv, opt_log_stderr_exit);
363 opt_parse(&argc, argv, opt_log_stderr_exit);
364
365 if (argc < 2)
366 errx(1, "You must specify a method");
367 method = argv[1];
368
369 if (streq(method, "runtest")) {
370 if (argc != 3)
371 errx(1, "'runtest' requires a filename argument");
372 runtest(argv[2]);
373 } else if (streq(method, "generate")) {
374 if (memeqzero(&rendezvous_id, sizeof(rendezvous_id)))
375 do_generate(argc, argv, assocdata, NULL);
376 else
377 do_generate(argc, argv, assocdata, &rendezvous_id);
378 } else if (streq(method, "decompress")) {
379 if (argc != 4) {
380 errx(2,
381 "'%s decompress' requires a private key and a "
382 "compressed onion",
383 argv[0]);
384 }
385
386 decompress(argv[2], argv[3]);
387 } else if (streq(method, "decode")) {
388 do_decode(argc, argv, assocdata);
389 } else {
390 errx(1, "Unrecognized method '%s'", method);
391 }
392 return 0;

Callers

nothing calls this directly

Calls 10

setup_localeFunction · 0.85
opt_set_allocFunction · 0.85
opt_early_parseFunction · 0.85
opt_parseFunction · 0.85
errxFunction · 0.85
runtestFunction · 0.85
memeqzeroFunction · 0.85
do_generateFunction · 0.85
decompressFunction · 0.85
do_decodeFunction · 0.85

Tested by

no test coverage detected