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

Function main

devtools/bolt12-cli.c:457–728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

455}
456
457int main(int argc, char *argv[])
458{
459 const tal_t *ctx = tal(NULL, char);
460 const char *method;
461 char *hrp;
462 u8 *data;
463 char *fail;
464 bool to_hex = false;
465
466 common_setup(argv[0]);
467 deprecated_apis = true;
468
469 opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn);
470 opt_register_noarg("--help|-h", opt_usage_and_exit,
471 "decode|decodehex <bolt12>\n"
472 "encodehex <hrp> <hexstr>...",
473 "Show this message");
474 opt_register_version();
475
476 opt_early_parse(argc, argv, opt_log_stderr_exit);
477 opt_parse(&argc, argv, opt_log_stderr_exit);
478
479 method = argv[1];
480 if (!method)
481 errx(ERROR_USAGE, "Need at least one argument\n%s",
482 opt_usage(argv[0], NULL));
483
484 if (streq(method, "encodehex")) {
485 char *nospaces;
486
487 if (argc < 4)
488 errx(ERROR_USAGE, "Need hrp and hexstr...\n%s",
489 opt_usage(argv[0], NULL));
490 nospaces = tal_arr(ctx, char, 0);
491 for (size_t i = 3; i < argc; i++) {
492 const char *src;
493
494 for (src = argv[i]; *src; src++) {
495 if (cisspace(*src))
496 continue;
497 tal_arr_expand(&nospaces, *src);
498 }
499 }
500 data = tal_hexdata(ctx, nospaces, tal_bytelen(nospaces));
501 if (!data)
502 errx(ERROR_USAGE, "Invalid hexstr\n%s",
503 opt_usage(argv[0], NULL));
504 printf("%s\n", to_bech32_charset(ctx, argv[2], data));
505 goto out;
506 }
507
508 if (streq(method, "decode"))
509 to_hex = false;
510 else if (streq(method, "decodehex"))
511 to_hex = true;
512 else
513 errx(ERROR_USAGE,
514 "Need encodehex/decode/decodehex argument\n%s",

Callers

nothing calls this directly

Calls 15

common_setupFunction · 0.85
opt_set_allocFunction · 0.85
opt_early_parseFunction · 0.85
opt_parseFunction · 0.85
errxFunction · 0.85
opt_usageFunction · 0.85
cisspaceFunction · 0.85
tal_hexdataFunction · 0.85
tal_bytelenFunction · 0.85
tal_hexFunction · 0.85
tal_hexstrFunction · 0.85
offer_decodeFunction · 0.85

Tested by

no test coverage detected