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