Browse Source

wallet: Add outpointfilter for the utxoset

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

14
wallet/wallet.c

@ -18,13 +18,27 @@
static void outpointfilters_init(struct wallet *w) static void outpointfilters_init(struct wallet *w)
{ {
sqlite3_stmt *stmt;
struct utxo **utxos = wallet_get_utxos(NULL, w, output_state_any); struct utxo **utxos = wallet_get_utxos(NULL, w, output_state_any);
struct bitcoin_txid txid;
u32 outnum;
w->owned_outpoints = outpointfilter_new(w); w->owned_outpoints = outpointfilter_new(w);
for (size_t i = 0; i < tal_count(utxos); i++) for (size_t i = 0; i < tal_count(utxos); i++)
outpointfilter_add(w->owned_outpoints, &utxos[i]->txid, utxos[i]->outnum); outpointfilter_add(w->owned_outpoints, &utxos[i]->txid, utxos[i]->outnum);
tal_free(utxos); tal_free(utxos);
w->utxoset_outpoints = outpointfilter_new(w);
stmt = db_prepare(w->db, "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL");
while (sqlite3_step(stmt) == SQLITE_ROW) {
sqlite3_column_sha256_double(stmt, 0, &txid.shad);
outnum = sqlite3_column_int(stmt, 1);
outpointfilter_add(w->utxoset_outpoints, &txid, outnum);
}
sqlite3_finalize(stmt);
} }
struct wallet *wallet_new(struct lightningd *ld, struct wallet *wallet_new(struct lightningd *ld,

4
wallet/wallet.h

@ -36,6 +36,10 @@ struct wallet {
/* Filter matching all outpoints corresponding to our owned outputs, /* Filter matching all outpoints corresponding to our owned outputs,
* including all spent ones */ * including all spent ones */
struct outpointfilter *owned_outpoints; struct outpointfilter *owned_outpoints;
/* Filter matching all outpoints that might be a funding transaction on
* the blockchain. This is currently all P2WSH outputs */
struct outpointfilter *utxoset_outpoints;
}; };
/* Possible states for tracked outputs in the database. Not sure yet /* Possible states for tracked outputs in the database. Not sure yet

Loading…
Cancel
Save