Skip to content

Commit

Permalink
pay: Pass description to send_payment
Browse files Browse the repository at this point in the history
Extract the description from the bolt11 string and store it in the database.
  • Loading branch information
cdecker authored and rustyrussell committed Jul 30, 2018
1 parent 60e0eec commit ab223c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ send_payment(const tal_t *ctx,
const struct sha256 *rhash,
const struct route_hop *route,
u64 msatoshi,
const char *description TAKES,
void (*cb)(const struct sendpay_result *, void*),
void *cbarg)
{
Expand Down Expand Up @@ -792,7 +793,10 @@ send_payment(const tal_t *ctx,
payment->path_secrets = tal_steal(payment, path_secrets);
payment->route_nodes = tal_steal(payment, ids);
payment->route_channels = tal_steal(payment, channels);
payment->description = NULL;
if (description != NULL)
payment->description = tal_strdup(payment, description);
else
payment->description = NULL;

/* We write this into db when HTLC is actually sent. */
wallet_payment_setup(ld->wallet, payment);
Expand Down Expand Up @@ -1021,8 +1025,10 @@ static void json_sendpay(struct command *cmd,
}
}

/* FIXME(cdecker): Add a description parameter to sendpay */
if (send_payment(cmd, cmd->ld, &rhash, route,
msatoshi ? *msatoshi : route[n_hops-1].amount,
NULL,
&json_sendpay_on_resolve, cmd))
command_still_pending(cmd);
}
Expand Down
2 changes: 2 additions & 0 deletions lightningd/pay.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ bool send_payment(const tal_t *ctx,
const struct sha256 *rhash,
const struct route_hop *route,
u64 msatoshi,
const char *description TAKES,
void (*cb)(const struct sendpay_result *, void*),
void *cbarg);

/* Wait for a previous send_payment to complete in definite
* success or failure. If the given context is freed before
* the callback is called, then the callback will no longer
Expand Down
5 changes: 5 additions & 0 deletions lightningd/payalgo.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ struct pay {
* is mainly useful for tiny transfers for which the leveraged fee would
* be dominated by the forwarding fee. */
u64 exemptfee;

/* The description from the bolt11 string */
const char *description;
};

static struct routing_failure *
Expand Down Expand Up @@ -502,6 +505,7 @@ static void json_pay_getroute_reply(struct subd *gossip UNUSED,
send_payment(pay->try_parent,
pay->cmd->ld, &pay->payment_hash, route,
pay->msatoshi,
pay->description,
&json_pay_sendpay_resume, pay);
}

Expand Down Expand Up @@ -691,6 +695,7 @@ static void json_pay(struct command *cmd,
/* Start with no failures */
list_head_init(&pay->pay_failures);
pay->in_sendpay = false;
pay->description = b11->description;

/* Initiate payment */
if (json_pay_try(pay))
Expand Down

0 comments on commit ab223c2

Please sign in to comment.