chaintopo: Record outpoint spends for owned outputs

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2018-03-02 15:07:13 +01:00
parent 2680e6d9ff
commit ae30942e3f
4 changed files with 44 additions and 0 deletions

View File

@@ -348,6 +348,22 @@ static void updates_complete(struct chain_topology *topo)
next_topology_timer(topo);
}
/**
* topo_update_spends -- Tell the wallet about all spent outpoints
*/
static void topo_update_spends(struct chain_topology *topo, struct block *b)
{
for (size_t i = 0; i < tal_count(b->full_txs); i++) {
const struct bitcoin_tx *tx = b->full_txs[i];
for (size_t j = 0; j < tal_count(tx->input); j++) {
const struct bitcoin_tx_input *input = &tx->input[j];
wallet_outpoint_spend(topo->wallet, b->height,
&input->txid,
input->index);
}
}
}
static void add_tip(struct chain_topology *topo, struct block *b)
{
/* Attach to tip; b is now the tip. */
@@ -357,6 +373,8 @@ static void add_tip(struct chain_topology *topo, struct block *b)
topo->tip = b;
wallet_block_add(topo->wallet, b);
topo_update_spends(topo, b);
/* Only keep the transactions we care about. */
filter_block_txs(topo, b);