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-16 19:08:05 -05:00
|
|
|
#include <common/key_derive.h>
|
2017-08-29 01:32:01 +09:30
|
|
|
#include <common/permute_tx.h>
|
2019-08-17 01:01:26 +08:00
|
|
|
#include <common/utils.h>
|
2017-08-29 01:35:01 +09:30
|
|
|
#include <common/utxo.h>
|
2017-12-10 05:48:18 +00:00
|
|
|
#include <string.h>
|
2017-12-21 21:40:24 +10:30
|
|
|
#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-13 03:29:13 +08:00
|
|
|
struct bitcoin_tx_output **outputs,
|
2019-06-05 14:58:57 +09:30
|
|
|
const struct ext_key *bip32_base,
|
2019-09-16 19:08:05 -05:00
|
|
|
u32 nlocktime)
|
2017-06-20 16:46:31 +02:00
|
|
|
{
|
2018-12-03 09:32:11 +10:30
|
|
|
struct bitcoin_tx *tx;
|
2019-12-30 13:02:23 -06:00
|
|
|
int output_count;
|
2018-12-03 09:32:11 +10:30
|
|
|
|
2019-07-30 16:14:43 +02:00
|
|
|
tx = tx_spending_utxos(ctx, chainparams, utxos, bip32_base,
|
2019-09-16 19:08:05 -05:00
|
|
|
false, tal_count(outputs), nlocktime,
|
2020-01-29 12:59:06 +01:00
|
|
|
BITCOIN_TX_DEFAULT_SEQUENCE - 1);
|
2018-12-03 09:32:11 +10:30
|
|
|
|
2019-12-30 13:02:23 -06: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-16 19:08:05 -05: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;
|
|
|
|
}
|
|
|
|
|