From adf14151fa868763d7b4ff05032cf45f3115312f Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 8 Nov 2022 15:42:38 +0100 Subject: [PATCH] wallet: Use boolean to determine whether an output is coinbase --- lightningd/chaintopology.c | 3 ++- lightningd/dual_open_control.c | 2 +- wallet/wallet.c | 6 +++--- wallet/wallet.h | 2 +- wallet/walletrpc.c | 3 +-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index eaa93e259..060789dc9 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -72,6 +72,7 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b) const struct bitcoin_tx *tx = b->full_txs[i]; struct bitcoin_txid txid; size_t j; + bool is_coinbase = i == 0; /* Tell them if it spends a txo we care about. */ for (j = 0; j < tx->wtx->num_inputs; j++) { @@ -92,7 +93,7 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b) txid = b->txids[i]; if (txfilter_match(topo->bitcoind->ld->owned_txfilter, tx)) { wallet_extract_owned_outputs(topo->bitcoind->ld->wallet, - tx->wtx, i, &b->height, &owned); + tx->wtx, is_coinbase, &b->height, &owned); wallet_transaction_add(topo->ld->wallet, tx->wtx, b->height, i); } diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 97d8747ae..468333f35 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -1462,7 +1462,7 @@ static void handle_tx_broadcast(struct channel_send *cs) /* This might have spent UTXOs from our wallet */ num_utxos = wallet_extract_owned_outputs(ld->wallet, /* FIXME: what txindex? */ - wtx, 1, NULL, + wtx, false, NULL, &unused); if (num_utxos) wallet_transaction_add(ld->wallet, wtx, 0, 0); diff --git a/wallet/wallet.c b/wallet/wallet.c index 391f18eb6..f56fc162f 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -2317,7 +2317,7 @@ void wallet_confirm_tx(struct wallet *w, } int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *wtx, - u32 tx_index, + bool is_coinbase, const u32 *blockheight, struct amount_sat *total) { @@ -2352,7 +2352,7 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *wtx, wally_txid(wtx, &utxo->outpoint.txid); utxo->outpoint.n = output; utxo->close_info = NULL; - utxo->is_in_coinbase = tx_index == 0; + utxo->is_in_coinbase = is_coinbase; utxo->blockheight = blockheight ? blockheight : NULL; utxo->spendheight = NULL; @@ -2366,7 +2366,7 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *wtx, type_to_string(tmpctx, struct bitcoin_txid, &utxo->outpoint.txid), blockheight ? " CONFIRMED" : "", - tx_index == 0 ? " COINBASE" : ""); + is_coinbase == 0 ? " COINBASE" : ""); /* We only record final ledger movements */ if (blockheight) { diff --git a/wallet/wallet.h b/wallet/wallet.h index 0c2da44e0..4b1d98e38 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -685,7 +685,7 @@ void wallet_blocks_heights(struct wallet *w, u32 def, u32 *min, u32 *max); * wallet_extract_owned_outputs - given a tx, extract all of our outputs */ int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *tx, - u32 tx_index, + bool is_coinbase, const u32 *blockheight, struct amount_sat *total); diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 9d02210ba..90d33372d 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -888,8 +888,7 @@ static void sendpsbt_done(struct bitcoind *bitcoind UNUSED, wallet_transaction_add(ld->wallet, sending->wtx, 0, 0); /* Extract the change output and add it to the DB */ - /* FIXME: what txindex? */ - wallet_extract_owned_outputs(ld->wallet, sending->wtx, 1, NULL, &change); + wallet_extract_owned_outputs(ld->wallet, sending->wtx, false, NULL, &change); wally_txid(sending->wtx, &txid); for (size_t i = 0; i < sending->psbt->num_outputs; i++)