Browse Source

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

Will allow for more intelligent change policy
travis-debug
lisa neigut 6 years ago
committed by Rusty Russell
parent
commit
38e404af51
  1. 2
      common/wallet_tx.c
  2. 4
      wallet/test/run-wallet.c
  3. 6
      wallet/wallet.c
  4. 1
      wallet/wallet.h

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

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

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

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

Loading…
Cancel
Save