mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
devtools/decodemsg: decode encoded_short_ids.
$ devtools/decodemsg 010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000000000000ffff0100160178da6360486760606400824c285d00a60111710144
$ devtools/decodemsg 010506226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00110000006700000100000000690000010000
Before:
WIRE_REPLY_CHANNEL_RANGE:
chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
first_blocknum=0
number_of_blocks=65535
complete=1
encoded_short_ids=[0178da6360486760606400824c285d00a60111710144]
WIRE_QUERY_SHORT_CHANNEL_IDS:
chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
encoded_short_ids=[0000006700000100000000690000010000]
After:
WIRE_REPLY_CHANNEL_RANGE:
chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
first_blocknum=0
number_of_blocks=65535
complete=1
encoded_short_ids=[ (ZLIB) 103:1:0 105:1:0 112:1:0 ]
WIRE_QUERY_SHORT_CHANNEL_IDS:
chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
encoded_short_ids=[ (UNCOMPRESSED) 103:1:0 105:1:0 ]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
9d3ce87700
commit
01c02fd617
@@ -8,6 +8,7 @@ DEVTOOLS_COMMON_OBJS := \
|
||||
common/bech32.o \
|
||||
common/bech32_util.o \
|
||||
common/bolt11.o \
|
||||
common/decode_short_channel_ids.o \
|
||||
common/hash_u5.o \
|
||||
common/type_to_string.o \
|
||||
common/utils.o \
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <ccan/err/err.h>
|
||||
#include <common/decode_short_channel_ids.h>
|
||||
#include <common/utils.h>
|
||||
#include <devtools/gen_print_wire.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <ccan/utf8/utf8.h>
|
||||
#include <common/decode_short_channel_ids.h>
|
||||
#include <common/type_to_string.h>
|
||||
#include <devtools/print_wire.h>
|
||||
#include <errno.h>
|
||||
@@ -100,6 +101,46 @@ static void printwire_addresses(const u8 **cursor, size_t *plen, size_t len)
|
||||
printf(" ]\n");
|
||||
}
|
||||
|
||||
static void printwire_encoded_short_ids(const u8 **cursor, size_t *plen, size_t len)
|
||||
{
|
||||
struct short_channel_id *scids;
|
||||
u8 *arr = tal_arr(tmpctx, u8, len);
|
||||
|
||||
fromwire_u8_array(cursor, plen, arr, len);
|
||||
if (!*cursor)
|
||||
return;
|
||||
|
||||
printf("[");
|
||||
scids = decode_short_ids(tmpctx, arr);
|
||||
if (scids) {
|
||||
switch (arr[0]) {
|
||||
case SHORTIDS_UNCOMPRESSED:
|
||||
printf(" (UNCOMPRESSED)");
|
||||
break;
|
||||
case SHORTIDS_ZLIB:
|
||||
printf(" (ZLIB)");
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
for (size_t i = 0; i < tal_count(scids); i++)
|
||||
printf(" %s",
|
||||
short_channel_id_to_str(tmpctx, &scids[i]));
|
||||
} else {
|
||||
/* If it was unknown, that's different from corrupt */
|
||||
if (len == 0
|
||||
|| arr[0] == SHORTIDS_UNCOMPRESSED
|
||||
|| arr[0] == SHORTIDS_ZLIB) {
|
||||
printf(" **CORRUPT**");
|
||||
return;
|
||||
} else {
|
||||
printf(" UNKNOWN:");
|
||||
print_hexstring(cursor, plen, len);
|
||||
}
|
||||
}
|
||||
printf(" ]\n");
|
||||
}
|
||||
|
||||
void printwire_u8_array(const char *fieldname, const u8 **cursor, size_t *plen, size_t len)
|
||||
{
|
||||
if (streq(fieldname, "node_announcement.alias")) {
|
||||
@@ -110,6 +151,10 @@ void printwire_u8_array(const char *fieldname, const u8 **cursor, size_t *plen,
|
||||
printwire_addresses(cursor, plen, len);
|
||||
return;
|
||||
}
|
||||
if (strends(fieldname, ".encoded_short_ids")) {
|
||||
printwire_encoded_short_ids(cursor, plen, len);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("[");
|
||||
if (!print_hexstring(cursor, plen, len))
|
||||
|
||||
Reference in New Issue
Block a user