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

Function json_add_fallback

common/bolt11_json.c:10–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

json_add_bolt11Function · 0.85

Calls 11

tal_bytelenFunction · 0.85
json_object_startFunction · 0.85
is_p2wpkhFunction · 0.85
is_p2wshFunction · 0.85
json_add_hex_talarrFunction · 0.85
json_object_endFunction · 0.85
json_add_stringFunction · 0.70
is_p2pkhFunction · 0.50
is_p2shFunction · 0.50
is_p2trFunction · 0.50

Tested by

no test coverage detected