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

Function main

tools/hsmtool.c:653–742  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

651}
652
653int main(int argc, char *argv[])
654{
655 const char *method;
656
657 setup_locale();
658 err_set_progname(argv[0]);
659
660 method = argc > 1 ? argv[1] : NULL;
661 if (!method)
662 show_usage(argv[0]);
663
664 if (streq(method, "decrypt")) {
665 if (argc < 3)
666 show_usage(argv[0]);
667 return decrypt_hsm(argv[2]);
668 }
669
670 if (streq(method, "encrypt")) {
671 if (argc < 3)
672 show_usage(argv[0]);
673 return encrypt_hsm(argv[2]);
674 }
675
676 if (streq(method, "dumpcommitments")) {
677 /* node_id channel_id depth hsm_secret */
678 if (argc < 6)
679 show_usage(argv[0]);
680 struct node_id node_id;
681 if (!node_id_from_hexstr(argv[2], strlen(argv[2]), &node_id))
682 errx(ERROR_USAGE, "Bad node id");
683 return dump_commitments_infos(&node_id, atol(argv[3]), atol(argv[4]),
684 argv[5]);
685 }
686
687 if (streq(method, "guesstoremote")) {
688 /* address node_id depth hsm_secret */
689 if (argc < 6)
690 show_usage(argv[0]);
691 struct node_id node_id;
692 if (!node_id_from_hexstr(argv[3], strlen(argv[3]), &node_id))
693 errx(ERROR_USAGE, "Bad node id");
694 return guess_to_remote(argv[2], &node_id, atol(argv[4]),
695 argv[5]);
696 }
697
698 if (streq(method, "generatehsm")) {
699 if (argc != 3)
700 show_usage(argv[0]);
701
702 char *hsm_secret_path = argv[2];
703
704 /* if hsm_secret already exists we abort the process
705 * we do not want to lose someone else's funds */
706 struct stat st;
707 if (stat(hsm_secret_path, &st) == 0)
708 errx(ERROR_USAGE, "hsm_secret file at %s already exists", hsm_secret_path);
709
710 return generate_hsm(hsm_secret_path);

Callers

nothing calls this directly

Calls 13

setup_localeFunction · 0.85
err_set_prognameFunction · 0.85
show_usageFunction · 0.85
decrypt_hsmFunction · 0.85
encrypt_hsmFunction · 0.85
errxFunction · 0.85
dump_commitments_infosFunction · 0.85
guess_to_remoteFunction · 0.85
generate_hsmFunction · 0.85
dumponchaindescriptorsFunction · 0.85
check_hsmFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected