| 382 | } |
| 383 | |
| 384 | struct command_result *route_sendpay_request(struct command *cmd, |
| 385 | struct route *route TAKES, |
| 386 | struct payment *payment) |
| 387 | { |
| 388 | // build onion |
| 389 | const u8 *onion; |
| 390 | const struct payment_info *pinfo; |
| 391 | const struct blinded_path *blinded_path = NULL; |
| 392 | struct out_req *req; |
| 393 | |
| 394 | pinfo = &payment->payment_info; |
| 395 | if (tal_count(pinfo->blinded_paths) > 0) { |
| 396 | assert(route->path_num < tal_count(pinfo->blinded_paths)); |
| 397 | blinded_path = pinfo->blinded_paths[route->path_num]; |
| 398 | } |
| 399 | |
| 400 | if (tal_count(route->hops) > 0) { |
| 401 | onion = create_onion( |
| 402 | route, payment->blockheight, route->hops, |
| 403 | &pinfo->payment_hash, pinfo->final_cltv, blinded_path, |
| 404 | pinfo->payment_secret, pinfo->amount, route->amount_deliver, |
| 405 | /* metadata = */ NULL, route->hops[0].node_id, 1, |
| 406 | &route->shared_secrets); |
| 407 | } else { |
| 408 | /* This is either a self-payment or a payment through a blinded |
| 409 | * path that starts at our node. */ |
| 410 | onion = create_onion(route, payment->blockheight, route->hops, |
| 411 | &pinfo->payment_hash, pinfo->final_cltv, |
| 412 | blinded_path, pinfo->payment_secret, |
| 413 | pinfo->amount, route->amount_deliver, |
| 414 | /* metadata = */ NULL, pay_plugin->my_id, |
| 415 | 0, &route->shared_secrets); |
| 416 | } |
| 417 | |
| 418 | // send onion |
| 419 | // FIXME: use injectpaymentonion in both cases |
| 420 | if (tal_count(route->hops) > 0) { |
| 421 | req = jsonrpc_request_start(cmd, "sendonion", sendonion_done, |
| 422 | sendonion_fail, payment); |
| 423 | json_add_hex_talarr(req->js, "onion", onion); |
| 424 | json_add_sha256(req->js, "payment_hash", &pinfo->payment_hash); |
| 425 | json_add_u64(req->js, "partid", route->key.partid); |
| 426 | json_add_u64(req->js, "groupid", route->key.groupid); |
| 427 | json_add_amount_msat(req->js, "amount_msat", |
| 428 | route->amount_deliver); |
| 429 | if (pinfo->label) |
| 430 | json_add_string(req->js, "label", pinfo->label); |
| 431 | if (pinfo->invstr) |
| 432 | json_add_string(req->js, "bolt11", pinfo->invstr); |
| 433 | if (pinfo->description) |
| 434 | json_add_string(req->js, "description", |
| 435 | pinfo->description); |
| 436 | json_add_node_id(req->js, "destination", &pinfo->destination); |
| 437 | json_add_amount_msat(req->js, "total_amount_msat", |
| 438 | pinfo->amount); |
| 439 | |
| 440 | json_array_start(req->js, "shared_secrets"); |
| 441 | for (size_t i = 0; i < tal_count(route->shared_secrets); i++) { |
no test coverage detected