Browse Source

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

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
parent
commit
85fbab2fab
  1. 17
      wallet/wallet.c
  2. 6
      wallet/wallet.h

17
wallet/wallet.c

@ -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;
}

6
wallet/wallet.h

@ -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 */

Loading…
Cancel
Save