2017-06-20 16:46:31 +02:00
|
|
|
#include "withdraw_tx.h"
|
2019-03-15 14:20:07 +01:00
|
|
|
#include <assert.h>
|
2017-06-20 16:46:31 +02:00
|
|
|
#include <bitcoin/pubkey.h>
|
|
|
|
#include <bitcoin/script.h>
|
|
|
|
#include <ccan/ptrint/ptrint.h>
|
2019-09-17 02:08:05 +02:00
|
|
|
#include <common/key_derive.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <common/permute_tx.h>
|
2019-08-16 19:01:26 +02:00
|
|
|
#include <common/utils.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/utxo.h>
|
2017-12-10 06:48:18 +01:00
|
|
|
#include <string.h>
|
2017-12-21 12:10:24 +01:00
|
|
|
#include <wally_bip32.h>
|
2017-06-20 16:46:31 +02:00
|
|
|
|
|
|
|
struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
|
2019-07-30 16:14:43 +02:00
|
|
|
const struct chainparams *chainparams,
|
2017-06-20 16:46:31 +02:00
|
|
|
const struct utxo **utxos,
|
2019-08-12 21:29:13 +02:00
|
|
|
struct bitcoin_tx_output **outputs,
|
2019-06-05 07:28:57 +02:00
|
|
|
const struct ext_key *bip32_base,
|
2019-09-17 02:08:05 +02:00
|
|
|
u32 nlocktime)
|
2017-06-20 16:46:31 +02:00
|
|
|
{
|
2018-12-03 00:02:11 +01:00
|
|
|
struct bitcoin_tx *tx;
|
2019-12-30 20:02:23 +01:00
|
|
|
int output_count;
|
2018-12-03 00:02:11 +01:00
|
|
|
|
2019-07-30 16:14:43 +02:00
|
|
|
tx = tx_spending_utxos(ctx, chainparams, utxos, bip32_base,
|
2019-09-17 02:08:05 +02:00
|
|
|
false, tal_count(outputs), nlocktime,
|
2020-01-29 12:59:06 +01:00
|
|
|
BITCOIN_TX_DEFAULT_SEQUENCE - 1);
|
2018-12-03 00:02:11 +01:00
|
|
|
|
2019-12-30 20:02:23 +01:00
|
|
|
output_count = bitcoin_tx_add_multi_outputs(tx, outputs);
|
|
|
|
assert(output_count == tal_count(outputs));
|
2017-06-20 16:46:31 +02:00
|
|
|
|
2019-09-17 02:08:05 +02:00
|
|
|
permute_outputs(tx, NULL, (const void **)outputs);
|
2019-03-14 17:47:13 +01:00
|
|
|
permute_inputs(tx, (const void **)utxos);
|
2020-02-08 21:26:55 +01:00
|
|
|
|
|
|
|
bitcoin_tx_finalize(tx);
|
2019-03-15 14:20:07 +01:00
|
|
|
assert(bitcoin_tx_check(tx));
|
2017-06-20 16:46:31 +02:00
|
|
|
return tx;
|
|
|
|
}
|
|
|
|
|