From ed238758a2c0d733240e8f2eb6b20629943c1f89 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Thu, 14 Nov 2019 13:33:11 +0100 Subject: [PATCH] wallet: fix accessing blockheight of unconfirmed transaction --- wallet/wallet.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/wallet/wallet.c b/wallet/wallet.c index 054985fb5..0484e6602 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -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