From fd8a716695228eb549b2de0bb3670e5b86e59d7c Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 16 Jun 2020 13:43:51 -0500 Subject: [PATCH] wallet: have wallet_extract_outputs take wally_tx, not bitcoin_tx With the incursion of PSBTs, we're moving away from bitcoin_tx --- lightningd/chaintopology.c | 2 +- wallet/wallet.c | 14 ++++++++------ wallet/wallet.h | 2 +- wallet/walletrpc.c | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 0c874ee1b..a2e60a8e6 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -92,7 +92,7 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b) bitcoin_txid(tx, &txid); if (txfilter_match(topo->bitcoind->ld->owned_txfilter, tx)) { wallet_extract_owned_outputs(topo->bitcoind->ld->wallet, - tx, &b->height, &owned); + tx->wtx, &b->height, &owned); wallet_transaction_add(topo->ld->wallet, tx, b->height, i); } diff --git a/wallet/wallet.c b/wallet/wallet.c index a64f787e5..bba6704b1 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1664,25 +1664,27 @@ void wallet_confirm_tx(struct wallet *w, db_exec_prepared_v2(take(stmt)); } -int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx, +int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *wtx, const u32 *blockheight, struct amount_sat *total) { int num_utxos = 0; *total = AMOUNT_SAT(0); - for (size_t output = 0; output < tx->wtx->num_outputs; output++) { + for (size_t output = 0; output < wtx->num_outputs; output++) { struct utxo *utxo; u32 index; bool is_p2sh; const u8 *script; - struct amount_asset asset = bitcoin_tx_output_get_amount(tx, output); + struct amount_asset asset = + wally_tx_output_get_amount(&wtx->outputs[output]); struct chain_coin_mvt *mvt; if (!amount_asset_is_main(&asset)) continue; - script = bitcoin_tx_output_get_script(tmpctx, tx, output); + script = wally_tx_output_get_script(tmpctx, + &wtx->outputs[output]); if (!script) continue; @@ -1694,7 +1696,7 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx, utxo->is_p2sh = is_p2sh; utxo->amount = amount_asset_to_sat(&asset); utxo->status = output_state_available; - bitcoin_txid(tx, &utxo->txid); + wally_txid(wtx, &utxo->txid); utxo->outnum = output; utxo->close_info = NULL; @@ -1738,7 +1740,7 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx, if (!amount_sat_add(total, *total, utxo->amount)) fatal("Cannot add utxo output %zu/%zu %s + %s", - output, tx->wtx->num_outputs, + output, wtx->num_outputs, type_to_string(tmpctx, struct amount_sat, total), type_to_string(tmpctx, struct amount_sat, &utxo->amount)); diff --git a/wallet/wallet.h b/wallet/wallet.h index 8d326ddb2..8213184ee 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -560,7 +560,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 bitcoin_tx *tx, +int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *tx, const u32 *blockheight, struct amount_sat *total); diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 0612fd358..a6fc4180c 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -59,7 +59,7 @@ static void wallet_withdrawal_broadcast(struct bitcoind *bitcoind UNUSED, wallet_confirm_utxos(ld->wallet, utx->wtx->utxos); /* Extract the change output and add it to the DB */ - wallet_extract_owned_outputs(ld->wallet, utx->tx, NULL, &change); + wallet_extract_owned_outputs(ld->wallet, utx->tx->wtx, NULL, &change); /* Note normally, change_satoshi == withdraw->wtx->change, but * not if we're actually making a payment to ourselves! */