mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-20 13:54:36 +01:00
wire: use common/bigsize routines
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
2241e25cb4
commit
cc70b9c4ec
20 changed files with 83 additions and 43 deletions
|
@ -20,6 +20,12 @@ static bool print_superverbose;
|
|||
/*#define DEBUG */
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_put */
|
||||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
||||
/* Generated stub for status_fmt */
|
||||
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
|
||||
|
||||
|
|
|
@ -14,6 +14,12 @@
|
|||
#include <wally_core.h>
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_put */
|
||||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
||||
/* Generated stub for status_failed */
|
||||
void status_failed(enum status_failreason code UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "config.h"
|
||||
#include <assert.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/bigsize.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -26,6 +27,12 @@ int test_printf(const char *format, ...);
|
|||
#undef main
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_put */
|
||||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
||||
/* Generated stub for version_and_exit */
|
||||
char *version_and_exit(const void *unused UNNEEDED)
|
||||
{ fprintf(stderr, "version_and_exit called!\n"); abort(); }
|
||||
|
|
|
@ -44,6 +44,7 @@ $(LIGHTNINGD_CLOSING_OBJS): $(LIGHTNINGD_HEADERS)
|
|||
CLOSINGD_COMMON_OBJS := \
|
||||
common/amount.o \
|
||||
common/base32.o \
|
||||
common/bigsize.o \
|
||||
common/bip32.o \
|
||||
common/close_tx.o \
|
||||
common/crypto_state.o \
|
||||
|
|
|
@ -41,6 +41,7 @@ CONNECTD_COMMON_OBJS := \
|
|||
common/base32.o \
|
||||
common/bech32.o \
|
||||
common/bech32_util.o \
|
||||
common/bigsize.o \
|
||||
common/bip32.o \
|
||||
common/crypto_state.o \
|
||||
common/cryptomsg.o \
|
||||
|
|
|
@ -40,6 +40,7 @@ GOSSIPD_COMMON_OBJS := \
|
|||
common/base32.o \
|
||||
common/bech32.o \
|
||||
common/bech32_util.o \
|
||||
common/bigsize.o \
|
||||
common/bip32.o \
|
||||
common/crypto_state.o \
|
||||
common/cryptomsg.o \
|
||||
|
|
|
@ -14,6 +14,7 @@ LIGHTNINGD_HSM_OBJS := $(LIGHTNINGD_HSM_SRC:.c=.o)
|
|||
# Common source we use.
|
||||
HSMD_COMMON_OBJS := \
|
||||
common/amount.o \
|
||||
common/bigsize.o \
|
||||
common/bip32.o \
|
||||
common/daemon.o \
|
||||
common/daemon_conn.o \
|
||||
|
|
|
@ -18,6 +18,12 @@ char *add_plugin_dir(struct plugins *plugins UNNEEDED, const char *dir UNNEEDED,
|
|||
/* Generated stub for begin_topology */
|
||||
void begin_topology(struct chain_topology *topo UNNEEDED)
|
||||
{ fprintf(stderr, "begin_topology called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_put */
|
||||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
||||
/* Generated stub for channel_notify_new_block */
|
||||
void channel_notify_new_block(struct lightningd *ld UNNEEDED,
|
||||
u32 block_height UNNEEDED)
|
||||
|
|
|
@ -6,6 +6,12 @@
|
|||
bool deprecated_apis = false;
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_put */
|
||||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
||||
/* Generated stub for bitcoind_gettxout */
|
||||
void bitcoind_gettxout(struct bitcoind *bitcoind UNNEEDED,
|
||||
const struct bitcoin_txid *txid UNNEEDED, const u32 outnum UNNEEDED,
|
||||
|
|
|
@ -3,6 +3,12 @@
|
|||
#include "../json.c"
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_put */
|
||||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
||||
/* Generated stub for db_begin_transaction_ */
|
||||
void db_begin_transaction_(struct db *db UNNEEDED, const char *location UNNEEDED)
|
||||
{ fprintf(stderr, "db_begin_transaction_ called!\n"); abort(); }
|
||||
|
|
|
@ -48,6 +48,7 @@ $(LIGHTNINGD_ONCHAIN_OBJS): $(LIGHTNINGD_HEADERS)
|
|||
# Common source we use.
|
||||
ONCHAIND_COMMON_OBJS := \
|
||||
common/amount.o \
|
||||
common/bigsize.o \
|
||||
common/bip32.o \
|
||||
common/daemon.o \
|
||||
common/daemon_conn.o \
|
||||
|
|
|
@ -37,6 +37,7 @@ LIGHTNINGD_HEADERS_NOGEN += $(LIGHTNINGD_OPENING_HEADERS_NOGEN)
|
|||
OPENINGD_COMMON_OBJS := \
|
||||
common/amount.o \
|
||||
common/base32.o \
|
||||
common/bigsize.o \
|
||||
common/bip32.o \
|
||||
common/channel_config.o \
|
||||
common/crypto_state.o \
|
||||
|
|
|
@ -21,6 +21,7 @@ PLUGIN_COMMON_OBJS := \
|
|||
common/amount.o \
|
||||
common/bech32.o \
|
||||
common/bech32_util.o \
|
||||
common/bigsize.o \
|
||||
common/bolt11.o \
|
||||
common/daemon.o \
|
||||
common/hash_u5.o \
|
||||
|
|
|
@ -18,6 +18,12 @@ static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, bool ca
|
|||
#include <unistd.h>
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_put */
|
||||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
static char *db_err;
|
||||
|
|
|
@ -35,6 +35,12 @@ const struct chainparams *get_chainparams(const struct lightningd *ld)
|
|||
}
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_put */
|
||||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
||||
/* Generated stub for bitcoind_gettxout */
|
||||
void bitcoind_gettxout(struct bitcoind *bitcoind UNNEEDED,
|
||||
const struct bitcoin_txid *txid UNNEEDED, const u32 outnum UNNEEDED,
|
||||
|
|
|
@ -163,37 +163,18 @@ bool fromwire_bool(const u8 **cursor, size_t *max)
|
|||
return ret;
|
||||
}
|
||||
|
||||
u64 fromwire_bigsize(const u8 **cursor, size_t *max)
|
||||
bigsize_t fromwire_bigsize(const u8 **cursor, size_t *max)
|
||||
{
|
||||
u8 flag = fromwire_u8(cursor, max);
|
||||
u64 ret;
|
||||
bigsize_t v;
|
||||
size_t len = bigsize_get(*cursor, *max, &v);
|
||||
|
||||
switch(flag) {
|
||||
case 0xff:
|
||||
ret = fromwire_u64(cursor, max);
|
||||
if ((ret >> 32) == 0) {
|
||||
SUPERVERBOSE("not minimal encoded");
|
||||
fromwire_fail(cursor, max);
|
||||
}
|
||||
break;
|
||||
case 0xfe:
|
||||
ret = fromwire_u32(cursor, max);
|
||||
if ((ret >> 16) == 0) {
|
||||
SUPERVERBOSE("not minimal encoded");
|
||||
fromwire_fail(cursor, max);
|
||||
}
|
||||
break;
|
||||
case 0xfd:
|
||||
ret = fromwire_u16(cursor, max);
|
||||
if (ret < 0xfd) {
|
||||
SUPERVERBOSE("not minimal encoded");
|
||||
fromwire_fail(cursor, max);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = flag;
|
||||
if (len == 0) {
|
||||
fromwire_fail(cursor, max);
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
assert(len <= *max);
|
||||
fromwire(cursor, max, NULL, len);
|
||||
return v;
|
||||
}
|
||||
|
||||
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)
|
||||
|
|
|
@ -12,6 +12,12 @@
|
|||
secp256k1_context *secp256k1_ctx;
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for bigsize_get */
|
||||
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
||||
/* Generated stub for bigsize_put */
|
||||
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
||||
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
/* memsetting pubkeys doesn't work */
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <common/utils.h>
|
||||
#include <stdio.h>
|
||||
#include <wally_core.h>
|
||||
|
||||
#include <common/bigsize.c>
|
||||
|
||||
static const char *reason;
|
||||
#undef SUPERVERBOSE
|
||||
#define SUPERVERBOSE(r) do { reason = (r); } while(0)
|
||||
|
||||
#include <wire/tlvstream.c>
|
||||
|
|
|
@ -87,20 +87,13 @@ void towire_bool(u8 **pptr, bool v)
|
|||
towire(pptr, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void towire_bigsize(u8 **pptr, const u64 val)
|
||||
void towire_bigsize(u8 **pptr, const bigsize_t val)
|
||||
{
|
||||
if (val < 0xfd) {
|
||||
towire_u8(pptr, val);
|
||||
} else if (val <= 0xffff) {
|
||||
towire_u8(pptr, 0xfd);
|
||||
towire_u16(pptr, val);
|
||||
} else if (val <= 0xffffffff) {
|
||||
towire_u8(pptr, 0xfe);
|
||||
towire_u32(pptr, val);
|
||||
} else {
|
||||
towire_u8(pptr, 0xff);
|
||||
towire_u64(pptr, val);
|
||||
}
|
||||
u8 buf[BIGSIZE_MAX_LEN];
|
||||
size_t len;
|
||||
|
||||
len = bigsize_put(buf, val);
|
||||
towire(pptr, buf, len);
|
||||
}
|
||||
|
||||
void towire_pubkey(u8 **pptr, const struct pubkey *pubkey)
|
||||
|
|
|
@ -79,7 +79,7 @@ void towire_tu64(u8 **pptr, u64 v);
|
|||
void towire_double(u8 **pptr, const double *v);
|
||||
void towire_pad(u8 **pptr, size_t num);
|
||||
void towire_bool(u8 **pptr, bool v);
|
||||
void towire_bigsize(u8 **pptr, const u64 val);
|
||||
void towire_bigsize(u8 **pptr, const bigsize_t val);
|
||||
|
||||
void towire_u8_array(u8 **pptr, const u8 *arr, size_t num);
|
||||
|
||||
|
@ -99,7 +99,7 @@ u32 fromwire_tu32(const u8 **cursor, size_t *max);
|
|||
u64 fromwire_tu64(const u8 **cursor, size_t *max);
|
||||
void fromwire_double(const u8 **cursor, size_t *max, double *v);
|
||||
bool fromwire_bool(const u8 **cursor, size_t *max);
|
||||
u64 fromwire_bigsize(const u8 **cursor, size_t *max);
|
||||
bigsize_t fromwire_bigsize(const u8 **cursor, size_t *max);
|
||||
void fromwire_secret(const u8 **cursor, size_t *max, struct secret *secret);
|
||||
void fromwire_privkey(const u8 **cursor, size_t *max, struct privkey *privkey);
|
||||
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey);
|
||||
|
|
Loading…
Add table
Reference in a new issue