mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
526d3a232e
These are now logically arrays of pointers. This is much more natural, and gets rid of the horrible utxo array converters. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
#include <common/utxo.h>
|
|
#include <wire/wire.h>
|
|
|
|
void towire_utxo(u8 **pptr, const struct utxo *utxo)
|
|
{
|
|
/* Is this a unilateral close output and needs the
|
|
* close_info? */
|
|
bool is_unilateral_close = utxo->close_info != NULL;
|
|
towire_bitcoin_txid(pptr, &utxo->txid);
|
|
towire_u32(pptr, utxo->outnum);
|
|
towire_u64(pptr, utxo->amount);
|
|
towire_u32(pptr, utxo->keyindex);
|
|
towire_bool(pptr, utxo->is_p2sh);
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
|
|
{
|
|
struct utxo *utxo = tal(ctx, struct utxo);
|
|
|
|
fromwire_bitcoin_txid(ptr, max, &utxo->txid);
|
|
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);
|
|
if (fromwire_bool(ptr, max)) {
|
|
utxo->close_info = tal(utxo, struct unilateral_close_info);
|
|
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;
|
|
}
|
|
return utxo;
|
|
}
|