chaintopology: Use the DB to locate transactions and rebroadcast txs

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2018-04-09 18:48:39 +02:00
parent 86b6402e5c
commit 23984ecde4
4 changed files with 38 additions and 58 deletions

View File

@@ -2206,7 +2206,7 @@ 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=?");
w->db, "SELECT blockheight FROM transactions WHERE id=?");
sqlite3_bind_sha256(stmt, 1, &txid->shad.sha);
if (sqlite3_step(stmt) != SQLITE_ROW) {
@@ -2218,3 +2218,31 @@ u32 wallet_transaction_height(struct wallet *w, const struct bitcoin_txid *txid)
sqlite3_finalize(stmt);
return blockheight;
}
struct txlocator *wallet_transaction_locate(const tal_t *ctx, struct wallet *w,
const struct bitcoin_txid *txid)
{
struct txlocator *loc;
sqlite3_stmt *stmt;
stmt = db_prepare(
w->db, "SELECT blockheight, txindex FROM transactions WHERE id=?");
sqlite3_bind_sha256(stmt, 1, &txid->shad.sha);
if (sqlite3_step(stmt) != SQLITE_ROW) {
goto fail;
}
if (sqlite3_column_type(stmt, 0) == SQLITE_NULL)
goto fail;
loc = tal(ctx, struct txlocator);
loc->blkheight = sqlite3_column_int(stmt, 0);
loc->index = sqlite3_column_int(stmt, 1);
sqlite3_finalize(stmt);
return loc;
fail:
sqlite3_finalize(stmt);
return NULL;
}

View File

@@ -820,4 +820,11 @@ void wallet_transaction_add(struct wallet *w, const struct bitcoin_tx *tx,
*/
u32 wallet_transaction_height(struct wallet *w, const struct bitcoin_txid *txid);
/**
* Locate a transaction in the blockchain, returns NULL if the transaction is
* not tracked or is not yet confirmed.
*/
struct txlocator *wallet_transaction_locate(const tal_t *ctx, struct wallet *w,
const struct bitcoin_txid *txid);
#endif /* LIGHTNING_WALLET_WALLET_H */