Browse Source

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 <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
be97673259
  1. 23
      wallet/wallet.c
  2. 6
      wallet/wallet.h

23
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;
}

6
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 */

Loading…
Cancel
Save