MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_add_fallback

Function json_add_fallback

common/bolt11_json.c:11–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include <common/json_stream.h>
10
11static 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
46void json_add_bolt11(struct json_stream *response,
47 const struct bolt11 *b11)

Callers 1

json_add_bolt11Function · 0.85

Calls 11

bitcoin_to_base58Function · 0.85
p2sh_to_base58Function · 0.85
segwit_addr_encodeFunction · 0.85
is_p2wshFunction · 0.85
json_object_startFunction · 0.70
json_add_stringFunction · 0.70
json_add_hex_talarrFunction · 0.70
json_object_endFunction · 0.70
is_p2pkhFunction · 0.50
is_p2shFunction · 0.50
is_p2wpkhFunction · 0.50

Tested by

no test coverage detected