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

Function main

devtools/onion.c:334–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

setup_localeFunction · 0.85
opt_set_allocFunction · 0.85
opt_register_versionFunction · 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