mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 09:34:24 +01:00
wallet_invoice_nextpaid: return a struct invoice.
This reuses the same code internally, and also now means that we deal correctly with "any" msatoshi invoices: the old code would a return 'msatoshi' of 0 in that case. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -411,12 +411,8 @@ static void json_waitanyinvoice(struct command *cmd,
|
||||
u64 pay_index;
|
||||
struct invoice_waiter *w;
|
||||
struct invoices *invs = cmd->ld->invoices;
|
||||
bool res;
|
||||
struct wallet *wallet = cmd->ld->wallet;
|
||||
char* outlabel;
|
||||
struct sha256 outrhash;
|
||||
u64 outmsatoshi;
|
||||
u64 outpay_index;
|
||||
struct invoice *inv;
|
||||
struct json_result *response;
|
||||
|
||||
if (!json_get_params(buffer, params,
|
||||
@@ -438,25 +434,24 @@ static void json_waitanyinvoice(struct command *cmd,
|
||||
}
|
||||
|
||||
/* Find next paid invoice. */
|
||||
res = wallet_invoice_nextpaid(cmd, wallet, pay_index,
|
||||
&outlabel, &outrhash,
|
||||
&outmsatoshi, &outpay_index);
|
||||
inv = wallet_invoice_nextpaid(cmd, wallet, pay_index);
|
||||
|
||||
/* If we found one, return it. */
|
||||
if (res) {
|
||||
if (inv) {
|
||||
response = new_json_result(cmd);
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_add_string(response, "label", outlabel);
|
||||
json_add_hex(response, "rhash", &outrhash, sizeof(outrhash));
|
||||
json_add_u64(response, "msatoshi", outmsatoshi);
|
||||
json_add_string(response, "label", inv->label);
|
||||
json_add_hex(response, "rhash", &inv->rhash, sizeof(inv->rhash));
|
||||
if (inv->msatoshi)
|
||||
json_add_u64(response, "msatoshi", *inv->msatoshi);
|
||||
json_add_bool(response, "complete", true);
|
||||
json_add_u64(response, "pay_index", outpay_index);
|
||||
json_add_u64(response, "pay_index", inv->pay_index);
|
||||
json_object_end(response);
|
||||
|
||||
command_success(cmd, response);
|
||||
|
||||
/* outlabel is freed when cmd is freed, and command_success
|
||||
/* inv is freed when cmd is freed, and command_success
|
||||
* also frees cmd. */
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user