| 548 | } |
| 549 | |
| 550 | struct command_result *notification_sendpay_success(struct command *cmd, |
| 551 | const char *buf, |
| 552 | const jsmntok_t *params) |
| 553 | { |
| 554 | plugin_log(pay_plugin->plugin, LOG_DBG, |
| 555 | "sendpay_success notification: %.*s", |
| 556 | json_tok_full_len(params), json_tok_full(buf, params)); |
| 557 | |
| 558 | const jsmntok_t *sub = json_get_member(buf, params, "sendpay_success"); |
| 559 | |
| 560 | struct routekey *key = tal_routekey_from_json(tmpctx, buf, sub); |
| 561 | if (!key) |
| 562 | plugin_err(pay_plugin->plugin, |
| 563 | "Unable to get routekey from sendpay_success: %.*s", |
| 564 | json_tok_full_len(sub), json_tok_full(buf, sub)); |
| 565 | |
| 566 | struct payment *payment = |
| 567 | payment_map_get(pay_plugin->payment_map, key->payment_hash); |
| 568 | |
| 569 | if (!payment) { |
| 570 | /* This sendpay is not linked to any route in our database, we |
| 571 | * skip it. */ |
| 572 | return notification_handled(cmd); |
| 573 | } |
| 574 | |
| 575 | struct routetracker *routetracker = payment->routetracker; |
| 576 | assert(routetracker); |
| 577 | struct route *route = |
| 578 | route_map_get(pay_plugin->pending_routes, key); |
| 579 | if (!route) { |
| 580 | /* This route was not created by us, make a basic route |
| 581 | * information dummy without hop details to pass onward. */ |
| 582 | route = tal_route_from_json(tmpctx, buf, sub); |
| 583 | if(!route) |
| 584 | plugin_err(pay_plugin->plugin, |
| 585 | "Failed to get route information from sendpay_success: %.*s", |
| 586 | json_tok_full_len(sub), json_tok_full(buf, sub)); |
| 587 | } |
| 588 | |
| 589 | assert(route->result == NULL); |
| 590 | route->result = tal_sendpay_result_from_json(route, buf, sub, |
| 591 | route->shared_secrets); |
| 592 | if (route->result == NULL) |
| 593 | plugin_err(pay_plugin->plugin, |
| 594 | "Unable to parse sendpay_success: %.*s", |
| 595 | json_tok_full_len(sub), json_tok_full(buf, sub)); |
| 596 | |
| 597 | assert(route->result->status == SENDPAY_COMPLETE); |
| 598 | route_success_register(payment->routetracker, route); |
| 599 | return notification_handled(cmd); |
| 600 | } |
nothing calls this directly
no test coverage detected