Skip to content

Commit

Permalink
common: remove type_to_string files altogther.
Browse files Browse the repository at this point in the history
This means including <common/utils.h> where it was indirectly included.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Mar 20, 2024
1 parent 37d22f9 commit e0e879c
Show file tree
Hide file tree
Showing 154 changed files with 44 additions and 326 deletions.
3 changes: 1 addition & 2 deletions bitcoin/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion bitcoin/locktime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions bitcoin/preimage.c
Original file line number Diff line number Diff line change
@@ -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>

Expand All @@ -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);
4 changes: 1 addition & 3 deletions bitcoin/privkey.c
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions bitcoin/pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions bitcoin/shadouble.c
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
{
Expand Down
10 changes: 0 additions & 10 deletions bitcoin/short_channel_id.c
Original file line number Diff line number Diff line change
@@ -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>

Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 1 addition & 5 deletions bitcoin/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions bitcoin/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions bitcoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion channeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion channeld/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion channeld/test/run-commit_tx.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 0 additions & 1 deletion channeld/watchtower.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 0 additions & 1 deletion cli/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion closingd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion closingd/closingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
16 changes: 1 addition & 15 deletions common/amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions common/blindedpath.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "config.h"
#include <bitcoin/tx.h>
#include <ccan/cast/cast.h>
#include <common/blindedpath.h>
#include <common/blinding.h>
Expand Down
2 changes: 0 additions & 2 deletions common/blockheight_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
1 change: 1 addition & 0 deletions common/bolt12_merkle.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
4 changes: 1 addition & 3 deletions common/channel_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
1 change: 0 additions & 1 deletion common/coin_mvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit e0e879c

Please sign in to comment.