mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-20 13:54:36 +01:00
wallet: Add outpointfilter to wallet so we can pass it all outputs
Will be used later to filter out outputs we are interested in, and trigger db updates with them. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
5fd19483a9
commit
7fc06d9b3e
3 changed files with 28 additions and 0 deletions
|
@ -254,6 +254,13 @@ struct json_result *new_json_result(const tal_t *ctx UNNEEDED)
|
|||
/* Generated stub for null_response */
|
||||
struct json_result *null_response(const tal_t *ctx UNNEEDED)
|
||||
{ fprintf(stderr, "null_response called!\n"); abort(); }
|
||||
/* Generated stub for outpointfilter_add */
|
||||
void outpointfilter_add(struct outpointfilter *of UNNEEDED,
|
||||
const struct bitcoin_txid *txid UNNEEDED, const u32 outnum UNNEEDED)
|
||||
{ fprintf(stderr, "outpointfilter_add called!\n"); abort(); }
|
||||
/* Generated stub for outpointfilter_new */
|
||||
struct outpointfilter *outpointfilter_new(tal_t *ctx UNNEEDED)
|
||||
{ fprintf(stderr, "outpointfilter_new called!\n"); abort(); }
|
||||
/* Generated stub for peer_accept_channel */
|
||||
u8 *peer_accept_channel(struct lightningd *ld UNNEEDED,
|
||||
const struct pubkey *peer_id UNNEEDED,
|
||||
|
|
|
@ -16,6 +16,17 @@
|
|||
#define DIRECTION_INCOMING 0
|
||||
#define DIRECTION_OUTGOING 1
|
||||
|
||||
static void outpointfilters_init(struct wallet *w)
|
||||
{
|
||||
struct utxo **utxos = wallet_get_utxos(NULL, w, output_state_any);
|
||||
|
||||
w->owned_outpoints = outpointfilter_new(w);
|
||||
for (size_t i = 0; i < tal_count(utxos); i++)
|
||||
outpointfilter_add(w->owned_outpoints, &utxos[i]->txid, utxos[i]->outnum);
|
||||
|
||||
tal_free(utxos);
|
||||
}
|
||||
|
||||
struct wallet *wallet_new(struct lightningd *ld,
|
||||
struct log *log, struct timers *timers)
|
||||
{
|
||||
|
@ -26,6 +37,10 @@ struct wallet *wallet_new(struct lightningd *ld,
|
|||
wallet->bip32_base = NULL;
|
||||
wallet->invoices = invoices_new(wallet, wallet->db, log, timers);
|
||||
list_head_init(&wallet->unstored_payments);
|
||||
|
||||
db_begin_transaction(wallet->db);
|
||||
outpointfilters_init(wallet);
|
||||
db_commit_transaction(wallet->db);
|
||||
return wallet;
|
||||
}
|
||||
|
||||
|
@ -1016,6 +1031,8 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
|
|||
tal_free(utxo);
|
||||
return -1;
|
||||
}
|
||||
outpointfilter_add(w->owned_outpoints, &utxo->txid, utxo->outnum);
|
||||
|
||||
*total_satoshi += utxo->amount;
|
||||
tal_free(utxo);
|
||||
num_utxos++;
|
||||
|
|
|
@ -32,6 +32,10 @@ struct wallet {
|
|||
struct invoices *invoices;
|
||||
struct list_head unstored_payments;
|
||||
u64 max_channel_dbid;
|
||||
|
||||
/* Filter matching all outpoints corresponding to our owned outputs,
|
||||
* including all spent ones */
|
||||
struct outpointfilter *owned_outpoints;
|
||||
};
|
||||
|
||||
/* Possible states for tracked outputs in the database. Not sure yet
|
||||
|
|
Loading…
Add table
Reference in a new issue