| 49 | } |
| 50 | |
| 51 | int main(int argc, char *argv[]) |
| 52 | { |
| 53 | const tal_t *ctx = tal(NULL, char); |
| 54 | const char *method; |
| 55 | struct bolt11 *b11; |
| 56 | struct bolt11_field *extra; |
| 57 | char *fail, *description = NULL; |
| 58 | |
| 59 | common_setup(argv[0]); |
| 60 | |
| 61 | opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn); |
| 62 | opt_register_noarg("--help|-h", opt_usage_and_exit, |
| 63 | "<decode> <bolt11>", "Show this message"); |
| 64 | opt_register_arg("--hashed-description", opt_set_charp, opt_show_charp, |
| 65 | &description, |
| 66 | "Description to check hashed description against"); |
| 67 | opt_register_version(); |
| 68 | |
| 69 | opt_early_parse(argc, argv, opt_log_stderr_exit); |
| 70 | opt_parse(&argc, argv, opt_log_stderr_exit); |
| 71 | |
| 72 | method = argv[1]; |
| 73 | if (!method) |
| 74 | errx(ERROR_USAGE, "Need at least one argument\n%s", |
| 75 | opt_usage(argv[0], NULL)); |
| 76 | |
| 77 | if (!streq(method, "decode")) |
| 78 | errx(ERROR_USAGE, "Need decode argument\n%s", |
| 79 | opt_usage(argv[0], NULL)); |
| 80 | |
| 81 | if (!argv[2]) |
| 82 | errx(ERROR_USAGE, "Need argument\n%s", |
| 83 | opt_usage(argv[0], NULL)); |
| 84 | |
| 85 | b11 = bolt11_decode(ctx, argv[2], NULL, description, NULL, &fail); |
| 86 | if (!b11) |
| 87 | errx(ERROR_BAD_DECODE, "%s", fail); |
| 88 | |
| 89 | printf("currency: %s\n", b11->chain->lightning_hrp); |
| 90 | printf("timestamp: %"PRIu64" (%s)\n", |
| 91 | b11->timestamp, fmt_time(ctx, b11->timestamp)); |
| 92 | printf("expiry: %"PRIu64" (%s)\n", |
| 93 | b11->expiry, fmt_time(ctx, b11->timestamp + b11->expiry)); |
| 94 | printf("payee: %s\n", |
| 95 | type_to_string(ctx, struct node_id, &b11->receiver_id)); |
| 96 | printf("payment_hash: %s\n", |
| 97 | tal_hexstr(ctx, &b11->payment_hash, sizeof(b11->payment_hash))); |
| 98 | printf("min_final_cltv_expiry: %u\n", b11->min_final_cltv_expiry); |
| 99 | if (b11->msat) { |
| 100 | printf("msatoshi: %"PRIu64"\n", b11->msat->millisatoshis); /* Raw: raw int for backwards compat */ |
| 101 | printf("amount_msat: %s\n", |
| 102 | type_to_string(tmpctx, struct amount_msat, b11->msat)); |
| 103 | } |
| 104 | if (b11->description) |
| 105 | printf("description: '%s'\n", b11->description); |
| 106 | if (b11->description_hash) |
| 107 | printf("description_hash: %s\n", |
| 108 | tal_hexstr(ctx, b11->description_hash, |
nothing calls this directly
no test coverage detected