Skip to content

Commit

Permalink
wire: generate printwire_ routines for bolt12 CSV.
Browse files Browse the repository at this point in the history
Good exercise, and we need it when bolt12 messages appear in onion
messages anyway.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Mar 25, 2022
1 parent d15d629 commit 2b42227
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions devtools/print_wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static bool print_hexstring(const u8 **cursor, size_t *plen, size_t len)
return true;
}

static bool printwire_alias(const u8 **cursor, size_t *plen, size_t len)
bool printwire_utf8_array(const char *fieldname, const u8 **cursor, size_t *plen, size_t len)
{
struct utf8_state utf8 = UTF8_STATE_INIT;
const char *p = (const char *)*cursor;
Expand Down Expand Up @@ -217,7 +217,7 @@ static bool printwire_encoded_short_ids(const u8 **cursor, size_t *plen, size_t
bool printwire_u8_array(const char *fieldname, const u8 **cursor, size_t *plen, size_t len)
{
if (streq(fieldname, "node_announcement.alias"))
return printwire_alias(cursor, plen, len);
return printwire_utf8_array(fieldname, cursor, plen, len);

if (streq(fieldname, "node_announcement.addresses"))
return printwire_addresses(cursor, plen, len);
Expand Down Expand Up @@ -316,10 +316,12 @@ bool printwire_tlvs(const char *fieldname, const u8 **cursor, size_t *plen,
#define PRINTWIRE_STRUCT_TYPE_TO_STRING(T) \
PRINTWIRE_TYPE_TO_STRING(struct T, T)

PRINTWIRE_STRUCT_TYPE_TO_STRING(bip340sig)
PRINTWIRE_STRUCT_TYPE_TO_STRING(bitcoin_blkid)
PRINTWIRE_STRUCT_TYPE_TO_STRING(bitcoin_txid)
PRINTWIRE_STRUCT_TYPE_TO_STRING(channel_id)
PRINTWIRE_STRUCT_TYPE_TO_STRING(node_id)
PRINTWIRE_STRUCT_TYPE_TO_STRING(point32)
PRINTWIRE_STRUCT_TYPE_TO_STRING(preimage)
PRINTWIRE_STRUCT_TYPE_TO_STRING(pubkey)
PRINTWIRE_STRUCT_TYPE_TO_STRING(sha256)
Expand Down
3 changes: 3 additions & 0 deletions devtools/print_wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ bool printwire_tu16(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_tu32(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_tu64(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_u8_array(const char *fieldname, const u8 **cursor, size_t *plen, size_t len);
bool printwire_utf8_array(const char *fieldname, const u8 **cursor, size_t *plen, size_t len);
bool printwire_tlvs(const char *tlv_name, const u8 **cursor, size_t *plen,
const struct tlv_print_record_type types[], size_t num_types);

bool printwire_bip340sig(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_bitcoin_blkid(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_wireaddr(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_bitcoin_txid(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_channel_id(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_amount_sat(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_amount_msat(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_point32(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_preimage(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_pubkey(const char *fieldname, const u8 **cursor, size_t *plen);
bool printwire_node_id(const char *fieldname, const u8 **cursor, size_t *plen);
Expand Down
8 changes: 8 additions & 0 deletions wire/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ WIRE_HEADERS := wire/onion_defs.h \
wire/onion$(EXP)_wiregen.h \
wire/bolt12$(EXP)_wiregen.h \
wire/channel_type_wiregen.h \
wire/bolt12$(EXP)_printgen.h \
wire/peer$(EXP)_printgen.h \
wire/onion$(EXP)_printgen.h

Expand All @@ -29,6 +30,7 @@ WIRE_SRC := wire/wire_sync.c \
WIRE_PRINT_SRC := \
wire/onion$(EXP)_printgen.c \
wire/peer$(EXP)_printgen.c \
wire/bolt12$(EXP)_printgen.c \
wire/channel_type_printgen.c

WIRE_OBJS := $(WIRE_SRC:.c=.o)
Expand Down Expand Up @@ -135,9 +137,15 @@ wire/onion_exp_wiregen.c_args := $(wire/onion_wiregen.c_args)

wire/bolt12_wiregen.c_args := -s --expose-tlv-type=tlv_blinded_path --expose-tlv-type=tlv_invoice_request
wire/bolt12_wiregen.h_args := --include='bitcoin/short_channel_id.h' --include='bitcoin/signature.h' --include='bitcoin/privkey.h' --include='common/bigsize.h' --include='common/amount.h' --include='common/node_id.h' --include='bitcoin/block.h' --include='wire/onion_wire.h' $(wire/bolt12_wiregen.c_args)

wire/bolt12_printgen.c_args := --expose-tlv-type=tlv_blinded_path --expose-tlv-type=tlv_invoice_request --include='wire/onion$(EXP)_wiregen.h' --include='wire/onion$(EXP)_printgen.h'
wire/bolt12_printgen.h_args := --include='wire/bolt12$(EXP)_wiregen.h' --expose-tlv-type=tlv_blinded_path --expose-tlv-type=tlv_invoice_request

# Same for _exp versions
wire/bolt12_exp_wiregen.h_args := $(wire/bolt12_wiregen.h_args)
wire/bolt12_exp_wiregen.c_args := $(wire/bolt12_wiregen.c_args)
wire/bolt12_exp_printgen.h_args := $(wire/bolt12_printgen.h_args)
wire/bolt12_exp_printgen.c_args := $(wire/bolt12_printgen.c_args)

wire/peer_wiregen.h_args := --include='common/channel_id.h' --include='bitcoin/tx.h' --include='bitcoin/preimage.h' --include='bitcoin/short_channel_id.h' --include='common/node_id.h' --include='common/bigsize.h' --include='bitcoin/block.h' --include='bitcoin/privkey.h' -s --expose-tlv-type=tlv_n1 --expose-tlv-type=tlv_n2

Expand Down

0 comments on commit 2b42227

Please sign in to comment.