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. */
| 352 | * and contains a witness program or P2PKH or P2SH address. |
| 353 | */ |
| 354 | static char *decode_f(struct bolt11 *b11, |
| 355 | struct hash_u5 *hu5, |
| 356 | u5 **data, size_t *data_len, |
| 357 | size_t data_length) |
| 358 | { |
| 359 | u64 version; |
| 360 | u8 *fallback; |
| 361 | |
| 362 | if (!pull_uint(hu5, data, data_len, &version, 5)) |
| 363 | return tal_fmt(b11, "f: data_length %zu short", data_length); |
| 364 | data_length--; |
| 365 | |
| 366 | /* BOLT #11: |
| 367 | * |
| 368 | * for Bitcoin payments... MUST set an `f` field to a valid |
| 369 | * witness version and program, OR to `17` followed by a |
| 370 | * public key hash, OR to `18` followed by a script hash. |
| 371 | */ |
| 372 | if (version == 17) { |
| 373 | /* Pay to pubkey hash (P2PKH) */ |
| 374 | struct bitcoin_address pkhash; |
| 375 | if (num_u8(data_length) != sizeof(pkhash)) |
| 376 | return tal_fmt(b11, "f: pkhash length %zu", |
| 377 | data_length); |
| 378 | |
| 379 | pull_bits_certain(hu5, data, data_len, &pkhash, data_length*5, |
| 380 | false); |
| 381 | fallback = scriptpubkey_p2pkh(b11, &pkhash); |
| 382 | } else if (version == 18) { |
| 383 | /* Pay to pubkey script hash (P2SH) */ |
| 384 | struct ripemd160 shash; |
| 385 | if (num_u8(data_length) != sizeof(shash)) |
| 386 | return tal_fmt(b11, "f: p2sh length %zu", |
| 387 | data_length); |
| 388 | |
| 389 | pull_bits_certain(hu5, data, data_len, &shash, data_length*5, |
| 390 | false); |
| 391 | fallback = scriptpubkey_p2sh_hash(b11, &shash); |
| 392 | } else if (version < 17) { |
| 393 | u8 *f = tal_arr(b11, u8, data_length * 5 / 8); |
| 394 | if (version == 0) { |
| 395 | if (tal_count(f) != 20 && tal_count(f) != 32) |
| 396 | return tal_fmt(b11, |
| 397 | "f: witness v0 bad length %zu", |
| 398 | data_length); |
| 399 | } |
| 400 | pull_bits_certain(hu5, data, data_len, f, data_length * 5, |
| 401 | false); |
| 402 | fallback = scriptpubkey_witness_raw(b11, version, |
| 403 | f, tal_count(f)); |
| 404 | tal_free(f); |
| 405 | } else { |
| 406 | /* Restore version for unknown field! */ |
| 407 | (*data)--; |
| 408 | (*data_len)++; |
| 409 | data_length++; |
| 410 | return unknown_field(b11, hu5, data, data_len, 'f', |
| 411 | data_length); |
no test coverage detected