| 9 | #include <common/json_stream.h> |
| 10 | |
| 11 | static void json_add_fallback(struct json_stream *response, |
| 12 | const char *fieldname, |
| 13 | const u8 *fallback, |
| 14 | const struct chainparams *chain) |
| 15 | { |
| 16 | struct bitcoin_address pkh; |
| 17 | struct ripemd160 sh; |
| 18 | struct sha256 wsh; |
| 19 | |
| 20 | json_object_start(response, fieldname); |
| 21 | if (is_p2pkh(fallback, &pkh)) { |
| 22 | json_add_string(response, "type", "P2PKH"); |
| 23 | json_add_string(response, "addr", |
| 24 | bitcoin_to_base58(tmpctx, chain, &pkh)); |
| 25 | } else if (is_p2sh(fallback, &sh)) { |
| 26 | json_add_string(response, "type", "P2SH"); |
| 27 | json_add_string(response, "addr", |
| 28 | p2sh_to_base58(tmpctx, chain, &sh)); |
| 29 | } else if (is_p2wpkh(fallback, &pkh)) { |
| 30 | char out[73 + strlen(chain->onchain_hrp)]; |
| 31 | json_add_string(response, "type", "P2WPKH"); |
| 32 | if (segwit_addr_encode(out, chain->onchain_hrp, 0, |
| 33 | (const u8 *)&pkh, sizeof(pkh))) |
| 34 | json_add_string(response, "addr", out); |
| 35 | } else if (is_p2wsh(fallback, &wsh)) { |
| 36 | char out[73 + strlen(chain->onchain_hrp)]; |
| 37 | json_add_string(response, "type", "P2WSH"); |
| 38 | if (segwit_addr_encode(out, chain->onchain_hrp, 0, |
| 39 | (const u8 *)&wsh, sizeof(wsh))) |
| 40 | json_add_string(response, "addr", out); |
| 41 | } |
| 42 | json_add_hex_talarr(response, "hex", fallback); |
| 43 | json_object_end(response); |
| 44 | } |
| 45 | |
| 46 | void json_add_bolt11(struct json_stream *response, |
| 47 | const struct bolt11 *b11) |
no test coverage detected