Browse Source

wallet: have wallet_extract_outputs take wally_tx, not bitcoin_tx

With the incursion of PSBTs, we're moving away from bitcoin_tx
paymod-02
niftynei 5 years ago
committed by Christian Decker
parent
commit
fd8a716695
  1. 2
      lightningd/chaintopology.c
  2. 14
      wallet/wallet.c
  3. 2
      wallet/wallet.h
  4. 2
      wallet/walletrpc.c

2
lightningd/chaintopology.c

@ -92,7 +92,7 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
bitcoin_txid(tx, &txid); bitcoin_txid(tx, &txid);
if (txfilter_match(topo->bitcoind->ld->owned_txfilter, tx)) { if (txfilter_match(topo->bitcoind->ld->owned_txfilter, tx)) {
wallet_extract_owned_outputs(topo->bitcoind->ld->wallet, 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, wallet_transaction_add(topo->ld->wallet, tx, b->height,
i); i);
} }

14
wallet/wallet.c

@ -1664,25 +1664,27 @@ void wallet_confirm_tx(struct wallet *w,
db_exec_prepared_v2(take(stmt)); 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, const u32 *blockheight,
struct amount_sat *total) struct amount_sat *total)
{ {
int num_utxos = 0; int num_utxos = 0;
*total = AMOUNT_SAT(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; struct utxo *utxo;
u32 index; u32 index;
bool is_p2sh; bool is_p2sh;
const u8 *script; 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; struct chain_coin_mvt *mvt;
if (!amount_asset_is_main(&asset)) if (!amount_asset_is_main(&asset))
continue; continue;
script = bitcoin_tx_output_get_script(tmpctx, tx, output); script = wally_tx_output_get_script(tmpctx,
&wtx->outputs[output]);
if (!script) if (!script)
continue; continue;
@ -1694,7 +1696,7 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
utxo->is_p2sh = is_p2sh; utxo->is_p2sh = is_p2sh;
utxo->amount = amount_asset_to_sat(&asset); utxo->amount = amount_asset_to_sat(&asset);
utxo->status = output_state_available; utxo->status = output_state_available;
bitcoin_txid(tx, &utxo->txid); wally_txid(wtx, &utxo->txid);
utxo->outnum = output; utxo->outnum = output;
utxo->close_info = NULL; 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)) if (!amount_sat_add(total, *total, utxo->amount))
fatal("Cannot add utxo output %zu/%zu %s + %s", 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, total),
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
&utxo->amount)); &utxo->amount));

2
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 * 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, const u32 *blockheight,
struct amount_sat *total); struct amount_sat *total);

2
wallet/walletrpc.c

@ -59,7 +59,7 @@ static void wallet_withdrawal_broadcast(struct bitcoind *bitcoind UNUSED,
wallet_confirm_utxos(ld->wallet, utx->wtx->utxos); wallet_confirm_utxos(ld->wallet, utx->wtx->utxos);
/* Extract the change output and add it to the DB */ /* 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 /* Note normally, change_satoshi == withdraw->wtx->change, but
* not if we're actually making a payment to ourselves! */ * not if we're actually making a payment to ourselves! */

Loading…
Cancel
Save