mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
wallet: have wallet_extract_outputs take wally_tx, not bitcoin_tx
With the incursion of PSBTs, we're moving away from bitcoin_tx
This commit is contained in:
committed by
Christian Decker
parent
0388fe6db4
commit
fd8a716695
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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! */
|
||||
|
||||
Reference in New Issue
Block a user