mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
global: expose all fmt_X functions for direct use, make uniform.
We have various functions to convert to a string, rename them all so we can count on fmt_X being the formatter for struct X, and make them all return `char *`. Sometimes they existed but were private, sometimes they had a different name. Most take a pointer, but simple types pass by copy: short_channel_id, amount_msat and amount_sat. The following public functions changed: 1. psbt_to_b64 -> fmt_wally_psbt. 2. pubkey_to_hexstr -> fmt_pubkey. 3. short_channel_id_to_str -> fmt_short_channel_id (scid by copy now!) 4. fmt_signature -> fmt_secp256k1_ecdsa_signature 5. fmt_amount_sat/fmt_amount_msat pass copy not pointer, return non-const char *. 6. node_id_to_hexstr -> fmt_node_id Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
aba7c50442
commit
d8c06dccac
@ -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)));
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "config.h"
|
||||
#include <bitcoin/preimage.h>
|
||||
#include <common/type_to_string.h>
|
||||
#include <common/utils.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
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);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/structeq/structeq.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
|
||||
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 */
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <common/type_to_string.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/structeq/structeq.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
|
||||
#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 */
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/crypto/sha256/sha256.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
|
||||
/* 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 */
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
*
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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++) {
|
||||
|
@ -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?
|
||||
*/
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/structeq/structeq.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
|
||||
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,
|
||||
|
@ -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++) {
|
||||
|
@ -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 */
|
||||
|
@ -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,"
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -4,11 +4,19 @@
|
||||
#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_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)
|
||||
|
@ -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 <common/autodata.h>
|
||||
#include <common/utils.h>
|
||||
|
||||
/* 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 */
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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(); }
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user