| 215 | } |
| 216 | |
| 217 | int main(int argc, char *argv[]) |
| 218 | { |
| 219 | const tal_t *ctx = tal(NULL, char); |
| 220 | const char *method; |
| 221 | struct bolt11 *b11; |
| 222 | struct bolt11_field *extra; |
| 223 | const char *fail; |
| 224 | char *description = NULL; |
| 225 | |
| 226 | common_setup(argv[0]); |
| 227 | |
| 228 | opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn); |
| 229 | opt_register_noarg("--help|-h", opt_usage_and_exit, |
| 230 | "<decode> <bolt11> OR\n" |
| 231 | "<encode> <privkey> [<field>=...]*", |
| 232 | "Show this message"); |
| 233 | opt_register_arg("--hashed-description", opt_set_charp, opt_show_charp, |
| 234 | &description, |
| 235 | "Description to check hashed description against"); |
| 236 | opt_register_version(); |
| 237 | |
| 238 | opt_early_parse(argc, argv, opt_log_stderr_exit); |
| 239 | opt_parse(&argc, argv, opt_log_stderr_exit); |
| 240 | |
| 241 | method = argv[1]; |
| 242 | if (!method) |
| 243 | errx(ERROR_USAGE, "Need at least one argument\n%s", |
| 244 | opt_usage(argv[0], NULL)); |
| 245 | |
| 246 | if (streq(method, "encode")) { |
| 247 | struct privkey privkey; |
| 248 | |
| 249 | if (!argv[2] |
| 250 | || !hex_decode(argv[2], strlen(argv[2]), &privkey, sizeof(privkey))) |
| 251 | errx(ERROR_USAGE, "Need valid <privkey>\n%s", |
| 252 | opt_usage(argv[0], NULL)); |
| 253 | encode(ctx, &privkey, argv + 3); |
| 254 | tal_free(ctx); |
| 255 | common_shutdown(); |
| 256 | return NO_ERROR; |
| 257 | } |
| 258 | |
| 259 | if (!streq(method, "decode")) |
| 260 | errx(ERROR_USAGE, "Need encode or decode argument\n%s", |
| 261 | opt_usage(argv[0], NULL)); |
| 262 | |
| 263 | if (!argv[2]) |
| 264 | errx(ERROR_USAGE, "Need argument\n%s", |
| 265 | opt_usage(argv[0], NULL)); |
| 266 | |
| 267 | b11 = bolt11_decode(ctx, argv[2], NULL, description, NULL, &fail); |
| 268 | if (!b11) |
| 269 | errx(ERROR_BAD_DECODE, "%s", fail); |
| 270 | |
| 271 | printf("currency: %s\n", b11->chain->lightning_hrp); |
| 272 | printf("timestamp: %"PRIu64" (%s)\n", |
| 273 | b11->timestamp, fmt_time(ctx, b11->timestamp)); |
| 274 | printf("expiry: %"PRIu64" (%s)\n", |
nothing calls this directly
no test coverage detected