diff --git a/common/wallet_tx.c b/common/wallet_tx.c index dc4e8b3a8..d462e06c5 100644 --- a/common/wallet_tx.c +++ b/common/wallet_tx.c @@ -152,7 +152,7 @@ struct command_result *wtx_select_utxos(struct wallet_tx *tx, } tx->utxos = wallet_select_coins(tx, tx->cmd->ld->wallet, - tx->amount, + true, tx->amount, fee_rate_per_kw, out_len, maxheight, &fee_estimate, &tx->change); diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index e5af87224..c47851842 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -789,7 +789,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx) "wallet_add_utxo with close_info"); /* Now select them */ - utxos = wallet_select_coins(w, w, AMOUNT_SAT(2), 0, 21, + utxos = wallet_select_coins(w, w, true, AMOUNT_SAT(2), 0, 21, 0 /* no confirmations required */, &fee_estimate, &change_satoshis); CHECK(utxos && tal_count(utxos) == 2); @@ -837,7 +837,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx) "wallet_add_utxo with close_info no commitment_point"); /* Now select it */ - utxos = wallet_select_coins(w, w, AMOUNT_SAT(5), 0, 21, + utxos = wallet_select_coins(w, w, true, AMOUNT_SAT(5), 0, 21, 0 /* no confirmations required */, &fee_estimate, &change_satoshis); CHECK(utxos && tal_count(utxos) == 2); diff --git a/wallet/wallet.c b/wallet/wallet.c index 91c463520..9d3e11b80 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -433,6 +433,7 @@ static const struct utxo **wallet_select(const tal_t *ctx, struct wallet *w, } const struct utxo **wallet_select_coins(const tal_t *ctx, struct wallet *w, + bool with_change, struct amount_sat sat, const u32 feerate_per_kw, size_t outscriptlen, @@ -444,7 +445,7 @@ const struct utxo **wallet_select_coins(const tal_t *ctx, struct wallet *w, const struct utxo **utxo; utxo = wallet_select(ctx, w, sat, feerate_per_kw, - outscriptlen, true, maxheight, + outscriptlen, with_change, maxheight, &satoshi_in, fee_estimate); /* Couldn't afford it? */ @@ -452,6 +453,9 @@ const struct utxo **wallet_select_coins(const tal_t *ctx, struct wallet *w, || !amount_sat_sub(change, *change, *fee_estimate)) return tal_free(utxo); + if (!with_change) + *change = AMOUNT_SAT(0); + return utxo; } diff --git a/wallet/wallet.h b/wallet/wallet.h index 145c09565..9272adff3 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -358,6 +358,7 @@ struct utxo **wallet_get_unconfirmed_closeinfo_utxos(const tal_t *ctx, struct wallet *w); const struct utxo **wallet_select_coins(const tal_t *ctx, struct wallet *w, + bool with_change, struct amount_sat value, const u32 feerate_per_kw, size_t outscriptlen,