Skip to content

Commit

Permalink
wallet: Add function to retrieve a watched transaction's blockheight
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Decker <[email protected]>
  • Loading branch information
cdecker committed Apr 12, 2018
1 parent 50600ae commit 85fbab2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 6 additions & 0 deletions wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 85fbab2

Please sign in to comment.