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

Function json_to_blinded_path

common/json_blinded_path.c:7–65  ·  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, *node_id_tok, *scid_tok;
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_node_id, 0, sizeof(first_node_id));
21 memset(&first_scidd, 0, sizeof(first_scidd));
22 err = json_scan(tmpctx, buffer, tok,
23 "{first_path_key:%,"
24 "first_node_id?:%,"
25 "first_scid?:%,"
26 "first_scid_dir?:%}",
27 JSON_SCAN(json_to_pubkey, &rpath->first_path_key),
28 JSON_SCAN(json_to_pubkey, &first_node_id),
29 JSON_SCAN(json_to_short_channel_id, &first_scidd.scid),
30 JSON_SCAN(json_to_int, &first_scidd.dir),
31 NULL);
32 if (err)
33 return tal_free(rpath);
34
35 /* A zero scid is valid on the wire, so don't use it as a sentinel:
36 * require exactly one of the two forms. */
37 node_id_tok = json_get_member(buffer, tok, "first_node_id");
38 scid_tok = json_get_member(buffer, tok, "first_scid");
39 if (!node_id_tok == !scid_tok)
40 return tal_free(rpath);
41
42 if (scid_tok)
43 sciddir_or_pubkey_from_scidd(&rpath->first_node_id, &first_scidd);
44 else
45 sciddir_or_pubkey_from_pubkey(&rpath->first_node_id, &first_node_id);
46
47 hops = json_get_member(buffer, tok, "hops");
48 if (!hops || hops->size < 1)
49 return tal_free(rpath);
50
51 rpath->path = tal_arr(rpath, struct blinded_path_hop *, hops->size);
52 json_for_each_arr(i, t, hops) {
53 rpath->path[i] = tal(rpath->path, struct blinded_path_hop);
54 err = json_scan(tmpctx, buffer, t, "{blinded_node_id:%,encrypted_recipient_data:%}",
55 JSON_SCAN(json_to_pubkey,
56 &rpath->path[i]->blinded_node_id),
57 JSON_SCAN_TAL(rpath->path[i],
58 json_tok_bin_from_hex,
59 &rpath->path[i]->encrypted_recipient_data));
60 if (err)
61 return tal_free(rpath);
62 }
63
64 return rpath;

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