2017-08-28 18:05:01 +02:00
|
|
|
#include <common/utxo.h>
|
2017-02-21 05:45:29 +01:00
|
|
|
#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 07:41:52 +01:00
|
|
|
towire_bitcoin_txid(pptr, &utxo->txid);
|
2017-02-21 05:45:29 +01:00
|
|
|
towire_u32(pptr, utxo->outnum);
|
|
|
|
towire_u64(pptr, utxo->amount);
|
|
|
|
towire_u32(pptr, utxo->keyindex);
|
|
|
|
towire_bool(pptr, utxo->is_p2sh);
|
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);
|
|
|
|
towire_pubkey(pptr, &utxo->close_info->peer_id);
|
|
|
|
towire_pubkey(pptr, &utxo->close_info->commitment_point);
|
|
|
|
}
|
2017-02-21 05:45:29 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 02:23:46 +01:00
|
|
|
struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
|
2017-02-21 05:45:29 +01:00
|
|
|
{
|
2018-02-08 02:23:46 +01:00
|
|
|
struct utxo *utxo = tal(ctx, struct utxo);
|
|
|
|
|
2017-12-18 07:41:52 +01:00
|
|
|
fromwire_bitcoin_txid(ptr, max, &utxo->txid);
|
2017-02-21 05:45:29 +01:00
|
|
|
utxo->outnum = fromwire_u32(ptr, max);
|
|
|
|
utxo->amount = fromwire_u64(ptr, max);
|
|
|
|
utxo->keyindex = fromwire_u32(ptr, max);
|
|
|
|
utxo->is_p2sh = fromwire_bool(ptr, max);
|
2018-01-02 14:54:32 +01:00
|
|
|
if (fromwire_bool(ptr, max)) {
|
2018-02-08 02:23:46 +01:00
|
|
|
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);
|
|
|
|
fromwire_pubkey(ptr, max, &utxo->close_info->peer_id);
|
|
|
|
fromwire_pubkey(ptr, max, &utxo->close_info->commitment_point);
|
|
|
|
} else {
|
|
|
|
utxo->close_info = NULL;
|
|
|
|
}
|
2018-02-08 02:23:46 +01:00
|
|
|
return utxo;
|
2017-02-21 05:45:29 +01:00
|
|
|
}
|