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

Function main

devtools/bolt12-cli.c:744–1222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

742}
743
744int main(int argc, char *argv[])
745{
746 const tal_t *ctx = tal(NULL, char);
747 const char *method;
748 char *hrp;
749 u8 *data;
750 const char *fail;
751 bool to_hex = false;
752
753 common_setup(argv[0]);
754
755 opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn);
756 opt_register_noarg("--help|-h", opt_usage_and_exit,
757 "decode|decodehex <bolt12>\n"
758 "encodehex <hrp> <hexstr>...\n"
759 "encode <hrp> [<tlvname> <tlvval>]...",
760 "Show this message");
761 opt_register_version();
762
763 opt_early_parse(argc, argv, opt_log_stderr_exit);
764 opt_parse(&argc, argv, opt_log_stderr_exit);
765
766 method = argv[1];
767 if (!method)
768 errx(ERROR_USAGE, "Need at least one argument\n%s",
769 opt_usage(argv[0], NULL));
770
771 if (streq(method, "encodehex")) {
772 char *nospaces;
773
774 if (argc < 4)
775 errx(ERROR_USAGE, "Need hrp and hexstr...\n%s",
776 opt_usage(argv[0], NULL));
777 nospaces = tal_arr(ctx, char, 0);
778 for (size_t i = 3; i < argc; i++) {
779 const char *src;
780
781 for (src = argv[i]; *src; src++) {
782 if (cisspace(*src))
783 continue;
784 tal_arr_expand(&nospaces, *src);
785 }
786 }
787 data = tal_hexdata(ctx, nospaces, tal_bytelen(nospaces));
788 if (!data)
789 errx(ERROR_USAGE, "Invalid hexstr\n%s",
790 opt_usage(argv[0], NULL));
791 printf("%s\n", to_bech32_charset(ctx, argv[2], data));
792 goto out;
793 }
794 if (streq(method, "encode")) {
795 data = tal_arr(ctx, u8, 0);
796
797 /* We encode literally, to make it possible to create invalid ones for
798 * testing! */
799 for (size_t i = 3; i < argc; i += 2) {
800 u64 tlvtype = get_offer_type(argv[i]);
801 u8 *tlvval = get_tlv_val(ctx, argv[i+1]);

Callers

nothing calls this directly

Calls 15

common_setupFunction · 0.85
opt_set_allocFunction · 0.85
opt_register_versionFunction · 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
get_offer_typeFunction · 0.85
get_tlv_valFunction · 0.85

Tested by

no test coverage detected