Browse Source

pay: Rename `pay_command` to `sendpay_command`

In preparation for separating `pay` algorithm from
`sendpay`.
ppa-0.6.1
ZmnSCPxj 7 years ago
committed by Christian Decker
parent
commit
700dda7e60
  1. 2
      lightningd/lightningd.c
  2. 4
      lightningd/lightningd.h
  3. 70
      lightningd/pay.c

2
lightningd/lightningd.c

@ -64,7 +64,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx,
ld->alias = NULL; ld->alias = NULL;
ld->rgb = NULL; ld->rgb = NULL;
list_head_init(&ld->connects); list_head_init(&ld->connects);
list_head_init(&ld->pay_commands); list_head_init(&ld->sendpay_commands);
ld->wireaddrs = tal_arr(ld, struct wireaddr, 0); ld->wireaddrs = tal_arr(ld, struct wireaddr, 0);
ld->portnum = DEFAULT_PORT; ld->portnum = DEFAULT_PORT;
timers_init(&ld->timers, time_mono()); timers_init(&ld->timers, time_mono());

4
lightningd/lightningd.h

@ -132,8 +132,8 @@ struct lightningd {
struct wallet *wallet; struct wallet *wallet;
/* Outstanding sendpay/pay commands. */ /* Outstanding sendpay commands. */
struct list_head pay_commands; struct list_head sendpay_commands;
/* Maintained by invoices.c */ /* Maintained by invoices.c */
struct invoices *invoices; struct invoices *invoices;

70
lightningd/pay.c

@ -19,35 +19,37 @@
#include <lightningd/subd.h> #include <lightningd/subd.h>
#include <sodium/randombytes.h> #include <sodium/randombytes.h>
/* pay/sendpay command */ /* sendpay command */
struct pay_command { struct sendpay_command {
struct list_node list; struct list_node list;
struct sha256 payment_hash; struct sha256 payment_hash;
struct command *cmd; struct command *cmd;
}; };
static void destroy_pay_command(struct pay_command *pc) static void destroy_sendpay_command(struct sendpay_command *pc)
{ {
list_del(&pc->list); list_del(&pc->list);
} }
/* Owned by cmd */ /* Owned by cmd */
static struct pay_command *new_pay_command(struct command *cmd, static struct sendpay_command *
const struct sha256 *payment_hash, new_sendpay_command(struct command *cmd,
struct lightningd *ld) const struct sha256 *payment_hash,
struct lightningd *ld)
{ {
struct pay_command *pc = tal(cmd, struct pay_command); struct sendpay_command *pc = tal(cmd, struct sendpay_command);
pc->payment_hash = *payment_hash; pc->payment_hash = *payment_hash;
pc->cmd = cmd; pc->cmd = cmd;
list_add(&ld->pay_commands, &pc->list); list_add(&ld->sendpay_commands, &pc->list);
tal_add_destructor(pc, destroy_pay_command); tal_add_destructor(pc, destroy_sendpay_command);
return pc; return pc;
} }
static void json_pay_command_success(struct command *cmd, static void
const struct preimage *payment_preimage) json_sendpay_command_success(struct command *cmd,
const struct preimage *payment_preimage)
{ {
struct json_result *response; struct json_result *response;
@ -63,14 +65,14 @@ static void json_pay_success(struct lightningd *ld,
const struct sha256 *payment_hash, const struct sha256 *payment_hash,
const struct preimage *payment_preimage) const struct preimage *payment_preimage)
{ {
struct pay_command *pc, *next; struct sendpay_command *pc, *next;
list_for_each_safe(&ld->pay_commands, pc, next, list) { list_for_each_safe(&ld->sendpay_commands, pc, next, list) {
if (!structeq(payment_hash, &pc->payment_hash)) if (!structeq(payment_hash, &pc->payment_hash))
continue; continue;
/* Deletes itself. */ /* Deletes itself. */
json_pay_command_success(pc->cmd, payment_preimage); json_sendpay_command_success(pc->cmd, payment_preimage);
} }
} }
@ -83,11 +85,11 @@ struct routing_failure {
}; };
static void static void
json_pay_command_routing_failed(struct command *cmd, json_sendpay_command_routing_failed(struct command *cmd,
bool retry_plausible, bool retry_plausible,
const struct routing_failure *fail, const struct routing_failure *fail,
const u8 *onionreply, const u8 *onionreply,
const char *details) const char *details)
{ {
int code = int code =
(!fail) ? PAY_UNPARSEABLE_ONION : (!fail) ? PAY_UNPARSEABLE_ONION :
@ -131,18 +133,18 @@ static void json_pay_failed(struct lightningd *ld,
const u8 *onionreply, const u8 *onionreply,
const char *details) const char *details)
{ {
struct pay_command *pc, *next; struct sendpay_command *pc, *next;
list_for_each_safe(&ld->pay_commands, pc, next, list) { list_for_each_safe(&ld->sendpay_commands, pc, next, list) {
if (!structeq(payment_hash, &pc->payment_hash)) if (!structeq(payment_hash, &pc->payment_hash))
continue; continue;
/* Deletes cmd. */ /* Deletes cmd. */
json_pay_command_routing_failed(pc->cmd, json_sendpay_command_routing_failed(pc->cmd,
retry_plausible, retry_plausible,
fail, fail,
onionreply, onionreply,
details); details);
} }
} }
@ -526,8 +528,8 @@ static bool send_payment(struct command *cmd,
&payment->destination)); &payment->destination));
return false; return false;
} }
json_pay_command_success(cmd, json_sendpay_command_success(cmd,
payment->payment_preimage); payment->payment_preimage);
return false; return false;
} }
wallet_payment_delete(cmd->ld->wallet, rhash); wallet_payment_delete(cmd->ld->wallet, rhash);
@ -543,9 +545,9 @@ static bool send_payment(struct command *cmd,
report_routing_failure(cmd->ld->log, cmd->ld->gossip, fail); report_routing_failure(cmd->ld->log, cmd->ld->gossip, fail);
/* Report routing failure to user */ /* Report routing failure to user */
json_pay_command_routing_failed(cmd, true, fail, NULL, json_sendpay_command_routing_failed(cmd, true, fail, NULL,
"No connection to first " "No connection to first "
"peer found"); "peer found");
return false; return false;
} }
@ -570,8 +572,8 @@ static bool send_payment(struct command *cmd,
report_routing_failure(cmd->ld->log, cmd->ld->gossip, fail); report_routing_failure(cmd->ld->log, cmd->ld->gossip, fail);
/* Report routing failure to user */ /* Report routing failure to user */
json_pay_command_routing_failed(cmd, true, fail, NULL, json_sendpay_command_routing_failed(cmd, true, fail, NULL,
"First peer not ready"); "First peer not ready");
return false; return false;
} }
@ -596,7 +598,7 @@ static bool send_payment(struct command *cmd,
/* We write this into db when HTLC is actually sent. */ /* We write this into db when HTLC is actually sent. */
wallet_payment_setup(cmd->ld->wallet, payment); wallet_payment_setup(cmd->ld->wallet, payment);
new_pay_command(cmd, rhash, cmd->ld); new_sendpay_command(cmd, rhash, cmd->ld);
tal_free(tmpctx); tal_free(tmpctx);
return true; return true;
} }

Loading…
Cancel
Save