wallet: add flag to specify whether or not to include change output

Will allow for more intelligent change policy
This commit is contained in:
lisa neigut 2019-08-29 21:13:33 -05:00 committed by Rusty Russell
parent 8854bc8ae6
commit 38e404af51
4 changed files with 9 additions and 4 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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,