Browse Source

pay: Move error message creation for sendpay into its own function

We're about to move it a bit up in the call-graph, so encapsulate it in its
own function.
travis-debug
Christian Decker 5 years ago
parent
commit
51ee5cc28d
  1. 4
      lightningd/notification.c
  2. 2
      lightningd/notification.h
  3. 27
      lightningd/pay.c

4
lightningd/notification.c

@ -285,14 +285,14 @@ void notify_sendpay_failure(struct lightningd *ld,
int pay_errcode, int pay_errcode,
const u8 *onionreply, const u8 *onionreply,
const struct routing_failure *fail, const struct routing_failure *fail,
char *errmsg) const char *errmsg)
{ {
void (*serialize)(struct json_stream *, void (*serialize)(struct json_stream *,
const struct wallet_payment *, const struct wallet_payment *,
int, int,
const u8 *, const u8 *,
const struct routing_failure *, const struct routing_failure *,
char *) = sendpay_failure_notification_gen.serialize; const char *) = sendpay_failure_notification_gen.serialize;
struct jsonrpc_notification *n = struct jsonrpc_notification *n =
jsonrpc_notification_start(NULL, "sendpay_failure"); jsonrpc_notification_start(NULL, "sendpay_failure");

2
lightningd/notification.h

@ -63,6 +63,6 @@ void notify_sendpay_failure(struct lightningd *ld,
int pay_errcode, int pay_errcode,
const u8 *onionreply, const u8 *onionreply,
const struct routing_failure *fail, const struct routing_failure *fail,
char *errmsg); const char *errmsg);
#endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */ #endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */

27
lightningd/pay.c

@ -191,6 +191,21 @@ void json_sendpay_fail_fields(struct json_stream *js,
fail->msg); fail->msg);
} }
static const char *sendpay_errmsg_fmt(const tal_t *ctx, int pay_errcode,
const struct routing_failure *fail,
const char *details)
{
char *errmsg;
if (pay_errcode == PAY_UNPARSEABLE_ONION)
errmsg = "Malformed error reply";
else {
assert(fail);
errmsg = tal_fmt(ctx, "failed: %s (%s)",
onion_type_name(fail->failcode), details);
}
return errmsg;
}
/* onionreply used if pay_errcode == PAY_UNPARSEABLE_ONION */ /* onionreply used if pay_errcode == PAY_UNPARSEABLE_ONION */
static struct command_result * static struct command_result *
sendpay_fail(struct command *cmd, sendpay_fail(struct command *cmd,
@ -201,16 +216,8 @@ sendpay_fail(struct command *cmd,
const char *details) const char *details)
{ {
struct json_stream *data; struct json_stream *data;
char *errmsg; const char *errmsg =
sendpay_errmsg_fmt(tmpctx, pay_errcode, fail, details);
if (pay_errcode == PAY_UNPARSEABLE_ONION)
errmsg = "Malformed error reply";
else {
assert(fail);
errmsg = tal_fmt(tmpctx, "failed: %s (%s)",
onion_type_name(fail->failcode),
details);
}
notify_sendpay_failure(cmd->ld, notify_sendpay_failure(cmd->ld,
payment, payment,

Loading…
Cancel
Save