| 44 | } |
| 45 | |
| 46 | struct command_result * |
| 47 | send_onion_reply(struct command *cmd, |
| 48 | struct tlv_onionmsg_payload_reply_path *reply_path, |
| 49 | struct tlv_onionmsg_payload *payload) |
| 50 | { |
| 51 | struct out_req *req; |
| 52 | size_t nhops; |
| 53 | |
| 54 | req = jsonrpc_request_start(cmd->plugin, cmd, "sendonionmessage", |
| 55 | finished, sendonionmessage_error, NULL); |
| 56 | |
| 57 | json_add_pubkey(req->js, "first_id", &reply_path->first_node_id); |
| 58 | json_add_pubkey(req->js, "blinding", &reply_path->blinding); |
| 59 | json_array_start(req->js, "hops"); |
| 60 | |
| 61 | nhops = tal_count(reply_path->path); |
| 62 | for (size_t i = 0; i < nhops; i++) { |
| 63 | struct tlv_onionmsg_payload *omp; |
| 64 | u8 *tlv; |
| 65 | |
| 66 | json_object_start(req->js, NULL); |
| 67 | json_add_pubkey(req->js, "id", &reply_path->path[i]->node_id); |
| 68 | |
| 69 | /* Put payload in last hop. */ |
| 70 | if (i == nhops - 1) |
| 71 | omp = payload; |
| 72 | else |
| 73 | omp = tlv_onionmsg_payload_new(tmpctx); |
| 74 | |
| 75 | omp->encrypted_data_tlv = reply_path->path[i]->encrypted_recipient_data; |
| 76 | |
| 77 | tlv = tal_arr(tmpctx, u8, 0); |
| 78 | towire_tlv_onionmsg_payload(&tlv, omp); |
| 79 | json_add_hex_talarr(req->js, "tlv", tlv); |
| 80 | json_object_end(req->js); |
| 81 | } |
| 82 | json_array_end(req->js); |
| 83 | return send_outreq(cmd->plugin, req); |
| 84 | } |
| 85 | |
| 86 | static struct command_result *onion_message_modern_call(struct command *cmd, |
| 87 | const char *buf, |
no test coverage detected