mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
wallet: add flag to specify whether or not to include change output
Will allow for more intelligent change policy
This commit is contained in:
parent
8854bc8ae6
commit
38e404af51
@ -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->utxos = wallet_select_coins(tx, tx->cmd->ld->wallet,
|
||||||
tx->amount,
|
true, tx->amount,
|
||||||
fee_rate_per_kw, out_len,
|
fee_rate_per_kw, out_len,
|
||||||
maxheight,
|
maxheight,
|
||||||
&fee_estimate, &tx->change);
|
&fee_estimate, &tx->change);
|
||||||
|
@ -789,7 +789,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
|
|||||||
"wallet_add_utxo with close_info");
|
"wallet_add_utxo with close_info");
|
||||||
|
|
||||||
/* Now select them */
|
/* 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 */,
|
0 /* no confirmations required */,
|
||||||
&fee_estimate, &change_satoshis);
|
&fee_estimate, &change_satoshis);
|
||||||
CHECK(utxos && tal_count(utxos) == 2);
|
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");
|
"wallet_add_utxo with close_info no commitment_point");
|
||||||
|
|
||||||
/* Now select it */
|
/* 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 */,
|
0 /* no confirmations required */,
|
||||||
&fee_estimate, &change_satoshis);
|
&fee_estimate, &change_satoshis);
|
||||||
CHECK(utxos && tal_count(utxos) == 2);
|
CHECK(utxos && tal_count(utxos) == 2);
|
||||||
|
@ -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,
|
const struct utxo **wallet_select_coins(const tal_t *ctx, struct wallet *w,
|
||||||
|
bool with_change,
|
||||||
struct amount_sat sat,
|
struct amount_sat sat,
|
||||||
const u32 feerate_per_kw,
|
const u32 feerate_per_kw,
|
||||||
size_t outscriptlen,
|
size_t outscriptlen,
|
||||||
@ -444,7 +445,7 @@ const struct utxo **wallet_select_coins(const tal_t *ctx, struct wallet *w,
|
|||||||
const struct utxo **utxo;
|
const struct utxo **utxo;
|
||||||
|
|
||||||
utxo = wallet_select(ctx, w, sat, feerate_per_kw,
|
utxo = wallet_select(ctx, w, sat, feerate_per_kw,
|
||||||
outscriptlen, true, maxheight,
|
outscriptlen, with_change, maxheight,
|
||||||
&satoshi_in, fee_estimate);
|
&satoshi_in, fee_estimate);
|
||||||
|
|
||||||
/* Couldn't afford it? */
|
/* 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))
|
|| !amount_sat_sub(change, *change, *fee_estimate))
|
||||||
return tal_free(utxo);
|
return tal_free(utxo);
|
||||||
|
|
||||||
|
if (!with_change)
|
||||||
|
*change = AMOUNT_SAT(0);
|
||||||
|
|
||||||
return utxo;
|
return utxo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +358,7 @@ struct utxo **wallet_get_unconfirmed_closeinfo_utxos(const tal_t *ctx,
|
|||||||
struct wallet *w);
|
struct wallet *w);
|
||||||
|
|
||||||
const struct utxo **wallet_select_coins(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,
|
struct amount_sat value,
|
||||||
const u32 feerate_per_kw,
|
const u32 feerate_per_kw,
|
||||||
size_t outscriptlen,
|
size_t outscriptlen,
|
||||||
|
Loading…
Reference in New Issue
Block a user