From be976732591f846d7917086d0d20191c1b0b5dcb Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 16 Nov 2017 19:11:59 +0100 Subject: [PATCH] wallet: Add function to retrieve a list of payments Used by the JSON-RPC for the listtransfers call. Currently does not support any form of paging. Signed-off-by: Christian Decker --- wallet/wallet.c | 23 +++++++++++++++++++++++ wallet/wallet.h | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/wallet/wallet.c b/wallet/wallet.c index f9b6fc958..ae398aba3 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1252,3 +1252,26 @@ void wallet_payment_set_status(struct wallet *wallet, sqlite3_bind_sha256(stmt, 2, payment_hash); db_exec_prepared(wallet->db, stmt); } + +const struct wallet_payment **wallet_payment_list(const tal_t *ctx, + struct wallet *wallet) +{ + const struct wallet_payment **payments; + sqlite3_stmt *stmt; + + payments = tal_arr(ctx, const struct wallet_payment *, 0); + stmt = db_prepare( + wallet->db, + "SELECT id, status, direction, destination, " + "msatoshi , payment_hash, timestamp " + "FROM payments;"); + + for (int i = 0; sqlite3_step(stmt) == SQLITE_ROW; i++) { + tal_resize(&payments, i+1); + payments[i] = wallet_stmt2payment(payments, stmt); + } + + sqlite3_finalize(stmt); + + return payments; +} diff --git a/wallet/wallet.h b/wallet/wallet.h index 72c6b5941..ce936ca7a 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -407,4 +407,10 @@ void wallet_payment_set_status(struct wallet *wallet, const struct sha256 *payment_hash, const enum wallet_payment_status newstatus); +/** + * wallet_payment_list - Retrieve a list of payments + */ +const struct wallet_payment **wallet_payment_list(const tal_t *ctx, + struct wallet *wallet); + #endif /* WALLET_WALLET_H */