From fddb38126d023a742627f8ac52fdb668a0492e19 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 21 Feb 2017 15:15:29 +1030 Subject: [PATCH] utxo: wire support for unspent transactions. Signed-off-by: Rusty Russell --- lightningd/Makefile | 3 ++- lightningd/utxo.c | 37 +++++++++++++++++++++++++++++++++++++ lightningd/utxo.h | 24 ++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 lightningd/utxo.c create mode 100644 lightningd/utxo.h diff --git a/lightningd/Makefile b/lightningd/Makefile index 41e0077d1..1bbe7b086 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -39,7 +39,8 @@ LIGHTNINGD_LIB_SRC := \ lightningd/cryptomsg.c \ lightningd/funding_tx.c \ lightningd/htlc_tx.c \ - lightningd/key_derive.c + lightningd/key_derive.c \ + lightningd/utxo.c LIGHTNINGD_LIB_OBJS := $(LIGHTNINGD_LIB_SRC:.c=.o) LIGHTNINGD_LIB_HEADERS := $(LIGHTNINGD_LIB_SRC:.c=.h) diff --git a/lightningd/utxo.c b/lightningd/utxo.c new file mode 100644 index 000000000..4091eff65 --- /dev/null +++ b/lightningd/utxo.c @@ -0,0 +1,37 @@ +#include +#include + +void towire_utxo(u8 **pptr, const struct utxo *utxo) +{ + towire_sha256_double(pptr, &utxo->txid); + towire_u32(pptr, utxo->outnum); + towire_u64(pptr, utxo->amount); + towire_u32(pptr, utxo->keyindex); + towire_bool(pptr, utxo->is_p2sh); +} + +void fromwire_utxo(const u8 **ptr, size_t *max, struct utxo *utxo) +{ + fromwire_sha256_double(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); +} + +void fromwire_utxo_array(const u8 **ptr, size_t *max, + struct utxo *utxo, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + fromwire_utxo(ptr, max, &utxo[i]); +} + +void towire_utxo_array(u8 **pptr, const struct utxo *utxo, size_t num) +{ + size_t i; + + for (i = 0; i < num; i++) + towire_utxo(pptr, &utxo[i]); +} diff --git a/lightningd/utxo.h b/lightningd/utxo.h new file mode 100644 index 000000000..a2eb5ca7d --- /dev/null +++ b/lightningd/utxo.h @@ -0,0 +1,24 @@ +#ifndef LIGHTNING_LIGHTNINGD_UTXO_H +#define LIGHTNING_LIGHTNINGD_UTXO_H +#include "config.h" +#include +#include +#include +#include + +struct utxo { + struct sha256_double txid; + u32 outnum; + u64 amount; + u32 keyindex; + bool is_p2sh; +}; + +void towire_utxo(u8 **pptr, const struct utxo *utxo); +void fromwire_utxo(const u8 **ptr, size_t *max, struct utxo *utxo); + +void fromwire_utxo_array(const u8 **ptr, size_t *max, + struct utxo *utxo, size_t num); + +void towire_utxo_array(u8 **pptr, const struct utxo *utxo, size_t num); +#endif /* LIGHTNING_LIGHTNINGD_UTXO_H */