wallet: Add function to retrieve a watched transaction's blockheight

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-04-09 15:18:09 +02:00
parent 50600ae241
commit 85fbab2fab
2 changed files with 23 additions and 0 deletions

View File

@ -2201,3 +2201,20 @@ void wallet_transaction_add(struct wallet *w, const struct bitcoin_tx *tx,
db_exec_prepared(w->db, stmt);
}
}
u32 wallet_transaction_height(struct wallet *w, const struct bitcoin_txid *txid)
{
u32 blockheight;
sqlite3_stmt *stmt = db_prepare(
w->db, "SELECT blockheight, txindex, rawtx FROM transactions WHERE id=?");
sqlite3_bind_sha256(stmt, 1, &txid->shad.sha);
if (sqlite3_step(stmt) != SQLITE_ROW) {
sqlite3_finalize(stmt);
return 0;
}
blockheight = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
return blockheight;
}

View File

@ -814,4 +814,10 @@ void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx,
void wallet_transaction_add(struct wallet *w, const struct bitcoin_tx *tx,
const u32 blockheight, const u32 txindex);
/**
* Get the confirmation height of a transaction we are watching by its
* txid. Returns 0 if the transaction was not part of any block.
*/
u32 wallet_transaction_height(struct wallet *w, const struct bitcoin_txid *txid);
#endif /* LIGHTNING_WALLET_WALLET_H */