BOLT #11: * * `f` (9): `data_length` variable, depending on version. Fallback * on-chain address: for Bitcoin, this starts with a 5-bit `version` * and contains a witness program or P2PKH or P2SH address. */
| 376 | * and contains a witness program or P2PKH or P2SH address. |
| 377 | */ |
| 378 | static const char *decode_f(struct bolt11 *b11, |
| 379 | const struct feature_set *our_features, |
| 380 | struct hash_u5 *hu5, |
| 381 | const u5 **data, size_t *field_len, |
| 382 | bool *have_f) |
| 383 | { |
| 384 | u64 version; |
| 385 | u8 *fallback; |
| 386 | const u5 *orig_data = *data; |
| 387 | size_t orig_len = *field_len; |
| 388 | const char *err; |
| 389 | |
| 390 | /* Read version but don't commit to hash yet */ |
| 391 | err = pull_uint(NULL, &orig_data, &orig_len, &version, 5, false); |
| 392 | if (err) |
| 393 | return tal_fmt(b11, "f: %s", err); |
| 394 | |
| 395 | bool is_known_version = version == 17 || version == 18 || version < 17; |
| 396 | |
| 397 | if (!is_known_version) { |
| 398 | return unknown_field(b11, hu5, data, field_len, 'f'); |
| 399 | } |
| 400 | |
| 401 | /* For known versions, process with hash */ |
| 402 | err = pull_uint(hu5, data, field_len, &version, 5, false); |
| 403 | if (err) |
| 404 | return tal_fmt(b11, "f: %s", err); |
| 405 | |
| 406 | /* BOLT #11: |
| 407 | * |
| 408 | * for Bitcoin payments... MUST set an `f` field to a valid |
| 409 | * witness version and program, OR to `17` followed by a |
| 410 | * public key hash, OR to `18` followed by a script hash. |
| 411 | */ |
| 412 | if (version == 17) { |
| 413 | /* Pay to pubkey hash (P2PKH) */ |
| 414 | struct bitcoin_address *pkhash; |
| 415 | pkhash = pull_all(tmpctx, hu5, data, field_len, false, &err); |
| 416 | if (!pkhash) |
| 417 | return err; |
| 418 | if (tal_bytelen(pkhash) != sizeof(*pkhash)) |
| 419 | return tal_fmt(b11, "f: pkhash length %zu", |
| 420 | tal_bytelen(pkhash)); |
| 421 | fallback = scriptpubkey_p2pkh(b11, pkhash); |
| 422 | } else if (version == 18) { |
| 423 | /* Pay to pubkey script hash (P2SH) */ |
| 424 | struct ripemd160 *shash; |
| 425 | shash = pull_all(tmpctx, hu5, data, field_len, false, &err); |
| 426 | if (!shash) |
| 427 | return err; |
| 428 | if (tal_bytelen(shash) != sizeof(*shash)) |
| 429 | return tal_fmt(b11, "f: p2sh length %zu", |
| 430 | tal_bytelen(shash)); |
| 431 | fallback = scriptpubkey_p2sh_hash(b11, shash); |
| 432 | } else if (version < 17) { |
| 433 | u8 *f = pull_all(tmpctx, hu5, data, field_len, false, &err); |
| 434 | if (!f) |
| 435 | return err; |
nothing calls this directly
no test coverage detected