| 480 | } |
| 481 | |
| 482 | struct command_result *notification_sendpay_failure(struct command *cmd, |
| 483 | const char *buf, |
| 484 | const jsmntok_t *params) |
| 485 | { |
| 486 | plugin_log(pay_plugin->plugin, LOG_DBG, |
| 487 | "sendpay_failure notification: %.*s", |
| 488 | json_tok_full_len(params), json_tok_full(buf, params)); |
| 489 | |
| 490 | // enum jsonrpc_errcode errcode; |
| 491 | const jsmntok_t *sub = json_get_member(buf, params, "sendpay_failure"); |
| 492 | |
| 493 | struct routekey *key = tal_routekey_from_json( |
| 494 | tmpctx, buf, json_get_member(buf, sub, "data")); |
| 495 | if (!key) |
| 496 | plugin_err(pay_plugin->plugin, |
| 497 | "Unable to get routekey from sendpay_failure: %.*s", |
| 498 | json_tok_full_len(sub), json_tok_full(buf, sub)); |
| 499 | |
| 500 | struct payment *payment = |
| 501 | payment_map_get(pay_plugin->payment_map, key->payment_hash); |
| 502 | |
| 503 | if (!payment) { |
| 504 | /* This sendpay is not linked to any route in our database, we |
| 505 | * skip it. */ |
| 506 | return notification_handled(cmd); |
| 507 | } |
| 508 | |
| 509 | struct routetracker *routetracker = payment->routetracker; |
| 510 | assert(routetracker); |
| 511 | struct route *route = |
| 512 | route_map_get(pay_plugin->pending_routes, key); |
| 513 | if (!route) { |
| 514 | route = tal_route_from_json(tmpctx, buf, |
| 515 | json_get_member(buf, sub, "data")); |
| 516 | if (!route) |
| 517 | plugin_err(pay_plugin->plugin, |
| 518 | "Failed to get route information from " |
| 519 | "sendpay_failure: %.*s", |
| 520 | json_tok_full_len(sub), |
| 521 | json_tok_full(buf, sub)); |
| 522 | } |
| 523 | |
| 524 | assert(route->result == NULL); |
| 525 | route->result = tal_sendpay_result_from_json(route, buf, sub, |
| 526 | route->shared_secrets); |
| 527 | if (route->result == NULL) |
| 528 | plugin_err(pay_plugin->plugin, |
| 529 | "Unable to parse sendpay_failure: %.*s", |
| 530 | json_tok_full_len(sub), json_tok_full(buf, sub)); |
| 531 | |
| 532 | if (route->result->status != SENDPAY_FAILED) { |
| 533 | /* FIXME shouldn't this be always SENDPAY_FAILED? */ |
| 534 | const jsmntok_t *datatok = json_get_member(buf, sub, "data"); |
| 535 | const jsmntok_t *statustok = |
| 536 | json_get_member(buf, datatok, "status"); |
| 537 | const char *status_str = json_strdup(tmpctx, buf, statustok); |
| 538 | |
| 539 | plugin_log(pay_plugin->plugin, LOG_UNUSUAL, |
nothing calls this directly
no test coverage detected