mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
wallet: Return any eventual outpoint scid when marking it spent
Just return the short_channel_id matching the outpoint that we just marked as spent. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
@@ -406,13 +406,17 @@ static void updates_complete(struct chain_topology *topo)
|
|||||||
*/
|
*/
|
||||||
static void topo_update_spends(struct chain_topology *topo, struct block *b)
|
static void topo_update_spends(struct chain_topology *topo, struct block *b)
|
||||||
{
|
{
|
||||||
|
const struct short_channel_id *scid;
|
||||||
for (size_t i = 0; i < tal_count(b->full_txs); i++) {
|
for (size_t i = 0; i < tal_count(b->full_txs); i++) {
|
||||||
const struct bitcoin_tx *tx = b->full_txs[i];
|
const struct bitcoin_tx *tx = b->full_txs[i];
|
||||||
for (size_t j = 0; j < tal_count(tx->input); j++) {
|
for (size_t j = 0; j < tal_count(tx->input); j++) {
|
||||||
const struct bitcoin_tx_input *input = &tx->input[j];
|
const struct bitcoin_tx_input *input = &tx->input[j];
|
||||||
wallet_outpoint_spend(topo->wallet, b->height,
|
scid = wallet_outpoint_spend(topo->wallet, tmpctx,
|
||||||
&input->txid,
|
b->height, &input->txid,
|
||||||
input->index);
|
input->index);
|
||||||
|
if (scid) {
|
||||||
|
tal_free(scid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2016,10 +2016,13 @@ void wallet_blocks_rollback(struct wallet *w, u32 height)
|
|||||||
db_exec_prepared(w->db, stmt);
|
db_exec_prepared(w->db, stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wallet_outpoint_spend(struct wallet *w, const u32 blockheight,
|
const struct short_channel_id *
|
||||||
const struct bitcoin_txid *txid, const u32 outnum)
|
wallet_outpoint_spend(struct wallet *w, const tal_t *ctx, const u32 blockheight,
|
||||||
|
const struct bitcoin_txid *txid, const u32 outnum)
|
||||||
{
|
{
|
||||||
|
struct short_channel_id *scid;
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
|
int res;
|
||||||
if (outpointfilter_matches(w->owned_outpoints, txid, outnum)) {
|
if (outpointfilter_matches(w->owned_outpoints, txid, outnum)) {
|
||||||
stmt = db_prepare(w->db,
|
stmt = db_prepare(w->db,
|
||||||
"UPDATE outputs "
|
"UPDATE outputs "
|
||||||
@@ -2046,7 +2049,29 @@ void wallet_outpoint_spend(struct wallet *w, const u32 blockheight,
|
|||||||
sqlite3_bind_int(stmt, 3, outnum);
|
sqlite3_bind_int(stmt, 3, outnum);
|
||||||
|
|
||||||
db_exec_prepared(w->db, stmt);
|
db_exec_prepared(w->db, stmt);
|
||||||
|
|
||||||
|
if (sqlite3_changes(w->db->sql) == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now look for the outpoint's short_channel_id */
|
||||||
|
stmt = db_prepare(w->db,
|
||||||
|
"SELECT blockheight, txindex "
|
||||||
|
"FROM utxoset "
|
||||||
|
"WHERE txid = ? AND outnum = ?");
|
||||||
|
sqlite3_bind_sha256_double(stmt, 1, &txid->shad);
|
||||||
|
sqlite3_bind_int(stmt, 2, outnum);
|
||||||
|
|
||||||
|
res = sqlite3_step(stmt);
|
||||||
|
assert(res == SQLITE_ROW);
|
||||||
|
|
||||||
|
scid = tal(ctx, struct short_channel_id);
|
||||||
|
mk_short_channel_id(scid, sqlite3_column_int(stmt, 0),
|
||||||
|
sqlite3_column_int(stmt, 1), outnum);
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return scid;
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx,
|
void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx,
|
||||||
|
|||||||
@@ -790,8 +790,18 @@ void wallet_block_remove(struct wallet *w, struct block *b);
|
|||||||
*/
|
*/
|
||||||
void wallet_blocks_rollback(struct wallet *w, u32 height);
|
void wallet_blocks_rollback(struct wallet *w, u32 height);
|
||||||
|
|
||||||
void wallet_outpoint_spend(struct wallet *w, const u32 blockheight,
|
/**
|
||||||
const struct bitcoin_txid *txid, const u32 outnum);
|
* Mark an outpoint as spent, both in the owned as well as the UTXO set
|
||||||
|
*
|
||||||
|
* Given the outpoint (txid, outnum), and the blockheight, mark the
|
||||||
|
* corresponding DB entries as spent at the blockheight.
|
||||||
|
*
|
||||||
|
* @return scid The short_channel_id corresponding to the spent outpoint, if
|
||||||
|
* any.
|
||||||
|
*/
|
||||||
|
const struct short_channel_id *
|
||||||
|
wallet_outpoint_spend(struct wallet *w, const tal_t *ctx, const u32 blockheight,
|
||||||
|
const struct bitcoin_txid *txid, const u32 outnum);
|
||||||
|
|
||||||
struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx,
|
struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx,
|
||||||
const struct short_channel_id *scid);
|
const struct short_channel_id *scid);
|
||||||
|
|||||||
Reference in New Issue
Block a user