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

Function get_words

tools/hsmtool.c:422–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420}
421
422static void get_words(struct words **words) {
423 struct wordlist_lang {
424 char *abbr;
425 char *name;
426 };
427
428 struct wordlist_lang languages[] = {
429 {"en", "English"},
430 {"es", "Spanish"},
431 {"fr", "French"},
432 {"it", "Italian"},
433 {"jp", "Japanese"},
434 {"zhs", "Chinese Simplified"},
435 {"zht", "Chinese Traditional"},
436 };
437
438 printf("Select your language:\n");
439 for (size_t i = 0; i < ARRAY_SIZE(languages); i++) {
440 printf(" %zu) %s (%s)\n", i, languages[i].name, languages[i].abbr);
441 }
442 printf("Select [0-%zu]: ", ARRAY_SIZE(languages));
443 fflush(stdout);
444
445 char *selected = NULL;
446 size_t size = 0;
447 size_t characters = getline(&selected, &size, stdin);
448 if (characters < 0)
449 errx(ERROR_USAGE, "Could not read line from stdin.");
450
451 /* To distinguish success/failure after call */
452 errno = 0;
453 char *endptr;
454 long val = strtol(selected, &endptr, 10);
455 if (errno == ERANGE || (errno != 0 && val == 0) || endptr == selected || val < 0 || val >= ARRAY_SIZE(languages))
456 errx(ERROR_USAGE, "Invalid language selection, select one from the list [0-6].");
457
458 bip39_get_wordlist(languages[val].abbr, words);
459}
460
461static void get_mnemonic(char *mnemonic) {
462 char *line = NULL;

Callers 1

read_mnemonicFunction · 0.85

Calls 1

errxFunction · 0.85

Tested by

no test coverage detected