wallet: Use boolean to determine whether an output is coinbase

This commit is contained in:
Christian Decker 2022-11-08 15:42:38 +01:00
parent 26f5dcd2a5
commit adf14151fa
5 changed files with 8 additions and 8 deletions

View file

@ -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);
}

View file

@ -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);

View file

@ -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) {

View file

@ -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);

View file

@ -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++)