core-lightning/bitcoin/shadouble.c
Rusty Russell d8c06dccac 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>
2024-03-20 13:51:48 +10:30

35 lines
951 B
C

#include "config.h"
#include <bitcoin/shadouble.h>
#include <ccan/mem/mem.h>
#include <common/type_to_string.h>
#include <wire/wire.h>
void sha256_double(struct sha256_double *shadouble, const void *p, size_t len)
{
sha256(&shadouble->sha, memcheck(p, len), len);
sha256(&shadouble->sha, &shadouble->sha, sizeof(shadouble->sha));
}
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));
}
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)
{
towire_sha256(pptr, &sha256d->sha);
}
void fromwire_sha256_double(const u8 **cursor, size_t *max,
struct sha256_double *sha256d)
{
fromwire_sha256(cursor, max, &sha256d->sha);
}