2017-02-21 05:49:02 +01:00
|
|
|
#include <bitcoin/base58.h>
|
|
|
|
#include <bitcoin/script.h>
|
|
|
|
#include <ccan/structeq/structeq.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <common/utils.h>
|
2017-02-21 05:49:02 +01:00
|
|
|
#include <lightningd/build_utxos.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <lightningd/jsonrpc.h>
|
2017-02-21 05:49:02 +01:00
|
|
|
#include <lightningd/lightningd.h>
|
|
|
|
#include <wally_bip32.h>
|
|
|
|
|
|
|
|
|
2017-03-07 01:58:09 +01:00
|
|
|
const struct utxo **build_utxos(const tal_t *ctx,
|
|
|
|
struct lightningd *ld, u64 satoshi_out,
|
|
|
|
u32 feerate_per_kw, u64 dust_limit,
|
2017-12-20 07:05:01 +01:00
|
|
|
size_t outputscriptlen,
|
2017-03-07 01:58:09 +01:00
|
|
|
u64 *change_satoshis, u32 *change_keyindex)
|
2017-02-21 05:49:02 +01:00
|
|
|
{
|
2017-06-13 15:42:31 +02:00
|
|
|
u64 fee_estimate = 0;
|
|
|
|
const struct utxo **utxos =
|
2017-06-20 16:54:53 +02:00
|
|
|
wallet_select_coins(ctx, ld->wallet, satoshi_out, feerate_per_kw,
|
2017-12-20 07:05:01 +01:00
|
|
|
outputscriptlen,
|
2017-06-20 16:54:53 +02:00
|
|
|
&fee_estimate, change_satoshis);
|
2017-02-21 05:49:02 +01:00
|
|
|
|
2017-06-13 15:42:31 +02:00
|
|
|
/* Oops, didn't have enough coins available */
|
|
|
|
if (!utxos)
|
|
|
|
return NULL;
|
2017-02-21 05:49:02 +01:00
|
|
|
|
2017-06-13 15:42:31 +02:00
|
|
|
/* Do we need a change output? */
|
|
|
|
if (*change_satoshis < dust_limit) {
|
|
|
|
*change_satoshis = 0;
|
|
|
|
*change_keyindex = 0;
|
|
|
|
} else {
|
2017-12-12 14:58:21 +01:00
|
|
|
*change_keyindex = wallet_get_newindex(ld);
|
2017-02-21 05:49:02 +01:00
|
|
|
}
|
2017-06-13 15:42:31 +02:00
|
|
|
return utxos;
|
2017-02-21 05:49:02 +01:00
|
|
|
}
|