| 8 | #include <common/json_stream.h> |
| 9 | |
| 10 | static void json_add_fallback(struct json_stream *response, |
| 11 | const char *fieldname, |
| 12 | const u8 *fallback, |
| 13 | const struct chainparams *chain) |
| 14 | { |
| 15 | char *addr; |
| 16 | const size_t fallback_len = tal_bytelen(fallback); |
| 17 | |
| 18 | json_object_start(response, fieldname); |
| 19 | if (is_p2pkh(fallback, fallback_len, NULL)) { |
| 20 | json_add_string(response, "type", "P2PKH"); |
| 21 | } else if (is_p2sh(fallback, fallback_len, NULL)) { |
| 22 | json_add_string(response, "type", "P2SH"); |
| 23 | } else if (is_p2wpkh(fallback, fallback_len, NULL)) { |
| 24 | json_add_string(response, "type", "P2WPKH"); |
| 25 | } else if (is_p2wsh(fallback, fallback_len, NULL)) { |
| 26 | json_add_string(response, "type", "P2WSH"); |
| 27 | } else if (is_p2tr(fallback, fallback_len, NULL)) { |
| 28 | json_add_string(response, "type", "P2TR"); |
| 29 | } |
| 30 | |
| 31 | addr = encode_scriptpubkey_to_addr(tmpctx, chain, fallback, fallback_len); |
| 32 | if (addr) |
| 33 | json_add_string(response, "addr", addr); |
| 34 | json_add_hex_talarr(response, "hex", fallback); |
| 35 | json_object_end(response); |
| 36 | } |
| 37 | |
| 38 | void json_add_bolt11(struct json_stream *response, |
| 39 | const struct bolt11 *b11) |
no test coverage detected