wallet: fix accessing blockheight of unconfirmed transaction

This commit is contained in:
Michael Schmoock
2019-11-14 13:33:11 +01:00
committed by Rusty Russell
parent 0d55dca50f
commit ed238758a2

View File

@@ -3445,7 +3445,7 @@ struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t
" transaction_annotations a ON (a.txid = t.id) LEFT JOIN"
" channels c ON (a.channel = c.id) LEFT JOIN"
" channels c2 ON (t.channel_id = c2.id) "
"ORDER BY blockheight, txindex ASC"));
"ORDER BY t.blockheight, t.txindex ASC"));
db_query_prepared(stmt);
for (count = 0; db_step(stmt); count++) {
@@ -3463,8 +3463,16 @@ struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t
cur->tx = db_column_tx(txs, stmt, 1);
cur->rawtx = tal_dup_arr(txs, u8, db_column_blob(stmt, 1),
db_column_bytes(stmt, 1), 0);
cur->blockheight = db_column_int(stmt, 2);
cur->txindex = db_column_int(stmt, 3);
/* TX may be unconfirmed. */
if (!db_column_is_null(stmt, 2) || !db_column_is_null(stmt, 3)) {
/* assert incomplete information */
assert(!db_column_is_null(stmt, 2) && !db_column_is_null(stmt, 3));
cur->blockheight = db_column_int(stmt, 2);
cur->txindex = db_column_int(stmt, 3);
} else {
cur->blockheight = 0;
cur->txindex = 0;
}
if (!db_column_is_null(stmt, 4))
cur->annotation.type = db_column_u64(stmt, 4);
else