diff --git a/bitcoin/block.c b/bitcoin/block.c index 956011dc0..2d64a5759 100644 --- a/bitcoin/block.c +++ b/bitcoin/block.c @@ -237,8 +237,8 @@ static bool bitcoin_blkid_to_hex(const struct bitcoin_blkid *blockid, return bitcoin_txid_to_hex(&fake_txid, hexstr, hexstr_len); } -static char *fmt_bitcoin_blkid(const tal_t *ctx, - const struct bitcoin_blkid *blkid) +char *fmt_bitcoin_blkid(const tal_t *ctx, + const struct bitcoin_blkid *blkid) { char *hexstr = tal_arr(ctx, char, hex_str_size(sizeof(*blkid))); diff --git a/bitcoin/block.h b/bitcoin/block.h index 546a7371f..a2631b732 100644 --- a/bitcoin/block.h +++ b/bitcoin/block.h @@ -53,4 +53,7 @@ void fromwire_chainparams(const u8 **cursor, size_t *max, const struct chainparams **chainparams); void towire_chainparams(u8 **cursor, const struct chainparams *chainparams); +char *fmt_bitcoin_blkid(const tal_t *ctx, + const struct bitcoin_blkid *blkid); + #endif /* LIGHTNING_BITCOIN_BLOCK_H */ diff --git a/bitcoin/preimage.c b/bitcoin/preimage.c index 8fcafa01d..837b70298 100644 --- a/bitcoin/preimage.c +++ b/bitcoin/preimage.c @@ -1,5 +1,7 @@ #include "config.h" #include +#include +#include #include void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage) @@ -12,4 +14,9 @@ void towire_preimage(u8 **pptr, const struct preimage *preimage) towire(pptr, preimage, sizeof(*preimage)); } +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); diff --git a/bitcoin/preimage.h b/bitcoin/preimage.h index d47ee48ec..dfe8e4d94 100644 --- a/bitcoin/preimage.h +++ b/bitcoin/preimage.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include struct preimage { u8 r[32]; @@ -13,4 +14,5 @@ STRUCTEQ_DEF(preimage, 0, r); void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage); void towire_preimage(u8 **pptr, const struct preimage *preimage); +char *fmt_preimage(const tal_t *ctx, const struct preimage *preimage); #endif /* LIGHTNING_BITCOIN_PREIMAGE_H */ diff --git a/bitcoin/privkey.c b/bitcoin/privkey.c index 646d655a9..ace556c10 100644 --- a/bitcoin/privkey.c +++ b/bitcoin/privkey.c @@ -4,7 +4,7 @@ #include #include -static char *privkey_to_hexstr(const tal_t *ctx, const struct privkey *secret) +char *fmt_privkey(const tal_t *ctx, const struct privkey *secret) { /* Bitcoin appends "01" to indicate the pubkey is compressed. */ char *str = tal_arr(ctx, char, hex_str_size(sizeof(*secret) + 1)); @@ -12,8 +12,13 @@ static char *privkey_to_hexstr(const tal_t *ctx, const struct privkey *secret) strcat(str, "01"); return str; } -REGISTER_TYPE_TO_STRING(privkey, privkey_to_hexstr); -REGISTER_TYPE_TO_HEXSTR(secret); +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) { diff --git a/bitcoin/privkey.h b/bitcoin/privkey.h index 9bebf602d..d592d4685 100644 --- a/bitcoin/privkey.h +++ b/bitcoin/privkey.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include #define PRIVKEY_LEN 32 @@ -25,4 +26,7 @@ void fromwire_privkey(const u8 **cursor, size_t *max, struct privkey *privkey); void towire_privkey(u8 **pptr, const struct privkey *privkey); void towire_secret(u8 **pptr, const struct secret *secret); +char *fmt_privkey(const tal_t *ctx, const struct privkey *privkey); +char *fmt_secret(const tal_t *ctx, const struct secret *secret); + #endif /* LIGHTNING_BITCOIN_PRIVKEY_H */ diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index 4d010508c..51b2f332c 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -733,7 +733,7 @@ struct wally_psbt *psbt_from_b64(const tal_t *ctx, return psbt; } -char *psbt_to_b64(const tal_t *ctx, const struct wally_psbt *psbt) +char *fmt_wally_psbt(const tal_t *ctx, const struct wally_psbt *psbt) { char *serialized_psbt; int ret; @@ -745,7 +745,7 @@ char *psbt_to_b64(const tal_t *ctx, const struct wally_psbt *psbt) return serialized_psbt; } -REGISTER_TYPE_TO_STRING(wally_psbt, psbt_to_b64); +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) diff --git a/bitcoin/psbt.h b/bitcoin/psbt.h index 4c693c8a3..31abd2d42 100644 --- a/bitcoin/psbt.h +++ b/bitcoin/psbt.h @@ -293,7 +293,7 @@ bool elements_psbt_output_is_fee(const struct wally_psbt *psbt, size_t outnum); struct wally_psbt *psbt_from_b64(const tal_t *ctx, const char *b64, size_t b64len); -char *psbt_to_b64(const tal_t *ctx, const struct wally_psbt *psbt); +char *fmt_wally_psbt(const tal_t *ctx, const struct wally_psbt *psbt); const u8 *psbt_get_bytes(const tal_t *ctx, const struct wally_psbt *psbt, size_t *bytes_written); bool validate_psbt(const struct wally_psbt *psbt); diff --git a/bitcoin/pubkey.c b/bitcoin/pubkey.c index b97379838..9e0492a96 100644 --- a/bitcoin/pubkey.c +++ b/bitcoin/pubkey.c @@ -62,16 +62,16 @@ bool pubkey_from_hexstr(const char *derstr, size_t slen, struct pubkey *key) return pubkey_from_der(der, dlen, key); } -char *pubkey_to_hexstr(const tal_t *ctx, const struct pubkey *key) +char *fmt_pubkey(const tal_t *ctx, const struct pubkey *key) { unsigned char der[PUBKEY_CMPR_LEN]; pubkey_to_der(der, key); return tal_hexstr(ctx, der, sizeof(der)); } -REGISTER_TYPE_TO_STRING(pubkey, pubkey_to_hexstr); +REGISTER_TYPE_TO_STRING(pubkey, fmt_pubkey); -static char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey *key) +char *fmt_secp256k1_pubkey(const tal_t *ctx, const secp256k1_pubkey *key) { unsigned char der[PUBKEY_CMPR_LEN]; size_t outlen = sizeof(der); @@ -81,7 +81,7 @@ static char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey assert(outlen == sizeof(der)); return tal_hexstr(ctx, der, sizeof(der)); } -REGISTER_TYPE_TO_STRING(secp256k1_pubkey, secp256k1_pubkey_to_hexstr); +REGISTER_TYPE_TO_STRING(secp256k1_pubkey, fmt_secp256k1_pubkey); int pubkey_cmp(const struct pubkey *a, const struct pubkey *b) { diff --git a/bitcoin/pubkey.h b/bitcoin/pubkey.h index f3231a8ba..601281f36 100644 --- a/bitcoin/pubkey.h +++ b/bitcoin/pubkey.h @@ -23,7 +23,8 @@ STRUCTEQ_DEF(pubkey, 0, pubkey.data); bool pubkey_from_hexstr(const char *derstr, size_t derlen, struct pubkey *key); /* Convert from hex string of DER (scriptPubKey from validateaddress) */ -char *pubkey_to_hexstr(const tal_t *ctx, const struct pubkey *key); +char *fmt_pubkey(const tal_t *ctx, const struct pubkey *key); +char *fmt_secp256k1_pubkey(const tal_t *ctx, const secp256k1_pubkey *key); /* Point from secret */ bool pubkey_from_secret(const struct secret *secret, struct pubkey *key); diff --git a/bitcoin/shadouble.c b/bitcoin/shadouble.c index fb7299804..bccab4b68 100644 --- a/bitcoin/shadouble.c +++ b/bitcoin/shadouble.c @@ -15,7 +15,12 @@ void sha256_double_done(struct sha256_ctx *shactx, struct sha256_double *res) sha256_done(shactx, &res->sha); sha256(&res->sha, &res->sha, sizeof(res->sha)); } -REGISTER_TYPE_TO_HEXSTR(sha256_double); + +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) { diff --git a/bitcoin/shadouble.h b/bitcoin/shadouble.h index c87e37ed1..17f5c3697 100644 --- a/bitcoin/shadouble.h +++ b/bitcoin/shadouble.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include /* To explicitly distinguish between single sha and bitcoin's standard double */ struct sha256_double { @@ -17,4 +18,6 @@ void sha256_double_done(struct sha256_ctx *sha256, struct sha256_double *res); void fromwire_sha256_double(const u8 **cursor, size_t *max, struct sha256_double *sha256d); void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d); + +char *fmt_sha256_double(const tal_t *ctx, const struct sha256_double *shad); #endif /* LIGHTNING_BITCOIN_SHADOUBLE_H */ diff --git a/bitcoin/short_channel_id.c b/bitcoin/short_channel_id.c index d6c341cea..e981263d2 100644 --- a/bitcoin/short_channel_id.c +++ b/bitcoin/short_channel_id.c @@ -53,12 +53,12 @@ bool short_channel_id_from_str(const char *str, size_t strlen, && mk_short_channel_id(dst, blocknum, txnum, outnum); } -char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid) +char *fmt_short_channel_id(const tal_t *ctx, struct short_channel_id scid) { return tal_fmt(ctx, "%dx%dx%d", - short_channel_id_blocknum(scid), - short_channel_id_txnum(scid), - short_channel_id_outnum(scid)); + short_channel_id_blocknum(&scid), + short_channel_id_txnum(&scid), + short_channel_id_outnum(&scid)); } bool short_channel_id_dir_from_str(const char *str, size_t strlen, @@ -78,17 +78,23 @@ bool short_channel_id_dir_from_str(const char *str, size_t strlen, return true; } -static char *short_channel_id_dir_to_str(const tal_t *ctx, - const struct short_channel_id_dir *scidd) +char *fmt_short_channel_id_dir(const tal_t *ctx, + const struct short_channel_id_dir *scidd) { - char *str, *scidstr = short_channel_id_to_str(NULL, &scidd->scid); + char *str, *scidstr = fmt_short_channel_id(NULL, scidd->scid); str = tal_fmt(ctx, "%s/%u", scidstr, scidd->dir); tal_free(scidstr); return str; } -REGISTER_TYPE_TO_STRING(short_channel_id, short_channel_id_to_str); -REGISTER_TYPE_TO_STRING(short_channel_id_dir, short_channel_id_dir_to_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) diff --git a/bitcoin/short_channel_id.h b/bitcoin/short_channel_id.h index 4465da462..d863ee369 100644 --- a/bitcoin/short_channel_id.h +++ b/bitcoin/short_channel_id.h @@ -71,11 +71,13 @@ bool WARN_UNUSED_RESULT mk_short_channel_id(struct short_channel_id *scid, bool WARN_UNUSED_RESULT short_channel_id_from_str(const char *str, size_t strlen, struct short_channel_id *dst); -char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid); - bool WARN_UNUSED_RESULT short_channel_id_dir_from_str(const char *str, size_t strlen, struct short_channel_id_dir *scidd); +char *fmt_short_channel_id(const tal_t *ctx, struct short_channel_id scid); +char *fmt_short_channel_id_dir(const tal_t *ctx, + const struct short_channel_id_dir *scidd); + /* Marshal/unmarshal */ void towire_short_channel_id(u8 **pptr, const struct short_channel_id *short_channel_id); diff --git a/bitcoin/signature.c b/bitcoin/signature.c index 20b2d4c34..b7495912d 100644 --- a/bitcoin/signature.c +++ b/bitcoin/signature.c @@ -324,7 +324,7 @@ bool signature_from_der(const u8 *der, size_t len, struct bitcoin_signature *sig return true; } -char *fmt_signature(const tal_t *ctx, const secp256k1_ecdsa_signature *sig) +char *fmt_secp256k1_ecdsa_signature(const tal_t *ctx, const secp256k1_ecdsa_signature *sig) { u8 der[72]; size_t len = 72; @@ -334,17 +334,17 @@ char *fmt_signature(const tal_t *ctx, const secp256k1_ecdsa_signature *sig) return tal_hexstr(ctx, der, len); } -REGISTER_TYPE_TO_STRING(secp256k1_ecdsa_signature, fmt_signature); +REGISTER_TYPE_TO_STRING(secp256k1_ecdsa_signature, fmt_secp256k1_ecdsa_signature); -static char *bitcoin_signature_to_hexstr(const tal_t *ctx, - const struct bitcoin_signature *sig) +char *fmt_bitcoin_signature(const tal_t *ctx, + const struct bitcoin_signature *sig) { u8 der[73]; size_t len = signature_to_der(der, sig); return tal_hexstr(ctx, der, len); } -REGISTER_TYPE_TO_STRING(bitcoin_signature, bitcoin_signature_to_hexstr); +REGISTER_TYPE_TO_STRING(bitcoin_signature, fmt_bitcoin_signature); void fromwire_bitcoin_signature(const u8 **cursor, size_t *max, struct bitcoin_signature *sig) @@ -378,7 +378,7 @@ char *fmt_bip340sig(const tal_t *ctx, const struct bip340sig *bip340sig) return tal_hexstr(ctx, bip340sig->u8, sizeof(bip340sig->u8)); } -REGISTER_TYPE_TO_HEXSTR(bip340sig); +REGISTER_TYPE_TO_STRING(bip340sig, fmt_bip340sig); /* BIP-340: * diff --git a/bitcoin/signature.h b/bitcoin/signature.h index 22efa5315..0cc0c7f92 100644 --- a/bitcoin/signature.h +++ b/bitcoin/signature.h @@ -150,8 +150,11 @@ void fromwire_bip340sig(const u8 **cursor, size_t *max, struct bip340sig *bip340sig); /* Get a hex string sig */ -char *fmt_signature(const tal_t *ctx, const secp256k1_ecdsa_signature *sig); +char *fmt_secp256k1_ecdsa_signature(const tal_t *ctx, + const secp256k1_ecdsa_signature *sig); char *fmt_bip340sig(const tal_t *ctx, const struct bip340sig *bip340sig); +char *fmt_bitcoin_signature(const tal_t *ctx, + const struct bitcoin_signature *sig); /* For caller convenience, we hand in tag in parts (any can be "") */ void bip340_sighash_init(struct sha256_ctx *sctx, diff --git a/bitcoin/tx.c b/bitcoin/tx.c index a416a4546..ba7dab9ca 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -738,15 +738,15 @@ char *fmt_bitcoin_txid(const tal_t *ctx, const struct bitcoin_txid *txid) return hexstr; } -static char *fmt_bitcoin_outpoint(const tal_t *ctx, - const struct bitcoin_outpoint *outpoint) +char *fmt_bitcoin_outpoint(const tal_t *ctx, + const struct bitcoin_outpoint *outpoint) { return tal_fmt(ctx, "%s:%u", fmt_bitcoin_txid(tmpctx, &outpoint->txid), outpoint->n); } -static char *fmt_wally_tx(const tal_t *ctx, const struct wally_tx *tx) +char *fmt_wally_tx(const tal_t *ctx, const struct wally_tx *tx) { u8 *lin = linearize_wtx(ctx, tx); char *s = tal_hex(ctx, lin); diff --git a/bitcoin/tx.h b/bitcoin/tx.h index 21797cee5..84b8d588c 100644 --- a/bitcoin/tx.h +++ b/bitcoin/tx.h @@ -286,6 +286,10 @@ void fromwire_bitcoin_outpoint(const u8 **cursor, size_t *max, struct bitcoin_outpoint *outp); char *fmt_bitcoin_tx(const tal_t *ctx, const struct bitcoin_tx *tx); char *fmt_bitcoin_txid(const tal_t *ctx, const struct bitcoin_txid *txid); +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); + /* Various weights of transaction parts. */ size_t bitcoin_tx_core_weight(size_t num_inputs, size_t num_outputs); diff --git a/channeld/channeld.c b/channeld/channeld.c index a1a12e104..fb38b7586 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -3684,7 +3684,8 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg) psbt_finalize(ictx->current_psbt); - status_debug("Splice accepter adding inflight: %s", psbt_to_b64(tmpctx, ictx->current_psbt)); + status_debug("Splice accepter adding inflight: %s", + fmt_wally_psbt(tmpctx, ictx->current_psbt)); msg = towire_channeld_add_inflight(NULL, &outpoint.txid, @@ -3928,7 +3929,7 @@ static void splice_initiator_user_finalized(struct peer *peer) psbt_elements_normalize_fees(ictx->current_psbt); status_debug("Splice adding inflight: %s", - psbt_to_b64(tmpctx, ictx->current_psbt)); + fmt_wally_psbt(tmpctx, ictx->current_psbt)); psbt_txid(tmpctx, ictx->current_psbt, ¤t_psbt_txid, NULL); diff --git a/common/amount.c b/common/amount.c index 176f912ea..9d2dd3b76 100644 --- a/common/amount.c +++ b/common/amount.c @@ -59,7 +59,7 @@ const char *fmt_amount_msat_btc(const tal_t *ctx, append_unit ? "btc" : ""); } -const char *fmt_amount_msat(const tal_t *ctx, struct amount_msat msat) +char *fmt_amount_msat(const tal_t *ctx, struct amount_msat msat) { return tal_fmt(ctx, "%"PRIu64"msat", msat.millisatoshis); } @@ -84,7 +84,7 @@ const char *fmt_amount_sat_btc(const tal_t *ctx, append_unit ? "btc" : ""); } -const char *fmt_amount_sat(const tal_t *ctx, struct amount_sat sat) +char *fmt_amount_sat(const tal_t *ctx, struct amount_sat sat) { return tal_fmt(ctx, "%"PRIu64"sat", sat.satoshis); } diff --git a/common/amount.h b/common/amount.h index 8c0b31583..5c3d70e04 100644 --- a/common/amount.h +++ b/common/amount.h @@ -187,14 +187,14 @@ const char *fmt_amount_msat_btc(const tal_t *ctx, struct amount_msat msat, bool append_unit); /* => 1234msat */ -const char *fmt_amount_msat(const tal_t *ctx, struct amount_msat msat); +char *fmt_amount_msat(const tal_t *ctx, struct amount_msat msat); /* => 1.23456789btc (8 decimals!) */ const char *fmt_amount_sat_btc(const tal_t *ctx, struct amount_sat sat, bool append_unit); /* => 1234sat */ -const char *fmt_amount_sat(const tal_t *ctx, struct amount_sat sat); +char *fmt_amount_sat(const tal_t *ctx, struct amount_sat sat); /* Valid strings: * [0-9]+ => millisatoshi. diff --git a/common/blockheight_states.c b/common/blockheight_states.c index d60602334..f6187d226 100644 --- a/common/blockheight_states.c +++ b/common/blockheight_states.c @@ -147,8 +147,8 @@ struct height_states *fromwire_height_states(const tal_t *ctx, const u8 **cursor return states; } -static const char *fmt_height_states(const tal_t *ctx, - const struct height_states *states) +char *fmt_height_states(const tal_t *ctx, + const struct height_states *states) { char *ret = tal_strdup(ctx, "{"); for (enum htlc_state i = 0; i < ARRAY_SIZE(states->height); i++) { diff --git a/common/blockheight_states.h b/common/blockheight_states.h index 715517533..2cb786990 100644 --- a/common/blockheight_states.h +++ b/common/blockheight_states.h @@ -72,6 +72,9 @@ void towire_height_states(u8 **pptr, const struct height_states *height_states); struct height_states *fromwire_height_states(const tal_t *ctx, const u8 **cursor, size_t *max); +char *fmt_height_states(const tal_t *ctx, + const struct height_states *states); + /** * is this height_state struct valid for this side? */ diff --git a/common/bolt11.c b/common/bolt11.c index 5a5d5e3cb..53c692454 100644 --- a/common/bolt11.c +++ b/common/bolt11.c @@ -323,7 +323,7 @@ static const char *decode_n(struct bolt11 *b11, if (!pubkey_from_node_id(&k, &b11->receiver_id)) return tal_fmt( b11, "invalid public key %s", - node_id_to_hexstr(tmpctx, &b11->receiver_id)); + fmt_node_id(tmpctx, &b11->receiver_id)); } return err; diff --git a/common/bolt11_json.c b/common/bolt11_json.c index 1ae5e9f2a..8b5ad674c 100644 --- a/common/bolt11_json.c +++ b/common/bolt11_json.c @@ -119,5 +119,6 @@ void json_add_bolt11(struct json_stream *response, json_add_sha256(response, "payment_hash", &b11->payment_hash); - json_add_string(response, "signature", fmt_signature(tmpctx, &b11->sig)); + json_add_string(response, "signature", + fmt_secp256k1_ecdsa_signature(tmpctx, &b11->sig)); } diff --git a/common/channel_id.c b/common/channel_id.c index c2f4ce6e0..317a04fe2 100644 --- a/common/channel_id.c +++ b/common/channel_id.c @@ -94,4 +94,9 @@ bool fromwire_channel_id(const u8 **cursor, size_t *max, return fromwire(cursor, max, channel_id, sizeof(*channel_id)) != NULL; } -REGISTER_TYPE_TO_HEXSTR(channel_id); +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); diff --git a/common/channel_id.h b/common/channel_id.h index d6ce8687a..1e1b3c4d5 100644 --- a/common/channel_id.h +++ b/common/channel_id.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include struct bitcoin_outpoint; struct pubkey; @@ -36,6 +37,8 @@ void derive_channel_id_v2(struct channel_id *channel_id, void derive_tmp_channel_id(struct channel_id *channel_id, const struct pubkey *opener_basepoint); +char *fmt_channel_id(const tal_t *ctx, const struct channel_id *channel_id); + /* Marshalling/unmarshalling functions */ void towire_channel_id(u8 **pptr, const struct channel_id *channel_id); bool fromwire_channel_id(const u8 **cursor, size_t *max, diff --git a/common/fee_states.c b/common/fee_states.c index adf6845d4..87940f118 100644 --- a/common/fee_states.c +++ b/common/fee_states.c @@ -157,8 +157,8 @@ bool fee_states_valid(const struct fee_states *fee_states, enum side opener) return fee_states->feerate[last_fee_state(opener)] != NULL; } -static const char *fmt_fee_states(const tal_t *ctx, - const struct fee_states *fee_states) +char *fmt_fee_states(const tal_t *ctx, + const struct fee_states *fee_states) { char *ret = tal_strdup(ctx, "{"); for (enum htlc_state i = 0; i < ARRAY_SIZE(fee_states->feerate); i++) { diff --git a/common/fee_states.h b/common/fee_states.h index cf846002b..676512915 100644 --- a/common/fee_states.h +++ b/common/fee_states.h @@ -90,4 +90,7 @@ bool fee_states_valid(const struct fee_states *fee_states, enum side opener); bool feerate_changes_done(const struct fee_states *fee_states, bool ignore_uncommitted); +char *fmt_fee_states(const tal_t *ctx, + const struct fee_states *fee_states); + #endif /* LIGHTNING_COMMON_FEE_STATES_H */ diff --git a/common/initial_channel.c b/common/initial_channel.c index 7415a2c42..46538be9f 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -238,7 +238,7 @@ static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view) } /* FIXME: This should reference HTLCs somehow, and feerates! */ -static char *fmt_channel(const tal_t *ctx, const struct channel *channel) +char *fmt_channel(const tal_t *ctx, const struct channel *channel) { return tal_fmt(ctx, "{ funding=%s," " opener=%s," diff --git a/common/initial_channel.h b/common/initial_channel.h index 3c20270e5..5204efe22 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -185,4 +185,5 @@ bool channel_has(const struct channel *channel, int feature); /* Convenience for querying either anchor_outputs or anchors_zero_fee_htlc_tx */ bool channel_has_anchors(const struct channel *channel); +char *fmt_channel(const tal_t *ctx, const struct channel *channel); #endif /* LIGHTNING_COMMON_INITIAL_CHANNEL_H */ diff --git a/common/json_stream.c b/common/json_stream.c index 59c7e8957..3b1743c3e 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -604,7 +604,7 @@ void json_add_psbt(struct json_stream *stream, const struct wally_psbt *psbt TAKES) { const char *psbt_b64; - psbt_b64 = psbt_to_b64(NULL, psbt); + psbt_b64 = fmt_wally_psbt(NULL, psbt); json_add_string(stream, fieldname, take(psbt_b64)); if (taken(psbt)) tal_free(psbt); diff --git a/common/node_id.c b/common/node_id.c index 902b651b6..273e8053f 100644 --- a/common/node_id.c +++ b/common/node_id.c @@ -34,11 +34,11 @@ bool node_id_valid(const struct node_id *id) } /* Convert to hex string of SEC1 encoding */ -char *node_id_to_hexstr(const tal_t *ctx, const struct node_id *id) +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, node_id_to_hexstr); +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) diff --git a/common/node_id.h b/common/node_id.h index 110c590dd..fa4779c1a 100644 --- a/common/node_id.h +++ b/common/node_id.h @@ -30,7 +30,7 @@ WARN_UNUSED_RESULT bool pubkey_from_node_id(struct pubkey *key, const struct node_id *id); /* Convert to hex string of SEC1 encoding. */ -char *node_id_to_hexstr(const tal_t *ctx, const struct node_id *id); +char *fmt_node_id(const tal_t *ctx, const struct node_id *id); /* Convert from hex string of SEC1 encoding: checks validity! */ bool node_id_from_hexstr(const char *str, size_t slen, struct node_id *id); diff --git a/common/test/run-json_stream-filter.c b/common/test/run-json_stream-filter.c index b6331830a..91a0df16b 100644 --- a/common/test/run-json_stream-filter.c +++ b/common/test/run-json_stream-filter.c @@ -59,7 +59,7 @@ struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_e struct json_filter **command_filter_ptr(struct command *cmd UNNEEDED) { fprintf(stderr, "command_filter_ptr called!\n"); abort(); } /* Generated stub for fmt_amount_sat */ -const char *fmt_amount_sat(const tal_t *ctx UNNEEDED, struct amount_sat sat UNNEEDED) +char *fmt_amount_sat(const tal_t *ctx UNNEEDED, struct amount_sat sat UNNEEDED) { fprintf(stderr, "fmt_amount_sat called!\n"); abort(); } /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) diff --git a/common/test/run-onion-message-test.c b/common/test/run-onion-message-test.c index dc6ae3aa1..2314bd582 100644 --- a/common/test/run-onion-message-test.c +++ b/common/test/run-onion-message-test.c @@ -97,7 +97,7 @@ static void json_hex_talfield(const char *name, const u8 *val) static void json_pubkey(const char *name, const struct pubkey *key) { - json_strfield(name, pubkey_to_hexstr(tmpctx, key)); + json_strfield(name, fmt_pubkey(tmpctx, key)); } static bool enable_superverbose; diff --git a/common/test/run-route-infloop.c b/common/test/run-route-infloop.c index 31989e2dd..6a29651fb 100644 --- a/common/test/run-route-infloop.c +++ b/common/test/run-route-infloop.c @@ -163,7 +163,7 @@ int main(int argc, char *argv[]) gossmap_node_get_id(gossmap, nodes[i], &them); - printf("%s,", node_id_to_hexstr(tmpctx, &them)); + printf("%s,", fmt_node_id(tmpctx, &them)); if (!r) { printf("0,0.0,"); } else { @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) r[0].amount.millisatoshis - amt, r[0].delay - final_delay); for (size_t j = 0; j < tal_count(r); j++) - printf(",%s/%u", short_channel_id_to_str(tmpctx, &r[j].scid), r[j].direction); + printf(",%s/%u", fmt_short_channel_id(tmpctx, r[j].scid), r[j].direction); } printf("\n"); } diff --git a/common/type_to_string.c b/common/type_to_string.c index a23bf358e..ec19f822a 100644 --- a/common/type_to_string.c +++ b/common/type_to_string.c @@ -4,11 +4,19 @@ #include #include +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_HEXSTR(sha256); -REGISTER_TYPE_TO_HEXSTR(ripemd160); -/* This one in bitcoin/ but doesn't have its own C file */ -REGISTER_TYPE_TO_HEXSTR(preimage); +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) diff --git a/common/type_to_string.h b/common/type_to_string.h index deb297eef..45fae3725 100644 --- a/common/type_to_string.h +++ b/common/type_to_string.h @@ -1,8 +1,8 @@ #ifndef LIGHTNING_COMMON_TYPE_TO_STRING_H #define LIGHTNING_COMMON_TYPE_TO_STRING_H #include "config.h" -#include "utils.h" #include +#include /* This must match the type_to_string_ cases. */ union printable_types { @@ -58,20 +58,13 @@ const char *type_to_string_(const tal_t *ctx, const char *typename, }; \ AUTODATA(type_to_string, &ttos_##typename) -#define REGISTER_TYPE_TO_HEXSTR(typename) \ - static const char *fmt_##typename##_(const tal_t *ctx, \ - union printable_types u) \ - { \ - return tal_hexstr(ctx, u.typename, sizeof(*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 */ diff --git a/common/wireaddr.c b/common/wireaddr.c index 174c5c22c..e9781f8ae 100644 --- a/common/wireaddr.c +++ b/common/wireaddr.c @@ -218,7 +218,7 @@ bool wireaddr_is_wildcard(const struct wireaddr *addr) } char *fmt_wireaddr_internal(const tal_t *ctx, - const struct wireaddr_internal *a) + const struct wireaddr_internal *a) { switch (a->itype) { case ADDR_INTERNAL_SOCKNAME: diff --git a/devtools/checkchannels.c b/devtools/checkchannels.c index 760d97c7f..bf7746d08 100644 --- a/devtools/checkchannels.c +++ b/devtools/checkchannels.c @@ -183,8 +183,8 @@ int main(int argc, char *argv[]) sqlite3_column_pubkey(stmt, 6, &remote_fundingkey); printf("Channel %s with peer %s: funding %s/%u: ", - short_channel_id_to_str(ctx, &scid), - node_id_to_hexstr(ctx, &peer_id), + fmt_short_channel_id(ctx, scid), + fmt_node_id(ctx, &peer_id), txid_hex, funding_outnum); fflush(stdout); diff --git a/devtools/lightning-checkmessage.c b/devtools/lightning-checkmessage.c index 490111097..506469d84 100644 --- a/devtools/lightning-checkmessage.c +++ b/devtools/lightning-checkmessage.c @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) shad.sha.u.u8)) errx(1, "Signature not recoverable"); - keystr = pubkey_to_hexstr(NULL, &reckey); + keystr = fmt_pubkey(NULL, &reckey); if (argv[3]) { if (!streq(keystr, argv[3])) errx(1, "Signature is invalid"); diff --git a/devtools/mkgossip.c b/devtools/mkgossip.c index 74fca27b6..0c1eef3a9 100644 --- a/devtools/mkgossip.c +++ b/devtools/mkgossip.c @@ -149,7 +149,7 @@ static void print_update(const struct bitcoin_blkid *chainhash, printf("type=channel_update\n"); printf(" signature=%s\n", sig_notation(privkey, &hash, &sig)); printf(" chain_hash=%s\n", tal_hexstr(NULL, chainhash, sizeof(*chainhash))); - printf(" short_channel_id=%s\n", short_channel_id_to_str(NULL, scid)); + printf(" short_channel_id=%s\n", fmt_short_channel_id(NULL, *scid)); printf(" timestamp=%u\n", opts->timestamp); printf(" message_flags=%u\n", ROUTING_OPT_HTLC_MAX_MSAT); @@ -196,7 +196,7 @@ static void print_nannounce(const struct node_id *nodeid, printf(" signature=%s\n", sig_notation(privkey, &hash, &sig)); printf(" features=%s\n", tal_hex(NULL, NULL)); printf(" timestamp=%u\n", opts->timestamp); - printf(" node_id=%s\n", node_id_to_hexstr(NULL, nodeid)); + printf(" node_id=%s\n", fmt_node_id(NULL, nodeid)); printf(" rgb_color=%s\n", tal_hexstr(NULL, nodeid->k, 3)); printf(" alias=%s\n", tal_hexstr(NULL, alias, 32)); printf(" addresses=%s\n", tal_hex(NULL, opts->addresses)); @@ -332,15 +332,15 @@ int main(int argc, char *argv[]) sig_notation(&funding_privkey[!lesser_key], &hash, &bitcoinsig[!lesser_key])); printf(" features=%s\n", tal_hex(NULL, features)); printf(" chain_hash=%s\n", tal_hexstr(NULL, &chainhash, sizeof(chainhash))); - printf(" short_channel_id=%s\n", short_channel_id_to_str(NULL, &scid)); + printf(" short_channel_id=%s\n", fmt_short_channel_id(NULL, scid)); printf(" node_id_1=%s\n", - node_id_to_hexstr(NULL, &nodeid[lesser_key])); + fmt_node_id(NULL, &nodeid[lesser_key])); printf(" node_id_2=%s\n", - node_id_to_hexstr(NULL, &nodeid[!lesser_key])); + fmt_node_id(NULL, &nodeid[!lesser_key])); printf(" bitcoin_key_1=%s\n", - pubkey_to_hexstr(NULL, &bitcoin[lesser_key])); + fmt_pubkey(NULL, &bitcoin[lesser_key])); printf(" bitcoin_key_2=%s\n", - pubkey_to_hexstr(NULL, &bitcoin[!lesser_key])); + fmt_pubkey(NULL, &bitcoin[!lesser_key])); printf("\n#Node 1:\n"); print_update(&chainhash, &scid, &opts[0], lesser_key == 0, diff --git a/devtools/onion.c b/devtools/onion.c index 622c405a1..18430ce7c 100644 --- a/devtools/onion.c +++ b/devtools/onion.c @@ -301,7 +301,7 @@ static void decompress(char *hexprivkey, char *hexonion) errx(1, "Could not generate shared secret from ephemeral key %s " "and private key %s", - pubkey_to_hexstr(NULL, &ephkey), hexprivkey); + fmt_pubkey(NULL, &ephkey), hexprivkey); onion = sphinx_decompress(NULL, tinyonion, &shared_secret); if (onion == NULL) diff --git a/devtools/print_wire.c b/devtools/print_wire.c index b3db3cb7c..36bd780f7 100644 --- a/devtools/print_wire.c +++ b/devtools/print_wire.c @@ -241,7 +241,7 @@ static bool printwire_encoded_short_ids(const u8 **cursor, size_t *plen, size_t } for (size_t i = 0; i < tal_count(scids); i++) printf(" %s", - short_channel_id_to_str(tmpctx, &scids[i])); + fmt_short_channel_id(tmpctx, scids[i])); } else { /* If it was unknown, that's different from corrupt */ if (len == 0 diff --git a/gossipd/gossmap_manage.c b/gossipd/gossmap_manage.c index 5235e5325..06c972ce9 100644 --- a/gossipd/gossmap_manage.c +++ b/gossipd/gossmap_manage.c @@ -160,7 +160,7 @@ static bool map_add(struct cannounce_map *map, status_unusual("%s being flooded by %s: dropping some", map->name, pca->source_peer - ? node_id_to_hexstr(tmpctx, pca->source_peer) + ? fmt_node_id(tmpctx, pca->source_peer) : "unknown"); map->flood_reported = true; } @@ -574,7 +574,7 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx, && short_channel_id_blocknum(&scid) > blockheight + 12) { return tal_fmt(ctx, "Bad gossip order: ignoring channel_announcement %s at blockheight %u", - short_channel_id_to_str(tmpctx, &scid), + fmt_short_channel_id(tmpctx, scid), blockheight); } @@ -589,7 +589,7 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx, } status_debug("channel_announcement: Adding %s to pending...", - short_channel_id_to_str(tmpctx, &scid)); + fmt_short_channel_id(tmpctx, scid)); if (!map_add(&gm->pending_ann_map, scid, pca)) { /* Already pending? Ignore */ tal_free(pca); @@ -617,7 +617,7 @@ void gossmap_manage_handle_get_txout_reply(struct gossmap_manage *gm, const u8 * master_badmsg(WIRE_GOSSIPD_GET_TXOUT_REPLY, msg); status_debug("channel_announcement: got reply for %s...", - short_channel_id_to_str(tmpctx, &scid)); + fmt_short_channel_id(tmpctx, scid)); pca = map_del(&gm->pending_ann_map, scid); if (!pca) { @@ -628,7 +628,7 @@ void gossmap_manage_handle_get_txout_reply(struct gossmap_manage *gm, const u8 * /* Was it deleted because we saw channel close? */ if (!in_txout_failures(gm->txf, scid)) status_broken("get_txout_reply with unknown scid %s?", - short_channel_id_to_str(tmpctx, &scid)); + fmt_short_channel_id(tmpctx, scid)); return; } @@ -642,14 +642,14 @@ void gossmap_manage_handle_get_txout_reply(struct gossmap_manage *gm, const u8 * if (tal_count(outscript) == 0) { peer_warning(gm, pca->source_peer, "channel_announcement: no unspent txout %s", - short_channel_id_to_str(tmpctx, &scid)); + fmt_short_channel_id(tmpctx, scid)); goto bad; } if (!tal_arr_eq(outscript, pca->scriptpubkey)) { peer_warning(gm, pca->source_peer, "channel_announcement: txout %s expected %s, got %s", - short_channel_id_to_str(tmpctx, &scid), + fmt_short_channel_id(tmpctx, scid), tal_hex(tmpctx, pca->scriptpubkey), tal_hex(tmpctx, outscript)); goto bad; @@ -717,7 +717,7 @@ static const char *process_channel_update(const tal_t *ctx, /* Don't send them warning, it can happen. */ bad_gossip(source_peer, tal_fmt(tmpctx, "Unknown channel %s", - short_channel_id_to_str(tmpctx, &scid))); + fmt_short_channel_id(tmpctx, scid))); return NULL; } @@ -733,7 +733,7 @@ static const char *process_channel_update(const tal_t *ctx, /* Don't allow private updates on public channels! */ if (message_flags & ROUTING_OPT_DONT_FORWARD) { return tal_fmt(ctx, "Do not set DONT_FORWARD on public channel_updates (%s)", - short_channel_id_to_str(tmpctx, &scid)); + fmt_short_channel_id(tmpctx, scid)); } /* Do we have same or earlier update? */ @@ -1000,7 +1000,7 @@ const char *gossmap_manage_node_announcement(const tal_t *ctx, bad_gossip(source_peer, tal_fmt(tmpctx, "node_announcement: unknown node %s", - node_id_to_hexstr(tmpctx, &node_id))); + fmt_node_id(tmpctx, &node_id))); return NULL; } @@ -1108,7 +1108,7 @@ static void reprocess_queued_msgs(struct gossmap_manage *gm) bad_gossip(pnas[i]->source_peer, tal_fmt(tmpctx, "node_announcement: unknown node %s", - node_id_to_hexstr(tmpctx, &pnas[i]->node_id))); + fmt_node_id(tmpctx, &pnas[i]->node_id))); continue; } @@ -1170,7 +1170,7 @@ void gossmap_manage_new_block(struct gossmap_manage *gm, u32 new_blockheight) } status_debug("gossmap_manage: new block, adding %s to pending...", - short_channel_id_to_str(tmpctx, &scid)); + fmt_short_channel_id(tmpctx, scid)); /* Ask lightningd about this scid: see * gossmap_manage_handle_get_txout_reply */ @@ -1408,7 +1408,7 @@ struct wireaddr *gossmap_manage_get_node_addresses(const tal_t *ctx, &addresses, &na_tlvs)) { status_broken("Bad node_announcement for %s in gossip_store: %s", - node_id_to_hexstr(tmpctx, node_id), + fmt_node_id(tmpctx, node_id), tal_hex(tmpctx, nannounce)); return NULL; } diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index e662dd238..413fdedb4 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -401,7 +401,7 @@ static void handle_splice_confirmed_init(struct lightningd *ld, } struct json_stream *response = json_stream_success(cc->cmd); - json_add_string(response, "psbt", psbt_to_b64(tmpctx, psbt)); + json_add_string(response, "psbt", fmt_wally_psbt(tmpctx, psbt)); was_pending(command_success(cc->cmd, response)); } @@ -434,7 +434,7 @@ static void handle_splice_confirmed_update(struct lightningd *ld, } struct json_stream *response = json_stream_success(cc->cmd); - json_add_string(response, "psbt", psbt_to_b64(tmpctx, psbt)); + json_add_string(response, "psbt", fmt_wally_psbt(tmpctx, psbt)); json_add_bool(response, "commitments_secured", commitments_secured); was_pending(command_success(cc->cmd, response)); diff --git a/lightningd/channel_gossip.c b/lightningd/channel_gossip.c index 59991645e..819609b05 100644 --- a/lightningd/channel_gossip.c +++ b/lightningd/channel_gossip.c @@ -355,7 +355,7 @@ static void cupdate_timer_refresh(struct channel *channel) cg->refresh_timer = NULL; log_debug(channel->log, "Sending keepalive channel_update for %s", - short_channel_id_to_str(tmpctx, channel->scid)); + fmt_short_channel_id(tmpctx, *channel->scid)); /* Free old cupdate to force a new one to be generated */ cg->cupdate = tal_free(cg->cupdate); @@ -379,7 +379,7 @@ static void stash_remote_announce_sigs(struct channel *channel, if (err) { channel_fail_transient(channel, true, "Bad gossip announcement_signatures for scid %s: %s", - short_channel_id_to_str(tmpctx, &scid), + fmt_short_channel_id(tmpctx, scid), err); return; } @@ -391,8 +391,8 @@ static void stash_remote_announce_sigs(struct channel *channel, cg->remote_sigs->bitcoin_sig = *bitcoin_sig; log_debug(channel->log, "channel_gossip: received announcement sigs for %s (we have %s)", - short_channel_id_to_str(tmpctx, &scid), - channel->scid ? short_channel_id_to_str(tmpctx, channel->scid) : "none"); + fmt_short_channel_id(tmpctx, scid), + channel->scid ? fmt_short_channel_id(tmpctx, *channel->scid) : "none"); } static bool apply_remote_sigs(struct channel *channel) @@ -716,7 +716,7 @@ void channel_gossip_scid_changed(struct channel *channel) case CGOSSIP_NEED_PEER_SIGS: case CGOSSIP_ANNOUNCED: log_debug(channel->log, "channel_gossip: scid now %s", - short_channel_id_to_str(tmpctx, channel->scid)); + fmt_short_channel_id(tmpctx, *channel->scid)); /* Start again. */ /* Maybe remote announcement signatures now apply? If not, * free them */ @@ -1003,7 +1003,7 @@ void channel_gossip_set_remote_update(struct lightningd *ld, if (!channel) { log_unusual(ld->log, "Bad gossip order: could not find channel %s for peer's " "channel update", - short_channel_id_to_str(tmpctx, &update->scid)); + fmt_short_channel_id(tmpctx, update->scid)); return; } diff --git a/lightningd/forwards.c b/lightningd/forwards.c index 81614e34a..2cf48018d 100644 --- a/lightningd/forwards.c +++ b/lightningd/forwards.c @@ -21,10 +21,10 @@ static u64 forward_index_inc(struct lightningd *ld, { return wait_index_increment(ld, WAIT_SUBSYSTEM_FORWARD, idx, "status", forward_status_name(status), - "in_channel", short_channel_id_to_str(tmpctx, &in_channel), + "in_channel", fmt_short_channel_id(tmpctx, in_channel), "=in_htlc_id", tal_fmt(tmpctx, "%"PRIu64, in_htlc_id), "=in_msat", in_amount ? tal_fmt(tmpctx, "%"PRIu64, in_amount->millisatoshis) : NULL, /* Raw: JSON output */ - "out_channel", out_channel ? short_channel_id_to_str(tmpctx, out_channel): NULL, + "out_channel", out_channel ? fmt_short_channel_id(tmpctx, *out_channel): NULL, NULL); } diff --git a/lightningd/log.c b/lightningd/log.c index 2afd0a373..316890115 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -167,7 +167,7 @@ static void lowest_filter(const struct list_head *print_filters, const char *node_id_str; if (node_id) - node_id_str = node_id_to_hexstr(tmpctx, node_id); + node_id_str = fmt_node_id(tmpctx, node_id); else node_id_str = NULL; @@ -216,7 +216,7 @@ static void log_to_files(const char *log_prefix, tstamp[0] = '\0'; if (node_id) - nodestr = node_id_to_hexstr(tmpctx, node_id); + nodestr = fmt_node_id(tmpctx, node_id); else nodestr = ""; if (level == LOG_IO_IN || level == LOG_IO_OUT) { diff --git a/lightningd/pay.c b/lightningd/pay.c index fa0dddc61..2ed7c0d97 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -838,7 +838,7 @@ find_channel_for_htlc_add(struct lightningd *ld, } log_debug(ld->log, "No channel found for selector %s (%s)", - short_channel_id_to_str(tmpctx, scid_or_alias), + fmt_short_channel_id(tmpctx, *scid_or_alias), type_to_string(tmpctx, struct amount_msat, amount)); return NULL; @@ -846,9 +846,9 @@ found: scid = channel_scid_or_local_alias(channel); log_debug( ld->log, "Selected channel %s (%s) for selector %s (%s)", - short_channel_id_to_str(tmpctx, scid), + fmt_short_channel_id(tmpctx, *scid), type_to_string(tmpctx, struct amount_msat, &channel->our_msat), - short_channel_id_to_str(tmpctx, scid_or_alias), + fmt_short_channel_id(tmpctx, *scid_or_alias), type_to_string(tmpctx, struct amount_msat, amount)); return channel; diff --git a/lightningd/runes.c b/lightningd/runes.c index 7ab13251e..ee5544019 100644 --- a/lightningd/runes.c +++ b/lightningd/runes.c @@ -733,7 +733,7 @@ static const char *check_condition(const tal_t *ctx, return rune_alt_single_int(ctx, alt, cinfo->now.ts.tv_sec); } else if (streq(alt->fieldname, "id")) { if (cinfo->peer) { - const char *id = node_id_to_hexstr(tmpctx, cinfo->peer); + const char *id = fmt_node_id(tmpctx, cinfo->peer); return rune_alt_single_str(ctx, alt, id, strlen(id)); } return rune_alt_single_missing(ctx, alt); diff --git a/lightningd/test/run-log-pruning.c b/lightningd/test/run-log-pruning.c index d3a6fe6ec..e6dfd00c1 100644 --- a/lightningd/test/run-log-pruning.c +++ b/lightningd/test/run-log-pruning.c @@ -17,6 +17,9 @@ struct command_result *command_success(struct command *cmd UNNEEDED, struct json_stream *response) { fprintf(stderr, "command_success called!\n"); abort(); } +/* Generated stub for fmt_node_id */ +char *fmt_node_id(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED) +{ fprintf(stderr, "fmt_node_id called!\n"); abort(); } /* Generated stub for fromwire_bigsize */ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } @@ -81,9 +84,6 @@ const char *log_level_name(enum log_level level UNNEEDED) bool log_level_parse(const char *levelstr UNNEEDED, size_t len UNNEEDED, enum log_level *level UNNEEDED) { fprintf(stderr, "log_level_parse called!\n"); abort(); } -/* Generated stub for node_id_to_hexstr */ -char *node_id_to_hexstr(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED) -{ fprintf(stderr, "node_id_to_hexstr called!\n"); abort(); } /* Generated stub for notify_warning */ void notify_warning(struct lightningd *ld UNNEEDED, struct log_entry *l UNNEEDED) { fprintf(stderr, "notify_warning called!\n"); abort(); } diff --git a/plugins/commando.c b/plugins/commando.c index eb85caac7..2d9fc1515 100644 --- a/plugins/commando.c +++ b/plugins/commando.c @@ -444,7 +444,7 @@ static void handle_incmd(struct command *cmd, /* Don't let them buffer multiple commands: discard old. */ if (incmd && incmd->id != idnum) { plugin_log(plugin, LOG_DBG, "New cmd from %s, replacing old", - node_id_to_hexstr(tmpctx, peer)); + fmt_node_id(tmpctx, peer)); incmd = tal_free(incmd); } @@ -467,7 +467,7 @@ static void handle_incmd(struct command *cmd, if (!incmd->contents) { plugin_log(plugin, LOG_UNUSUAL, "%s: ignoring oversize request", - node_id_to_hexstr(tmpctx, peer)); + fmt_node_id(tmpctx, peer)); return; } @@ -491,7 +491,7 @@ static struct command_result *handle_reply(struct node_id *peer, plugin_log(plugin, LOG_DBG, "Ignoring unexpected %s reply from %s (id %"PRIu64")", terminal ? "terminal" : "partial", - node_id_to_hexstr(tmpctx, peer), + fmt_node_id(tmpctx, peer), idnum); return NULL; } diff --git a/plugins/keysend.c b/plugins/keysend.c index ce3e3a6fe..0a8683d1b 100644 --- a/plugins/keysend.c +++ b/plugins/keysend.c @@ -81,7 +81,7 @@ static void keysend_cb(struct keysend_data *d, struct payment *p) { p, "Recipient %s reported an invalid payload, this " "usually means they don't support keysend.", - node_id_to_hexstr(tmpctx, p->destination)); + fmt_node_id(tmpctx, p->destination)); } } diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 4e8ce19d8..6563bc68e 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -752,7 +752,7 @@ fundchannel_complete_ok(struct command *cmd, plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64", dest %u: fundchannel_complete %s done.", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id)); + fmt_node_id(tmpctx, &dest->id)); channel_id_tok = json_get_member(buf, result, "channel_id"); if (!channel_id_tok) @@ -778,7 +778,7 @@ fundchannel_complete_err(struct command *cmd, "mfc %"PRIu64", dest %u: " "failed! fundchannel_complete %s: %.*s", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id), + fmt_node_id(tmpctx, &dest->id), json_tok_full_len(error), json_tok_full(buf, error)); fail_destination_tok(dest, buf, error); @@ -795,7 +795,7 @@ fundchannel_complete_dest(struct multifundchannel_destination *dest) plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64", dest %u: fundchannel_complete %s.", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id)); + fmt_node_id(tmpctx, &dest->id)); req = jsonrpc_request_start(cmd->plugin, cmd, @@ -1053,7 +1053,7 @@ fundchannel_start_ok(struct command *cmd, plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64", dest %u: fundchannel_start %s done.", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id)); + fmt_node_id(tmpctx, &dest->id)); /* May not be set */ dest->close_to_script = NULL; @@ -1085,7 +1085,7 @@ fundchannel_start_err(struct command *cmd, "mfc %"PRIu64", dest %u: " "failed! fundchannel_start %s: %.*s.", dest->mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id), + fmt_node_id(tmpctx, &dest->id), json_tok_full_len(error), json_tok_full(buf, error)); /* @@ -1114,7 +1114,7 @@ fundchannel_start_dest(struct multifundchannel_destination *dest) plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64", dest %u: fundchannel_start %s.", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id)); + fmt_node_id(tmpctx, &dest->id)); req = jsonrpc_request_start(cmd->plugin, cmd, @@ -1594,7 +1594,7 @@ connect_err(struct command *cmd, plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64", dest %u: failed! connect %s: %.*s.", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id), + fmt_node_id(tmpctx, &dest->id), json_tok_full_len(error), json_tok_full(buf, error)); @@ -1610,7 +1610,7 @@ connect_dest(struct multifundchannel_destination *dest) const char *id; struct out_req *req; - id = node_id_to_hexstr(tmpctx, &dest->id); + id = fmt_node_id(tmpctx, &dest->id); plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64", dest %u: connect %s.", mfc->id, dest->index, id); diff --git a/plugins/spender/multiwithdraw.c b/plugins/spender/multiwithdraw.c index d68c0c718..a47954fb1 100644 --- a/plugins/spender/multiwithdraw.c +++ b/plugins/spender/multiwithdraw.c @@ -447,7 +447,7 @@ mw_after_fundpsbt(struct command *cmd, "multiwithdraw %"PRIu64": %s done: %s.", mw->id, mw->utxos ? "utxopsbt" : "fundpsbt", - psbt_to_b64(tmpctx, mw->psbt)); + fmt_wally_psbt(tmpctx, mw->psbt)); /* Handle 'all'. */ if (mw->has_all) { diff --git a/plugins/spender/openchannel.c b/plugins/spender/openchannel.c index 5993f1e9f..fc0044675 100644 --- a/plugins/spender/openchannel.c +++ b/plugins/spender/openchannel.c @@ -693,7 +693,7 @@ openchannel_update_ok(struct command *cmd, plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64", dest %u: openchannel_update %s returned.", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id)); + fmt_node_id(tmpctx, &dest->id)); assert(!dest->updated_psbt); psbt_tok = json_get_member(buf, result, "psbt"); @@ -794,7 +794,7 @@ openchannel_update_dest(struct multifundchannel_destination *dest) "mfc %"PRIu64", dest %u: `openchannel_update` %s " "with psbt %s", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id), + fmt_node_id(tmpctx, &dest->id), type_to_string(tmpctx, struct wally_psbt, dest->psbt)); req = jsonrpc_request_start(cmd->plugin, @@ -923,7 +923,7 @@ openchannel_init_ok(struct command *cmd, plugin_log(mfc->cmd->plugin, LOG_DBG, "mfc %"PRIu64", dest %u: openchannel_init %s done.", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id)); + fmt_node_id(tmpctx, &dest->id)); err = json_scan(mfc, buf, result, "{psbt:%," @@ -980,7 +980,7 @@ openchannel_init_dest(struct multifundchannel_destination *dest) plugin_log(cmd->plugin, LOG_DBG, "mfc %"PRIu64", dest %u: openchannel_init %s.", mfc->id, dest->index, - node_id_to_hexstr(tmpctx, &dest->id)); + fmt_node_id(tmpctx, &dest->id)); req = jsonrpc_request_start(cmd->plugin, cmd, "openchannel_init", @@ -1021,7 +1021,7 @@ openchannel_init_dest(struct multifundchannel_destination *dest) plugin_log(cmd->plugin, LOG_INFORM, "Using openchannel for %s open, " "ignoring `push_msat` of %s", - node_id_to_hexstr(tmpctx, &dest->id), + fmt_node_id(tmpctx, &dest->id), type_to_string(tmpctx, struct amount_msat, &dest->push_msat)); diff --git a/plugins/sql.c b/plugins/sql.c index b427d876f..7379fb714 100644 --- a/plugins/sql.c +++ b/plugins/sql.c @@ -768,7 +768,7 @@ static void delete_channel_from_db(struct command *cmd, tal_fmt(tmpctx, "DELETE FROM channels" " WHERE short_channel_id = '%s'", - short_channel_id_to_str(tmpctx, &scid)), + fmt_short_channel_id(tmpctx, scid)), NULL, NULL, &errmsg); if (err != SQLITE_OK) plugin_err(cmd->plugin, "Could not delete from channels: %s", @@ -904,7 +904,7 @@ static void delete_node_from_db(struct command *cmd, tal_fmt(tmpctx, "DELETE FROM nodes" " WHERE nodeid = X'%s'", - node_id_to_hexstr(tmpctx, id)), + fmt_node_id(tmpctx, id)), NULL, NULL, &errmsg); if (err != SQLITE_OK) plugin_err(cmd->plugin, "Could not delete from nodes: %s",