Browse Source

wallet: Add invoice removal support

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
9a106bf799
  1. 10
      lightningd/invoice.c
  2. 7
      wallet/wallet.c
  3. 13
      wallet/wallet.h

10
lightningd/invoice.c

@ -5,6 +5,8 @@
#include <ccan/structeq/structeq.h>
#include <ccan/tal/str/str.h>
#include <common/utils.h>
#include <inttypes.h>
#include <lightningd/log.h>
#include <sodium/randombytes.h>
struct invoice_waiter {
@ -87,9 +89,6 @@ static void tell_waiter(struct command *cmd, const struct invoice *paid)
command_success(cmd, response);
}
/* UNIFICATION FIXME */
bool db_remove_invoice(struct lightningd *ld, const char *label);
void resolve_invoice(struct lightningd *ld, struct invoice *invoice)
{
struct invoice_waiter *w;
@ -265,7 +264,10 @@ static void json_delinvoice(struct command *cmd,
command_fail(cmd, "Unknown invoice");
return;
}
if (!db_remove_invoice(cmd->ld, i->label)) {
if (!wallet_invoice_remove(cmd->ld->wallet, i)) {
log_broken(cmd->ld->log, "Error attempting to remove invoice %"PRIu64": %s",
i->id, cmd->ld->wallet->db->err);
command_fail(cmd, "Database error");
return;
}

7
wallet/wallet.c

@ -1192,3 +1192,10 @@ bool wallet_invoices_load(struct wallet *wallet, struct invoices *invs)
log_debug(wallet->log, "Loaded %d invoices from DB", count);
return true;
}
bool wallet_invoice_remove(struct wallet *wallet, struct invoice *inv)
{
sqlite3_stmt *stmt = db_prepare(wallet->db, "DELETE FROM invoices WHERE id=?");
sqlite3_bind_int64(stmt, 1, inv->id);
return db_exec_prepared(wallet->db, stmt) && sqlite3_changes(wallet->db->sql) == 1;
}

13
wallet/wallet.h

@ -323,4 +323,17 @@ bool wallet_invoice_save(struct wallet *wallet, struct invoice *inv);
*/
bool wallet_invoices_load(struct wallet *wallet, struct invoices *invs);
/**
* wallet_invoice_remove -- Remove the specified invoice from the wallet
*
* Remove the invoice from the underlying database. The invoice is
* identified by `inv->id` so if the caller does not have the full
* invoice, it may just instantiate a new one and set the `id` to
* match the desired invoice.
*
* @wallet: Wallet to remove from
* @inv: Invoice to remove.
*/
bool wallet_invoice_remove(struct wallet *wallet, struct invoice *inv);
#endif /* WALLET_WALLET_H */

Loading…
Cancel
Save