common: remove type_to_string files altogther.

This means including <common/utils.h> where it was indirectly included.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-03-20 11:17:55 +10:30
parent 37d22f9141
commit e0e879c003
154 changed files with 44 additions and 326 deletions

View file

@ -5,7 +5,7 @@
#include <bitcoin/tx.h>
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h>
#include <common/type_to_string.h>
#include <common/utils.h>
/* Sets *cursor to NULL and returns NULL when a pull fails. */
static const u8 *pull(const u8 **cursor, size_t *max, void *copy, size_t n)
@ -245,7 +245,6 @@ char *fmt_bitcoin_blkid(const tal_t *ctx,
bitcoin_blkid_to_hex(blkid, hexstr, hex_str_size(sizeof(*blkid)));
return hexstr;
}
REGISTER_TYPE_TO_STRING(bitcoin_blkid, fmt_bitcoin_blkid);
void fromwire_bitcoin_blkid(const u8 **cursor, size_t *max,
struct bitcoin_blkid *blkid)

View file

@ -2,7 +2,6 @@
#include <assert.h>
#include <bitcoin/locktime.h>
#include <ccan/tal/str/str.h>
#include <common/type_to_string.h>
#define SECONDS_POINT 500000000

View file

@ -1,6 +1,5 @@
#include "config.h"
#include <bitcoin/preimage.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <wire/wire.h>
@ -18,5 +17,3 @@ char *fmt_preimage(const tal_t *ctx, const struct preimage *preimage)
{
return tal_hexstr(ctx, preimage, sizeof(*preimage));
}
REGISTER_TYPE_TO_STRING(preimage, fmt_preimage);

View file

@ -1,7 +1,7 @@
#include "config.h"
#include <bitcoin/privkey.h>
#include <ccan/str/hex/hex.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <wire/wire.h>
char *fmt_privkey(const tal_t *ctx, const struct privkey *secret)
@ -12,13 +12,11 @@ char *fmt_privkey(const tal_t *ctx, const struct privkey *secret)
strcat(str, "01");
return str;
}
REGISTER_TYPE_TO_STRING(privkey, fmt_privkey);
char *fmt_secret(const tal_t *ctx, const struct secret *secret)
{
return tal_hexstr(ctx, secret, sizeof(*secret));
}
REGISTER_TYPE_TO_STRING(secret, fmt_secret);
bool secret_eq_consttime(const struct secret *a, const struct secret *b)
{

View file

@ -8,7 +8,7 @@
#include <ccan/ccan/array_size/array_size.h>
#include <ccan/ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <wally_psbt.h>
#include <wire/wire.h>
@ -745,7 +745,6 @@ char *fmt_wally_psbt(const tal_t *ctx, const struct wally_psbt *psbt)
return serialized_psbt;
}
REGISTER_TYPE_TO_STRING(wally_psbt, fmt_wally_psbt);
const u8 *psbt_get_bytes(const tal_t *ctx, const struct wally_psbt *psbt,
size_t *bytes_written)

View file

@ -4,7 +4,7 @@
#include <bitcoin/pubkey.h>
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <wire/wire.h>
#ifndef SUPERVERBOSE
@ -69,7 +69,6 @@ char *fmt_pubkey(const tal_t *ctx, const struct pubkey *key)
pubkey_to_der(der, key);
return tal_hexstr(ctx, der, sizeof(der));
}
REGISTER_TYPE_TO_STRING(pubkey, fmt_pubkey);
char *fmt_secp256k1_pubkey(const tal_t *ctx, const secp256k1_pubkey *key)
{
@ -81,7 +80,6 @@ char *fmt_secp256k1_pubkey(const tal_t *ctx, const secp256k1_pubkey *key)
assert(outlen == sizeof(der));
return tal_hexstr(ctx, der, sizeof(der));
}
REGISTER_TYPE_TO_STRING(secp256k1_pubkey, fmt_secp256k1_pubkey);
int pubkey_cmp(const struct pubkey *a, const struct pubkey *b)
{

View file

@ -1,7 +1,7 @@
#include "config.h"
#include <bitcoin/shadouble.h>
#include <ccan/mem/mem.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <wire/wire.h>
void sha256_double(struct sha256_double *shadouble, const void *p, size_t len)
@ -20,7 +20,6 @@ char *fmt_sha256_double(const tal_t *ctx, const struct sha256_double *shad)
{
return tal_hexstr(ctx, shad, sizeof(*shad));
}
REGISTER_TYPE_TO_STRING(sha256_double, fmt_sha256_double);
void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d)
{

View file

@ -1,7 +1,6 @@
#include "config.h"
#include <bitcoin/short_channel_id.h>
#include <ccan/tal/str/str.h>
#include <common/type_to_string.h>
#include <stdio.h>
#include <wire/wire.h>
@ -87,15 +86,6 @@ char *fmt_short_channel_id_dir(const tal_t *ctx,
return str;
}
static char *fmt_short_channel_id_ptr(const tal_t *ctx,
const struct short_channel_id *scid)
{
return fmt_short_channel_id(ctx, *scid);
}
REGISTER_TYPE_TO_STRING(short_channel_id, fmt_short_channel_id_ptr);
REGISTER_TYPE_TO_STRING(short_channel_id_dir, fmt_short_channel_id_dir);
void towire_short_channel_id(u8 **pptr,
const struct short_channel_id *short_channel_id)
{

View file

@ -8,7 +8,7 @@
#include <bitcoin/signature.h>
#include <bitcoin/tx.h>
#include <ccan/mem/mem.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <secp256k1_schnorrsig.h>
#include <wire/wire.h>
@ -334,7 +334,6 @@ char *fmt_secp256k1_ecdsa_signature(const tal_t *ctx, const secp256k1_ecdsa_sign
return tal_hexstr(ctx, der, len);
}
REGISTER_TYPE_TO_STRING(secp256k1_ecdsa_signature, fmt_secp256k1_ecdsa_signature);
char *fmt_bitcoin_signature(const tal_t *ctx,
const struct bitcoin_signature *sig)
@ -344,7 +343,6 @@ char *fmt_bitcoin_signature(const tal_t *ctx,
return tal_hexstr(ctx, der, len);
}
REGISTER_TYPE_TO_STRING(bitcoin_signature, fmt_bitcoin_signature);
void fromwire_bitcoin_signature(const u8 **cursor, size_t *max,
struct bitcoin_signature *sig)
@ -378,8 +376,6 @@ char *fmt_bip340sig(const tal_t *ctx, const struct bip340sig *bip340sig)
return tal_hexstr(ctx, bip340sig->u8, sizeof(bip340sig->u8));
}
REGISTER_TYPE_TO_STRING(bip340sig, fmt_bip340sig);
/* BIP-340:
*
* This proposal suggests to include the tag by prefixing the hashed

View file

@ -6,7 +6,7 @@
#include <ccan/cast/cast.h>
#include <ccan/str/hex/hex.h>
#include <ccan/tal/str/str.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <wally_psbt.h>
#include <wire/wire.h>
@ -754,10 +754,15 @@ char *fmt_wally_tx(const tal_t *ctx, const struct wally_tx *tx)
return s;
}
REGISTER_TYPE_TO_STRING(bitcoin_tx, fmt_bitcoin_tx);
REGISTER_TYPE_TO_STRING(bitcoin_txid, fmt_bitcoin_txid);
REGISTER_TYPE_TO_STRING(bitcoin_outpoint, fmt_bitcoin_outpoint);
REGISTER_TYPE_TO_STRING(wally_tx, fmt_wally_tx);
char *fmt_sha256(const tal_t *ctx, const struct sha256 *sha256)
{
return tal_hexstr(ctx, sha256, sizeof(*sha256));
}
char *fmt_ripemd160(const tal_t *ctx, const struct ripemd160 *ripemd160)
{
return tal_hexstr(ctx, ripemd160, sizeof(*ripemd160));
}
void fromwire_bitcoin_txid(const u8 **cursor, size_t *max,
struct bitcoin_txid *txid)

View file

@ -14,7 +14,9 @@
/* BIP 125: Any nsequence < 0xFFFFFFFE is replacable.
* And bitcoind uses this value. */
#define BITCOIN_TX_RBF_SEQUENCE 0xFFFFFFFD
struct wally_psbt;
struct ripemd160;
struct bitcoin_txid {
struct sha256_double shad;
@ -290,6 +292,9 @@ char *fmt_bitcoin_outpoint(const tal_t *ctx,
const struct bitcoin_outpoint *outpoint);
char *fmt_wally_tx(const tal_t *ctx, const struct wally_tx *tx);
/* For want of somewhere better to define them! */
char *fmt_sha256(const tal_t *ctx, const struct sha256 *sha256);
char *fmt_ripemd160(const tal_t *ctx, const struct ripemd160 *ripemd160);
/* Various weights of transaction parts. */
size_t bitcoin_tx_core_weight(size_t num_inputs, size_t num_outputs);

View file

@ -90,7 +90,6 @@ CHANNELD_COMMON_OBJS := \
common/status_wire.o \
common/subdaemon.o \
common/timeout.o \
common/type_to_string.o \
common/utils.o \
common/utxo.o \
common/version.o \

View file

@ -42,7 +42,6 @@
#include <common/status.h>
#include <common/subdaemon.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <errno.h>
#include <fcntl.h>

View file

@ -13,7 +13,6 @@
#include <common/keyset.h>
#include <common/memleak.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <stdio.h>
/* Needs to be at end, since it doesn't include its own hdrs */
#include "full_channel_error_names_gen.h"

View file

@ -22,7 +22,6 @@ CHANNELD_TEST_COMMON_OBJS := \
common/permute_tx.o \
common/pseudorand.o \
common/setup.o \
common/type_to_string.o \
common/utils.o
$(CHANNELD_TEST_PROGRAMS): $(BITCOIN_OBJS) $(WIRE_OBJS) $(CHANNELD_TEST_COMMON_OBJS)

View file

@ -1,7 +1,8 @@
#include "config.h"
#include <inttypes.h>
#include <stdio.h>
#include <common/type_to_string.h>
#include <stdbool.h>
static bool print_superverbose;
#define SUPERVERBOSE(...) \
do { if (print_superverbose) printf(__VA_ARGS__); } while(0)

View file

@ -8,7 +8,6 @@
#include <common/keyset.h>
#include <common/psbt_keypath.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <hsmd/hsmd_wiregen.h>
#include <wire/wire_sync.h>

View file

@ -20,7 +20,6 @@ CLI_TEST_COMMON_OBJS := \
common/setup.o \
common/utils.o \
common/version.o \
common/type_to_string.o \
common/permute_tx.o
$(CLI_TEST_PROGRAMS): libccan.a $(BITCOIN_OBJS) $(WIRE_OBJS) $(CLI_TEST_COMMON_OBJS)

View file

@ -53,7 +53,6 @@ CLOSINGD_COMMON_OBJS := \
common/status.o \
common/status_wire.o \
common/subdaemon.o \
common/type_to_string.o \
common/utils.o \
common/utxo.o \
common/version.o \

View file

@ -16,7 +16,6 @@
#include <common/read_peer_msg.h>
#include <common/status.h>
#include <common/subdaemon.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <common/version.h>
#include <common/wire_error.h>

View file

@ -94,7 +94,6 @@ COMMON_SRC_NOGEN := \
common/timeout.c \
common/trace.c \
common/tx_roles.c \
common/type_to_string.c \
common/utils.c \
common/utxo.c \
common/version.c \

View file

@ -5,7 +5,7 @@
#include <ccan/tal/str/str.h>
#include <common/amount.h>
#include <common/overflows.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <inttypes.h>
#include <wire/wire.h>
@ -64,13 +64,6 @@ char *fmt_amount_msat(const tal_t *ctx, struct amount_msat msat)
return tal_fmt(ctx, "%"PRIu64"msat", msat.millisatoshis);
}
static const char *fmt_amount_msat_ptr(const tal_t *ctx,
const struct amount_msat *msat)
{
return fmt_amount_msat(ctx, *msat);
}
REGISTER_TYPE_TO_STRING(amount_msat, fmt_amount_msat_ptr);
const char *fmt_amount_sat_btc(const tal_t *ctx,
struct amount_sat sat,
bool append_unit)
@ -89,13 +82,6 @@ char *fmt_amount_sat(const tal_t *ctx, struct amount_sat sat)
return tal_fmt(ctx, "%"PRIu64"sat", sat.satoshis);
}
static const char *fmt_amount_sat_ptr(const tal_t *ctx,
const struct amount_sat *sat)
{
return fmt_amount_sat(ctx, *sat);
}
REGISTER_TYPE_TO_STRING(amount_sat, fmt_amount_sat_ptr);
static bool breakup(const char *str, size_t slen,
/* Length of first numeric part. */
size_t *whole_number_len,

View file

@ -1,4 +1,5 @@
#include "config.h"
#include <bitcoin/tx.h>
#include <ccan/cast/cast.h>
#include <common/blindedpath.h>
#include <common/blinding.h>

View file

@ -4,7 +4,6 @@
#include <ccan/tal/str/str.h>
#include <common/blockheight_states.h>
#include <common/fee_states.h>
#include <common/type_to_string.h>
#include <wire/wire.h>
struct height_states *new_height_states(const tal_t *ctx,
@ -160,4 +159,3 @@ char *fmt_height_states(const tal_t *ctx,
tal_append_fmt(&ret, " }");
return ret;
}
REGISTER_TYPE_TO_STRING(height_states, fmt_height_states);

View file

@ -1,5 +1,6 @@
#include "config.h"
#include <assert.h>
#include <bitcoin/tx.h>
#include <ccan/cast/cast.h>
#include <ccan/ilog/ilog.h>
#include <ccan/mem/mem.h>

View file

@ -3,7 +3,7 @@
#include <bitcoin/tx.h>
#include <common/channel_id.h>
#include <common/pseudorand.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <wire/wire.h>
void derive_channel_id(struct channel_id *channel_id,
@ -98,5 +98,3 @@ char *fmt_channel_id(const tal_t *ctx, const struct channel_id *channel_id)
{
return tal_hexstr(ctx, channel_id, sizeof(*channel_id));
}
REGISTER_TYPE_TO_STRING(channel_id, fmt_channel_id);

View file

@ -5,7 +5,6 @@
#include <ccan/tal/str/str.h>
#include <common/coin_mvt.h>
#include <common/node_id.h>
#include <common/type_to_string.h>
#include <wire/wire.h>
#define EXTERNAL "external"

View file

@ -3,7 +3,6 @@
#include <ccan/cast/cast.h>
#include <ccan/tal/str/str.h>
#include <common/fee_states.h>
#include <common/type_to_string.h>
#include <wire/wire.h>
/* If we're the finder, it's like an HTLC we added, if they are, it's like
@ -170,4 +169,3 @@ char *fmt_fee_states(const tal_t *ctx,
tal_append_fmt(&ret, " }");
return ret;
}
REGISTER_TYPE_TO_STRING(fee_states, fmt_fee_states);

View file

@ -9,7 +9,6 @@
#include <common/gossip_store.h>
#include <common/gossmap.h>
#include <common/pseudorand.h>
#include <common/type_to_string.h>
#include <errno.h>
#include <fcntl.h>
#include <gossipd/gossip_store_wiregen.h>

View file

@ -8,7 +8,6 @@
#include <common/initial_channel.h>
#include <common/initial_commit_tx.h>
#include <common/keyset.h>
#include <common/type_to_string.h>
struct channel *new_initial_channel(const tal_t *ctx,
const struct channel_id *cid,
@ -247,5 +246,3 @@ char *fmt_channel(const tal_t *ctx, const struct channel *channel)
fmt_channel_view(ctx, &channel->view[LOCAL]),
fmt_channel_view(ctx, &channel->view[REMOTE]));
}
/* Magic comment. */
REGISTER_TYPE_TO_STRING(channel, fmt_channel);

View file

@ -5,7 +5,6 @@
#include <common/keyset.h>
#include <common/permute_tx.h>
#include <common/status.h>
#include <common/type_to_string.h>
/* BOLT #3:
*

View file

@ -21,7 +21,6 @@
#include <common/setup.h>
#include <common/status.h>
#include <common/subdaemon.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
/*

View file

@ -20,7 +20,6 @@
#include <common/json_parse.h>
#include <common/json_stream.h>
#include <common/node_id.h>
#include <common/type_to_string.h>
#include <common/wireaddr.h>
#include <inttypes.h>
#include <stdio.h>

View file

@ -5,7 +5,7 @@
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h>
#include <common/node_id.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <wire/wire.h>
/* Convert from pubkey to compressed pubkey. */
@ -38,7 +38,6 @@ char *fmt_node_id(const tal_t *ctx, const struct node_id *id)
{
return tal_hexstr(ctx, id->k, sizeof(id->k));
}
REGISTER_TYPE_TO_STRING(node_id, fmt_node_id);
/* Convert from hex string of SEC1 encoding */
bool node_id_from_hexstr(const char *str, size_t slen, struct node_id *id)

View file

@ -6,7 +6,6 @@
#include <common/onion_message_parse.h>
#include <common/sphinx.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <wire/onion_wire.h>
#include <wire/peer_wire.h>

View file

@ -31,7 +31,6 @@ common/test/run-json: \
common/lease_rates.o \
common/node_id.o \
common/pseudorand.o \
common/type_to_string.o \
common/wireaddr.o \
wire/fromwire.o \
wire/onion_wiregen.o \
@ -74,7 +73,6 @@ common/test/run-bolt12_merkle: \
common/bech32_util.o \
common/bolt12.o \
common/node_id.o \
common/type_to_string.o \
common/wireaddr.o \
wire/bolt12_wiregen.o \
wire/fromwire.o \

View file

@ -2,7 +2,6 @@
#include "../bigsize.c"
#include "../blinding.c"
#include "../hmac.c"
#include "../type_to_string.c"
#include <common/channel_id.h>
#include <common/setup.h>
#include <stdio.h>

View file

@ -7,7 +7,6 @@
#include "../onion_decode.c"
#include "../onion_encode.c"
#include "../sphinx.c"
#include "../type_to_string.c"
#include <common/setup.h>
#include <wire/peer_wire.h>
#include <stdio.h>

View file

@ -1,7 +1,6 @@
#define SUPERVERBOSE printf
#include "config.h"
/* Needed before including bolt12_merkle.c: */
#include <common/type_to_string.h>
#include <stdio.h>
#include "../bolt12_merkle.c"
#include <assert.h>

View file

@ -1,7 +1,6 @@
#include "config.h"
#include "../fp16.c"
#include <common/setup.h>
#include <common/type_to_string.h>
#include <stdio.h>
#include <wire/wire.h>

View file

@ -1,12 +1,12 @@
#define SUPERVERBOSE
#include "config.h"
#include <assert.h>
#include <ccan/str/hex/hex.h>
#include <common/amount.h>
#include <common/setup.h>
#include <stdio.h>
#include <wire/wire.h>
#include "../type_to_string.c"
#include "../key_derive.c"
/* AUTOGENERATED MOCKS START */

View file

@ -15,7 +15,6 @@ static void maybe_print(const char *fmt, ...);
#include "../onion_encode.c"
#include "../onion_message_parse.c"
#include "../sphinx.c"
#include "../type_to_string.c"
#include "../../wire/onion_wiregen.c"
#include "../../wire/peer_wiregen.c"
#include <common/ecdh.h>

View file

@ -5,7 +5,6 @@
#include "../onion_decode.c"
#include "../sphinx.c"
#include "../hmac.c"
#include "../type_to_string.c"
#include "../../wire/towire.c"
#include "../../wire/fromwire.c"
#include "../../wire/onion_wiregen.c"

View file

@ -9,7 +9,6 @@
#include <common/gossip_store.h>
#include <common/route.h>
#include <common/setup.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <math.h>
#include <stdio.h>

View file

@ -13,7 +13,6 @@
#include <common/gossip_store.h>
#include <common/route.h>
#include <common/setup.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <bitcoin/chainparams.h>
#include <stdio.h>

View file

@ -6,7 +6,6 @@
#include <common/gossip_store.h>
#include <common/route.h>
#include <common/setup.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <bitcoin/chainparams.h>
#include <stdio.h>

View file

@ -13,7 +13,6 @@
#include "../json_parse_simple.c"
#include "../onion_encode.c"
#include "../sphinx.c"
#include "../type_to_string.c"
#include "../../wire/onion_wiregen.c"
#include <ccan/tal/grab_file/grab_file.h>
#include <ccan/tal/path/path.h>

View file

@ -7,7 +7,6 @@
#include "../hmac.c"
#include "../json_parse.c"
#include "../json_parse_simple.c"
#include "../type_to_string.c"
#include <ccan/tal/grab_file/grab_file.h>
#include <ccan/tal/path/path.h>
#include <common/channel_id.h>

View file

@ -1,49 +0,0 @@
#include "config.h"
#include <assert.h>
#include <bitcoin/preimage.h>
#include <ccan/tal/str/str.h>
#include <common/type_to_string.h>
char *fmt_sha256(const tal_t *ctx, const struct sha256 *sha256)
{
return tal_hexstr(ctx, sha256, sizeof(*sha256));
}
char *fmt_ripemd160(const tal_t *ctx, const struct ripemd160 *ripemd160)
{
return tal_hexstr(ctx, ripemd160, sizeof(*ripemd160));
}
/* We need at least one, and these are in CCAN so register it here. */
REGISTER_TYPE_TO_STRING(sha256, fmt_sha256);
REGISTER_TYPE_TO_STRING(ripemd160, fmt_ripemd160);
const char *type_to_string_(const tal_t *ctx, const char *typename,
union printable_types u)
{
const char *s = NULL;
size_t i;
static size_t num_p;
static struct type_to_string **t = NULL;
assert(typename != NULL);
if (!t)
t = autodata_get(type_to_string, &num_p);
/* Typenames in registrations don't include "struct " */
if (strstarts(typename, "struct "))
typename += strlen("struct ");
for (i = 0; i < num_p; i++) {
if (streq(t[i]->typename, typename)) {
s = t[i]->fmt(ctx, u);
break;
}
}
/* **BROKEN** makes CI upset, which is what we want! */
if (!s)
s = tal_fmt(ctx, "**BROKEN** UNKNOWN TYPE %s", typename);
return s;
}

View file

@ -1,70 +0,0 @@
#ifndef LIGHTNING_COMMON_TYPE_TO_STRING_H
#define LIGHTNING_COMMON_TYPE_TO_STRING_H
#include "config.h"
#include <common/autodata.h>
#include <common/utils.h>
/* This must match the type_to_string_ cases. */
union printable_types {
const struct pubkey *pubkey;
const struct node_id *node_id;
const struct bitcoin_txid *bitcoin_txid;
const struct bitcoin_blkid *bitcoin_blkid;
const struct bitcoin_outpoint *bitcoin_outpoint;
const struct sha256 *sha256;
const struct sha256_double *sha256_double;
const struct ripemd160 *ripemd160;
const struct bitcoin_tx *bitcoin_tx;
const struct htlc *htlc;
const struct preimage *preimage;
const struct channel_oneside *channel_oneside;
const struct wireaddr *wireaddr;
const struct wireaddr_internal *wireaddr_internal;
const secp256k1_pubkey *secp256k1_pubkey;
const struct channel_id *channel_id;
const struct short_channel_id *short_channel_id;
const struct short_channel_id_dir *short_channel_id_dir;
const struct secret *secret;
const struct privkey *privkey;
const secp256k1_ecdsa_signature *secp256k1_ecdsa_signature;
const struct bitcoin_signature *bitcoin_signature;
const struct bip340sig *bip340sig;
const struct channel *channel;
const struct amount_msat *amount_msat;
const struct amount_sat *amount_sat;
const struct fee_states *fee_states;
const struct height_states *height_states;
const char *charp_;
const struct wally_psbt *wally_psbt;
const struct wally_tx *wally_tx;
};
#define type_to_string(ctx, type, ptr) \
type_to_string_((ctx), stringify(type), \
((void)sizeof((ptr) == (type *)NULL), \
((union printable_types)((const type *)ptr))))
const char *type_to_string_(const tal_t *ctx, const char *typename,
union printable_types u);
#define REGISTER_TYPE_TO_STRING(typename, fmtfn) \
static const char *fmt_##typename##_(const tal_t *ctx, \
union printable_types u) \
{ \
return fmtfn(ctx, u.typename); \
} \
static struct type_to_string ttos_##typename = { \
#typename, fmt_##typename##_ \
}; \
AUTODATA(type_to_string, &ttos_##typename)
struct type_to_string {
const char *typename;
const char *(*fmt)(const tal_t *ctx, union printable_types u);
};
AUTODATA_TYPE(type_to_string, struct type_to_string);
char *fmt_sha256(const tal_t *ctx, const struct sha256 *sha256);
char *fmt_ripemd160(const tal_t *ctx, const struct ripemd160 *ripemd160);
#endif /* LIGHTNING_COMMON_TYPE_TO_STRING_H */

View file

@ -1,7 +1,6 @@
#include "config.h"
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <wire/peer_wire.h>

View file

@ -5,7 +5,7 @@
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <common/base32.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <common/wireaddr.h>
#include <netdb.h>
#include <netinet/in.h>
@ -243,7 +243,6 @@ char *fmt_wireaddr_internal(const tal_t *ctx,
}
abort();
}
REGISTER_TYPE_TO_STRING(wireaddr_internal, fmt_wireaddr_internal);
char *fmt_wireaddr_without_port(const tal_t * ctx, const struct wireaddr *a)
{
@ -279,7 +278,6 @@ char *fmt_wireaddr(const tal_t *ctx, const struct wireaddr *a)
tal_append_fmt(&ret, ":%u", a->port);
return ret;
}
REGISTER_TYPE_TO_STRING(wireaddr, fmt_wireaddr);
/* Valid forms:
*

View file

@ -74,7 +74,6 @@ CONNECTD_COMMON_OBJS := \
common/status_wire.o \
common/subdaemon.o \
common/timeout.o \
common/type_to_string.o \
common/utils.o \
common/utxo.o \
common/version.o \

View file

@ -28,7 +28,6 @@
#include <common/status.h>
#include <common/subdaemon.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <connectd/connectd.h>
#include <connectd/connectd_gossipd_wiregen.h>

View file

@ -8,7 +8,6 @@
#include <common/crypto_state.h>
#include <common/ecdh.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <common/wireaddr.h>
#include <connectd/handshake.h>

View file

@ -15,7 +15,6 @@
#include <common/ping.h>
#include <common/status.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <common/wire_error.h>
#include <connectd/connectd.h>

View file

@ -9,7 +9,6 @@
#include <common/onion_message_parse.h>
#include <common/sphinx.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <connectd/connectd.h>
#include <connectd/connectd_wiregen.h>

View file

@ -9,7 +9,6 @@ CONNECTD_TEST_COMMON_OBJS := \
common/features.o \
common/pseudorand.o \
common/setup.o \
common/type_to_string.o \
common/utils.o
ALL_C_SOURCES += $(CONNECTD_TEST_SRC)

View file

@ -38,7 +38,6 @@ DEVTOOLS_COMMON_OBJS := \
common/psbt_open.o \
common/pseudorand.o \
common/setup.o \
common/type_to_string.o \
common/utils.o \
common/version.o \
common/wireaddr.o \

View file

@ -11,7 +11,6 @@
#include <common/bolt11.h>
#include <common/features.h>
#include <common/setup.h>
#include <common/type_to_string.h>
#include <common/version.h>
#include <inttypes.h>
#include <stdio.h>

View file

@ -1,5 +1,6 @@
#include "config.h"
#include <bitcoin/chainparams.h>
#include <bitcoin/tx.h>
#include <ccan/array_size/array_size.h>
#include <ccan/err/err.h>
#include <ccan/opt/opt.h>
@ -10,7 +11,6 @@
#include <common/features.h>
#include <common/iso4217.h>
#include <common/setup.h>
#include <common/type_to_string.h>
#include <common/version.h>
#include <inttypes.h>
#include <secp256k1_schnorrsig.h>

View file

@ -3,7 +3,6 @@
#include <ccan/err/err.h>
#include <ccan/opt/opt.h>
#include <common/gossip_store.h>
#include <common/type_to_string.h>
#include <fcntl.h>
#include <gossipd/gossip_store_wiregen.h>
#include <stdio.h>

View file

@ -4,7 +4,6 @@
#include <ccan/opt/opt.h>
#include <common/fp16.h>
#include <common/setup.h>
#include <common/type_to_string.h>
#include <inttypes.h>
#include <stdio.h>

View file

@ -11,7 +11,6 @@
#include <common/htlc_wire.h>
#include <common/initial_commit_tx.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <stdio.h>
static bool verbose = false;

View file

@ -23,7 +23,6 @@
#include <common/htlc_wire.h>
#include <common/key_derive.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <common/version.h>
#include <inttypes.h>
#include <stdio.h>

View file

@ -14,7 +14,6 @@
#include <common/initial_commit_tx.h>
#include <common/setup.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <common/utxo.h>
#include <stdio.h>

View file

@ -13,7 +13,6 @@
#include <ccan/opt/opt.h>
#include <ccan/str/hex/hex.h>
#include <ccan/tal/str/str.h>
#include <common/type_to_string.h>
#include <inttypes.h>
#include <stdio.h>
#include <wire/peer_wire.h>

View file

@ -2,7 +2,6 @@
#include <ccan/mem/mem.h>
#include <ccan/utf8/utf8.h>
#include <common/decode_array.h>
#include <common/type_to_string.h>
#include <devtools/print_wire.h>
#include <errno.h>
#include <stdio.h>

View file

@ -6,7 +6,6 @@
#include <common/gossmap.h>
#include <common/route.h>
#include <common/setup.h>
#include <common/type_to_string.h>
#include <devtools/clean_topo.h>
#include <inttypes.h>
#include <stdio.h>

View file

@ -6,7 +6,6 @@
#include <common/dijkstra.h>
#include <common/gossmap.h>
#include <common/route.h>
#include <common/type_to_string.h>
#include <devtools/clean_topo.h>
#include <inttypes.h>
#include <stdio.h>

View file

@ -104,8 +104,7 @@ Everything should be declared static and const by default. Note that `tal_free(
## Typesafety Is Worth Some Pain
If code is typesafe, refactoring is as simple as changing a type and compiling to find where to refactor. We rely on this, so most places in the code will break if you hand the wrong type, eg
`type_to_string` and `structeq`.
If code is typesafe, refactoring is as simple as changing a type and compiling to find where to refactor. We rely on this, so most places in the code will break if you hand the wrong type, eg `structeq` and `tal`.
The two tools we have to help us are complicated macros in `ccan/typesafe_cb` allow you to create callbacks which must match the type of their argument, rather than using `void *`. The other is `ARRAY_SIZE`, a macro which won't compile if you hand it a pointer instead of an actual array.
@ -170,4 +169,4 @@ In case you think the pull request is small enough not to require a changelog en
Under some circumstances a feature may be removed even without deprecation warning if it was not part of a released version yet, or the removal is urgent.
In order to ensure that each pull request has the required `Changelog-*:` line for the changelog our trusty @bitcoin-bot will check logs whenever a pull request is created or updated and search for the required line. If there is no such line it'll mark the pull request as `pending` to call out the need for an entry.
In order to ensure that each pull request has the required `Changelog-*:` line for the changelog our trusty @bitcoin-bot will check logs whenever a pull request is created or updated and search for the required line. If there is no such line it'll mark the pull request as `pending` to call out the need for an entry.

View file

@ -63,7 +63,6 @@ GOSSIPD_COMMON_OBJS := \
common/status_wire.o \
common/subdaemon.o \
common/timeout.o \
common/type_to_string.o \
common/utils.o \
common/utxo.o \
common/version.o \

View file

@ -21,7 +21,6 @@
#include <common/status.h>
#include <common/subdaemon.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <common/wireaddr.h>
#include <connectd/connectd_gossipd_wiregen.h>

View file

@ -8,7 +8,6 @@
#include <common/gossmap.h>
#include <common/status.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <errno.h>
#include <fcntl.h>

View file

@ -8,7 +8,6 @@
#include <common/decode_array.h>
#include <common/gossmap.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <gossipd/gossip_store.h>
#include <gossipd/gossipd.h>

View file

@ -2,7 +2,7 @@
#include <bitcoin/shadouble.h>
#include <bitcoin/signature.h>
#include <ccan/tal/str/str.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <common/wire_error.h>
#include <gossipd/sigcheck.h>

View file

@ -20,7 +20,6 @@ GOSSIPD_TEST_COMMON_OBJS := \
common/lease_rates.o \
common/pseudorand.o \
common/setup.o \
common/type_to_string.o \
common/utils.o \
common/wireaddr.o \
gossipd/gossip_store_wiregen.o \

View file

@ -48,7 +48,6 @@ HSMD_COMMON_OBJS := \
common/status_wire.o \
common/status_wiregen.o \
common/subdaemon.o \
common/type_to_string.o \
common/utils.o \
common/utxo.o \
common/version.o \

View file

@ -19,7 +19,6 @@
#include <common/status.h>
#include <common/status_wiregen.h>
#include <common/subdaemon.h>
#include <common/type_to_string.h>
#include <errno.h>
#include <fcntl.h>
/*~ _wiregen files are autogenerated by tools/generate-wire.py */

View file

@ -7,7 +7,6 @@
#include <common/hash_u5.h>
#include <common/key_derive.h>
#include <common/lease_rates.h>
#include <common/type_to_string.h>
#include <hsmd/libhsmd.h>
#include <hsmd/permissions.h>
#include <inttypes.h>

View file

@ -142,7 +142,6 @@ LIGHTNINGD_COMMON_OBJS := \
common/timeout.o \
common/trace.o \
common/tx_roles.o \
common/type_to_string.o \
common/utils.o \
common/utxo.o \
common/version.o \

View file

@ -7,7 +7,6 @@
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <channeld/channeld_wiregen.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <hsmd/hsmd_wiregen.h>
#include <inttypes.h>

View file

@ -12,7 +12,6 @@
#include <common/memleak.h>
#include <common/timeout.h>
#include <common/trace.h>
#include <common/type_to_string.h>
#include <db/exec.h>
#include <lightningd/bitcoind.h>
#include <lightningd/chaintopology.h>

View file

@ -4,7 +4,6 @@
#include <common/closing_fee.h>
#include <common/fee_states.h>
#include <common/json_command.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <connectd/connectd_wiregen.h>
#include <errno.h>

View file

@ -8,7 +8,6 @@
#include <common/json_stream.h>
#include <common/memleak.h>
#include <common/shutdown_scriptpubkey.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <connectd/connectd_wiregen.h>
#include <errno.h>

View file

@ -2,7 +2,6 @@
#include <ccan/mem/mem.h>
#include <common/memleak.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <connectd/connectd_wiregen.h>
#include <hsmd/hsmd_wiregen.h>

View file

@ -15,7 +15,6 @@
#include <common/json_param.h>
#include <common/shutdown_scriptpubkey.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <connectd/connectd_wiregen.h>
#include <errno.h>

View file

@ -1,6 +1,5 @@
#include "config.h"
#include <ccan/array_size/array_size.h>
#include <common/type_to_string.h>
#include <lightningd/channel.h>
#include <lightningd/coin_mvts.h>
#include <lightningd/notification.h>

View file

@ -7,7 +7,6 @@
#include <common/json_param.h>
#include <common/memleak.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <connectd/connectd_wiregen.h>
#include <gossipd/gossipd_wiregen.h>
#include <hsmd/permissions.h>

View file

@ -14,7 +14,6 @@
#include <common/json_param.h>
#include <common/psbt_open.h>
#include <common/shutdown_scriptpubkey.h>
#include <common/type_to_string.h>
#include <common/wire_error.h>
#include <connectd/connectd_wiregen.h>
#include <errno.h>

View file

@ -9,7 +9,6 @@
#include <common/json_stream.h>
#include <common/node_id.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <connectd/connectd_wiregen.h>
#include <gossipd/gossipd_wiregen.h>
#include <hsmd/hsmd_wiregen.h>

View file

@ -10,7 +10,6 @@
#include <common/json_command.h>
#include <common/json_param.h>
#include <common/jsonrpc_errors.h>
#include <common/type_to_string.h>
#include <errno.h>
#include <hsmd/hsmd_wiregen.h>
#include <lightningd/hsm_control.h>

View file

@ -4,7 +4,6 @@
#include <ccan/tal/str/str.h>
#include <common/htlc.h>
#include <common/pseudorand.h>
#include <common/type_to_string.h>
#include <lightningd/htlc_end.h>
#include <lightningd/log.h>

View file

@ -1,7 +1,6 @@
#include "config.h"
#include <common/features.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <lightningd/channel.h>
#include <lightningd/htlc_set.h>
#include <lightningd/invoice.h>

View file

@ -16,7 +16,6 @@
#include <common/overflows.h>
#include <common/random_select.h>
#include <common/timeout.h>
#include <common/type_to_string.h>
#include <db/exec.h>
#include <errno.h>
#include <hsmd/hsmd_wiregen.h>

View file

@ -56,7 +56,6 @@
#include <common/memleak.h>
#include <common/timeout.h>
#include <common/trace.h>
#include <common/type_to_string.h>
#include <common/version.h>
#include <db/exec.h>
@ -1355,12 +1354,13 @@ int main(int argc, char *argv[])
/*~ Mark ourselves live.
*
* Note the use of type_to_string() here: it's a typesafe formatter,
* often handed 'tmpctx' like here to allocate a throwaway string for
* formatting. json_escape() avoids printing weird characters in our
* log. And tal_hex() is a helper from utils which returns a hex string;
* it's assumed that the argument was allocated with tal or tal_arr
* so it can use tal_bytelen() to get the length. */
* Note the use of fmt_node_id() here: most complex types have a
* string formatter of this convention, usually handed 'tmpctx' like
* here to allocate a throwaway string for formatting. json_escape()
* avoids printing weird characters in our log. And tal_hex() is a
* helper from utils which returns a hex string; it's assumed that the
* argument was allocated with tal or tal_arr so it can use
* tal_bytelen() to get the length. */
log_info(ld->log, "--------------------------------------------------");
log_info(ld->log, "Server started with public key %s, alias %s (color #%s) and lightningd %s",
fmt_node_id(tmpctx, &ld->id),

View file

@ -1,7 +1,6 @@
#include "config.h"
#include <ccan/cast/cast.h>
#include <common/configdir.h>
#include <common/type_to_string.h>
#include <lightningd/channel.h>
#include <lightningd/coin_mvts.h>
#include <lightningd/notification.h>

View file

@ -7,7 +7,6 @@
#include <common/json_command.h>
#include <common/json_param.h>
#include <common/json_stream.h>
#include <common/type_to_string.h>
#include <errno.h>
#include <hsmd/hsmd_wiregen.h>
#include <lightningd/hsm_control.h>

View file

@ -6,7 +6,6 @@
#include <common/htlc_tx.h>
#include <common/key_derive.h>
#include <common/psbt_keypath.h>
#include <common/type_to_string.h>
#include <db/exec.h>
#include <errno.h>
#include <hsmd/hsmd_wiregen.h>

View file

@ -4,7 +4,6 @@
#include <common/configdir.h>
#include <common/json_command.h>
#include <common/json_param.h>
#include <common/type_to_string.h>
#include <connectd/connectd_wiregen.h>
#include <lightningd/channel.h>
#include <lightningd/onion_message.h>

Some files were not shown because too many files have changed in this diff Show more