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:
Christian Decker
2018-07-23 15:27:58 +02:00
committed by Rusty Russell
parent bc7393bb64
commit 6bbe5b60f6

View File

@@ -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,12 +1697,7 @@ 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,"
"msatoshi, payment_hash, timestamp, payment_preimage, "
"path_secrets, route_nodes, route_channels, "
"msatoshi_sent, description "
"FROM payments "
"WHERE payment_hash = ?"); "WHERE payment_hash = ?");
sqlite3_bind_sha256(stmt, 1, payment_hash); sqlite3_bind_sha256(stmt, 1, payment_hash);
@@ -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, "
"msatoshi, payment_hash, timestamp, payment_preimage, "
"path_secrets, route_nodes, route_channels "
"FROM payments "
"WHERE payment_hash = ?;"); "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++) {