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

Function json_to_blinded_path

common/json_blinded_path.c:7–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <wire/onion_wiregen.h>
6
7struct blinded_path *
8json_to_blinded_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok)
9{
10 struct blinded_path *rpath;
11 const jsmntok_t *hops, *t;
12 size_t i;
13 const char *err;
14 struct pubkey first_node_id;
15 struct short_channel_id_dir first_scidd;
16
17 rpath = tal(ctx, struct blinded_path);
18
19 /* It will give us either scid or node_id */
20 memset(&first_scidd, 0, sizeof(first_scidd));
21 err = json_scan(tmpctx, buffer, tok,
22 "{first_path_key:%,"
23 "first_node_id?:%,"
24 "first_scid?:%,"
25 "first_scid_dir?:%}",
26 JSON_SCAN(json_to_pubkey, &rpath->first_path_key),
27 JSON_SCAN(json_to_pubkey, &first_node_id),
28 JSON_SCAN(json_to_short_channel_id, &first_scidd.scid),
29 JSON_SCAN(json_to_int, &first_scidd.dir),
30 NULL);
31 if (err)
32 return tal_free(rpath);
33
34 if (first_scidd.scid.u64 != 0)
35 sciddir_or_pubkey_from_scidd(&rpath->first_node_id, &first_scidd);
36 else
37 sciddir_or_pubkey_from_pubkey(&rpath->first_node_id, &first_node_id);
38
39 hops = json_get_member(buffer, tok, "hops");
40 if (!hops || hops->size < 1)
41 return tal_free(rpath);
42
43 rpath->path = tal_arr(rpath, struct blinded_path_hop *, hops->size);
44 json_for_each_arr(i, t, hops) {
45 rpath->path[i] = tal(rpath->path, struct blinded_path_hop);
46 err = json_scan(tmpctx, buffer, t, "{blinded_node_id:%,encrypted_recipient_data:%}",
47 JSON_SCAN(json_to_pubkey,
48 &rpath->path[i]->blinded_node_id),
49 JSON_SCAN_TAL(rpath->path[i],
50 json_tok_bin_from_hex,
51 &rpath->path[i]->encrypted_recipient_data));
52 if (err)
53 return tal_free(rpath);
54 }
55
56 return rpath;
57}
58

Callers 1

onion_message_recvFunction · 0.85

Calls 5

tal_freeFunction · 0.85
json_get_memberFunction · 0.85
json_scanFunction · 0.70

Tested by

no test coverage detected