|
6 | 6 | #include <common/type_to_string.h>
|
7 | 7 | #include <common/wireaddr.h>
|
8 | 8 | #include <errno.h>
|
| 9 | +#include <wire/onion_wire.h> |
9 | 10 | #include <wire/peer_wire.h>
|
10 | 11 |
|
11 | 12 | bool json_to_bitcoin_amount(const char *buffer, const jsmntok_t *tok,
|
@@ -140,6 +141,42 @@ struct wally_psbt *json_to_psbt(const tal_t *ctx, const char *buffer,
|
140 | 141 | return psbt_from_b64(ctx, buffer + tok->start, tok->end - tok->start);
|
141 | 142 | }
|
142 | 143 |
|
| 144 | +struct tlv_onionmsg_payload_reply_path * |
| 145 | +json_to_reply_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok) |
| 146 | +{ |
| 147 | + struct tlv_onionmsg_payload_reply_path *rpath; |
| 148 | + const jsmntok_t *hops, *t; |
| 149 | + size_t i; |
| 150 | + const char *err; |
| 151 | + |
| 152 | + rpath = tal(ctx, struct tlv_onionmsg_payload_reply_path); |
| 153 | + err = json_scan(tmpctx, buffer, tok, "{blinding:%,first_node_id:%}", |
| 154 | + JSON_SCAN(json_to_pubkey, &rpath->blinding), |
| 155 | + JSON_SCAN(json_to_pubkey, &rpath->first_node_id), |
| 156 | + NULL); |
| 157 | + if (err) |
| 158 | + return tal_free(rpath); |
| 159 | + |
| 160 | + hops = json_get_member(buffer, tok, "hops"); |
| 161 | + if (!hops || hops->size < 1) |
| 162 | + return tal_free(rpath); |
| 163 | + |
| 164 | + rpath->path = tal_arr(rpath, struct onionmsg_path *, hops->size); |
| 165 | + json_for_each_arr(i, t, hops) { |
| 166 | + rpath->path[i] = tal(rpath->path, struct onionmsg_path); |
| 167 | + err = json_scan(tmpctx, buffer, t, "{id:%,enctlv:%}", |
| 168 | + JSON_SCAN(json_to_pubkey, |
| 169 | + &rpath->path[i]->node_id), |
| 170 | + JSON_SCAN_TAL(rpath->path[i], |
| 171 | + json_tok_bin_from_hex, |
| 172 | + &rpath->path[i]->enctlv)); |
| 173 | + if (err) |
| 174 | + return tal_free(rpath); |
| 175 | + } |
| 176 | + |
| 177 | + return rpath; |
| 178 | +} |
| 179 | + |
143 | 180 | void json_add_node_id(struct json_stream *response,
|
144 | 181 | const char *fieldname,
|
145 | 182 | const struct node_id *id)
|
|
0 commit comments