Browse Source

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.
ppa-0.6.1
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
6bbe5b60f6
  1. 34
      wallet/wallet.c

34
wallet/wallet.c

@ -1679,6 +1679,12 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
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 *
wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
const struct sha256 *payment_hash)
@ -1691,13 +1697,8 @@ wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
if (payment)
return payment;
stmt = db_prepare(wallet->db,
"SELECT id, status, destination,"
"msatoshi, payment_hash, timestamp, payment_preimage, "
"path_secrets, route_nodes, route_channels, "
"msatoshi_sent, description "
"FROM payments "
"WHERE payment_hash = ?");
stmt = db_prepare(wallet->db, "SELECT " PAYMENT_FIELDS " FROM payments "
"WHERE payment_hash = ?");
sqlite3_bind_sha256(stmt, 1, payment_hash);
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);
if (payment_hash) {
stmt = db_prepare(
wallet->db,
"SELECT id, status, destination, "
"msatoshi, payment_hash, timestamp, payment_preimage, "
"path_secrets, route_nodes, route_channels "
"FROM payments "
"WHERE payment_hash = ?;");
stmt = db_prepare(wallet->db,
"SELECT " PAYMENT_FIELDS " FROM payments "
"WHERE payment_hash = ?;");
sqlite3_bind_sha256(stmt, 1, payment_hash);
} else {
stmt = db_prepare(
wallet->db,
"SELECT id, status, destination, "
"msatoshi, payment_hash, timestamp, payment_preimage, "
"path_secrets, route_nodes, route_channels, "
"msatoshi_sent "
"FROM payments;");
stmt = db_prepare(wallet->db,
"SELECT " PAYMENT_FIELDS " FROM payments;");
}
for (i = 0; sqlite3_step(stmt) == SQLITE_ROW; i++) {

Loading…
Cancel
Save