2021-02-01 13:28:50 +10:30
|
|
|
#include "config.h"
|
2017-08-29 01:35:01 +09:30
|
|
|
#include <common/utxo.h>
|
2017-02-21 15:15:29 +10:30
|
|
|
#include <wire/wire.h>
|
|
|
|
|
|
|
|
void towire_utxo(u8 **pptr, const struct utxo *utxo)
|
|
|
|
{
|
2018-01-02 14:54:32 +01:00
|
|
|
/* Is this a unilateral close output and needs the
|
|
|
|
* close_info? */
|
|
|
|
bool is_unilateral_close = utxo->close_info != NULL;
|
2017-12-18 17:11:52 +10:30
|
|
|
towire_bitcoin_txid(pptr, &utxo->txid);
|
2017-02-21 15:15:29 +10:30
|
|
|
towire_u32(pptr, utxo->outnum);
|
2019-02-21 13:09:51 +10:30
|
|
|
towire_amount_sat(pptr, utxo->amount);
|
2017-02-21 15:15:29 +10:30
|
|
|
towire_u32(pptr, utxo->keyindex);
|
|
|
|
towire_bool(pptr, utxo->is_p2sh);
|
2018-01-02 14:54:32 +01:00
|
|
|
|
2019-09-30 17:05:28 -05:00
|
|
|
towire_u16(pptr, tal_count(utxo->scriptPubkey));
|
|
|
|
towire_u8_array(pptr, utxo->scriptPubkey, tal_count(utxo->scriptPubkey));
|
|
|
|
|
2018-01-02 14:54:32 +01:00
|
|
|
towire_bool(pptr, is_unilateral_close);
|
|
|
|
if (is_unilateral_close) {
|
|
|
|
towire_u64(pptr, utxo->close_info->channel_id);
|
2019-04-08 19:28:32 +09:30
|
|
|
towire_node_id(pptr, &utxo->close_info->peer_id);
|
2019-09-10 11:54:27 +09:30
|
|
|
towire_bool(pptr, utxo->close_info->commitment_point != NULL);
|
|
|
|
if (utxo->close_info->commitment_point)
|
|
|
|
towire_pubkey(pptr, utxo->close_info->commitment_point);
|
2020-08-14 11:00:42 +09:30
|
|
|
towire_bool(pptr, utxo->close_info->option_anchor_outputs);
|
2021-06-16 12:56:36 -05:00
|
|
|
towire_u32(pptr, utxo->close_info->csv);
|
2018-01-02 14:54:32 +01:00
|
|
|
}
|
2017-02-21 15:15:29 +10:30
|
|
|
}
|
|
|
|
|
2018-02-08 11:53:46 +10:30
|
|
|
struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
|
2017-02-21 15:15:29 +10:30
|
|
|
{
|
2018-02-08 11:53:46 +10:30
|
|
|
struct utxo *utxo = tal(ctx, struct utxo);
|
|
|
|
|
2017-12-18 17:11:52 +10:30
|
|
|
fromwire_bitcoin_txid(ptr, max, &utxo->txid);
|
2017-02-21 15:15:29 +10:30
|
|
|
utxo->outnum = fromwire_u32(ptr, max);
|
2019-02-21 13:09:51 +10:30
|
|
|
utxo->amount = fromwire_amount_sat(ptr, max);
|
2017-02-21 15:15:29 +10:30
|
|
|
utxo->keyindex = fromwire_u32(ptr, max);
|
|
|
|
utxo->is_p2sh = fromwire_bool(ptr, max);
|
2019-02-22 15:47:30 +01:00
|
|
|
|
2019-09-30 17:05:28 -05:00
|
|
|
utxo->scriptPubkey = fromwire_tal_arrn(utxo, ptr, max, fromwire_u16(ptr, max));
|
2019-02-22 15:47:30 +01:00
|
|
|
|
2018-01-02 14:54:32 +01:00
|
|
|
if (fromwire_bool(ptr, max)) {
|
2018-02-08 11:53:46 +10:30
|
|
|
utxo->close_info = tal(utxo, struct unilateral_close_info);
|
2018-01-02 14:54:32 +01:00
|
|
|
utxo->close_info->channel_id = fromwire_u64(ptr, max);
|
2019-04-08 19:28:32 +09:30
|
|
|
fromwire_node_id(ptr, max, &utxo->close_info->peer_id);
|
2019-09-10 11:54:27 +09:30
|
|
|
if (fromwire_bool(ptr, max)) {
|
|
|
|
utxo->close_info->commitment_point = tal(utxo,
|
|
|
|
struct pubkey);
|
|
|
|
fromwire_pubkey(ptr, max,
|
|
|
|
utxo->close_info->commitment_point);
|
|
|
|
} else
|
|
|
|
utxo->close_info->commitment_point = NULL;
|
2020-08-14 11:00:42 +09:30
|
|
|
utxo->close_info->option_anchor_outputs
|
|
|
|
= fromwire_bool(ptr, max);
|
2021-06-16 12:56:36 -05:00
|
|
|
utxo->close_info->csv = fromwire_u32(ptr, max);
|
2018-01-02 14:54:32 +01:00
|
|
|
} else {
|
|
|
|
utxo->close_info = NULL;
|
|
|
|
}
|
2018-02-08 11:53:46 +10:30
|
|
|
return utxo;
|
2017-02-21 15:15:29 +10:30
|
|
|
}
|
2018-12-03 09:32:11 +10:30
|
|
|
|
2020-11-17 19:45:23 -06:00
|
|
|
size_t utxo_spend_weight(const struct utxo *utxo, size_t min_witness_weight)
|
2020-07-06 14:56:14 +09:30
|
|
|
{
|
2020-11-17 19:45:23 -06:00
|
|
|
size_t wit_weight = bitcoin_tx_simple_input_witness_weight();
|
|
|
|
/* If the min is less than what we'd use for a 'normal' tx,
|
|
|
|
* we return the value with the greater added/calculated */
|
|
|
|
if (wit_weight < min_witness_weight)
|
|
|
|
return bitcoin_tx_input_weight(utxo->is_p2sh,
|
|
|
|
min_witness_weight);
|
|
|
|
|
|
|
|
return bitcoin_tx_input_weight(utxo->is_p2sh, wit_weight);
|
2020-07-06 14:56:14 +09:30
|
|
|
}
|