invoice: Fix waitanyinvoice

There were two bugs: we weren't returning the next from the given
label but the one matching the label, and we were appending new
invoices to the head instead of the tail, which meant we'd be
traversing in the wrong order.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2017-11-13 16:13:35 +01:00
committed by Rusty Russell
parent 71c090745b
commit adfe494b08

View File

@@ -191,7 +191,7 @@ static void json_invoice(struct command *cmd,
/* OK, connect it to main state, respond with hash */ /* OK, connect it to main state, respond with hash */
tal_steal(invs, invoice); tal_steal(invs, invoice);
list_add(&invs->invlist, &invoice->list); list_add_tail(&invs->invlist, &invoice->list);
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_hex(response, "rhash", json_add_hex(response, "rhash",
@@ -342,6 +342,8 @@ static void json_waitanyinvoice(struct command *cmd,
command_fail(cmd, "Label not found"); command_fail(cmd, "Label not found");
return; return;
} }
/* Skip this particular invoice */
i = list_next(&invs->invlist, i, list);
while (i && i->state == UNPAID) { while (i && i->state == UNPAID) {
i = list_next(&invs->invlist, i, list); i = list_next(&invs->invlist, i, list);
} }