mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
wallet: Extract the payment fields into a define
`wallet_stmt2payment` always expects the same fields in the same order, so we should make sure that we always fetch them in that order and all of them.
This commit is contained in:
committed by
Rusty Russell
parent
bc7393bb64
commit
6bbe5b60f6
@@ -1679,6 +1679,12 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
|
|||||||
return payment;
|
return payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* List of the fields that stmt2payment expects to correctly convert */
|
||||||
|
#define PAYMENT_FIELDS \
|
||||||
|
"id, status, destination, msatoshi, payment_hash, timestamp, " \
|
||||||
|
"payment_preimage, path_secrets, route_nodes, route_channels, " \
|
||||||
|
"msatoshi_sent, description "
|
||||||
|
|
||||||
struct wallet_payment *
|
struct wallet_payment *
|
||||||
wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
|
wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
|
||||||
const struct sha256 *payment_hash)
|
const struct sha256 *payment_hash)
|
||||||
@@ -1691,13 +1697,8 @@ wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
|
|||||||
if (payment)
|
if (payment)
|
||||||
return payment;
|
return payment;
|
||||||
|
|
||||||
stmt = db_prepare(wallet->db,
|
stmt = db_prepare(wallet->db, "SELECT " PAYMENT_FIELDS " FROM payments "
|
||||||
"SELECT id, status, destination,"
|
"WHERE payment_hash = ?");
|
||||||
"msatoshi, payment_hash, timestamp, payment_preimage, "
|
|
||||||
"path_secrets, route_nodes, route_channels, "
|
|
||||||
"msatoshi_sent, description "
|
|
||||||
"FROM payments "
|
|
||||||
"WHERE payment_hash = ?");
|
|
||||||
|
|
||||||
sqlite3_bind_sha256(stmt, 1, payment_hash);
|
sqlite3_bind_sha256(stmt, 1, payment_hash);
|
||||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||||
@@ -1889,22 +1890,13 @@ wallet_payment_list(const tal_t *ctx,
|
|||||||
|
|
||||||
payments = tal_arr(ctx, const struct wallet_payment *, 0);
|
payments = tal_arr(ctx, const struct wallet_payment *, 0);
|
||||||
if (payment_hash) {
|
if (payment_hash) {
|
||||||
stmt = db_prepare(
|
stmt = db_prepare(wallet->db,
|
||||||
wallet->db,
|
"SELECT " PAYMENT_FIELDS " FROM payments "
|
||||||
"SELECT id, status, destination, "
|
"WHERE payment_hash = ?;");
|
||||||
"msatoshi, payment_hash, timestamp, payment_preimage, "
|
|
||||||
"path_secrets, route_nodes, route_channels "
|
|
||||||
"FROM payments "
|
|
||||||
"WHERE payment_hash = ?;");
|
|
||||||
sqlite3_bind_sha256(stmt, 1, payment_hash);
|
sqlite3_bind_sha256(stmt, 1, payment_hash);
|
||||||
} else {
|
} else {
|
||||||
stmt = db_prepare(
|
stmt = db_prepare(wallet->db,
|
||||||
wallet->db,
|
"SELECT " PAYMENT_FIELDS " FROM payments;");
|
||||||
"SELECT id, status, destination, "
|
|
||||||
"msatoshi, payment_hash, timestamp, payment_preimage, "
|
|
||||||
"path_secrets, route_nodes, route_channels, "
|
|
||||||
"msatoshi_sent "
|
|
||||||
"FROM payments;");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; sqlite3_step(stmt) == SQLITE_ROW; i++) {
|
for (i = 0; sqlite3_step(stmt) == SQLITE_ROW; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user