mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
wallet: Add invoice removal support
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
f5a412d90d
commit
9a106bf799
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user