mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
type_to_string: move formatting to appropriate files.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "bitcoin/locktime.h"
|
||||
#include "type_to_string.h"
|
||||
#include <assert.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
|
||||
#define SECONDS_POINT 500000000
|
||||
|
||||
@@ -94,3 +96,22 @@ u32 abs_locktime_to_blocks(const struct abs_locktime *abs)
|
||||
assert(!abs_locktime_is_seconds(abs));
|
||||
return abs->locktime;
|
||||
}
|
||||
|
||||
static char *fmt_rel_locktime(const tal_t *ctx, const struct rel_locktime *rl)
|
||||
{
|
||||
if (rel_locktime_is_seconds(rl))
|
||||
return tal_fmt(ctx, "+%usec", rel_locktime_to_seconds(rl));
|
||||
else
|
||||
return tal_fmt(ctx, "+%ublocks", rel_locktime_to_blocks(rl));
|
||||
}
|
||||
|
||||
static char *fmt_abs_locktime(const tal_t *ctx, const struct abs_locktime *al)
|
||||
{
|
||||
if (abs_locktime_is_seconds(al))
|
||||
return tal_fmt(ctx, "%usec", abs_locktime_to_seconds(al));
|
||||
else
|
||||
return tal_fmt(ctx, "%ublocks", abs_locktime_to_blocks(al));
|
||||
}
|
||||
|
||||
REGISTER_TYPE_TO_STRING(rel_locktime, fmt_rel_locktime);
|
||||
REGISTER_TYPE_TO_STRING(abs_locktime, fmt_abs_locktime);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "privkey.h"
|
||||
#include "pubkey.h"
|
||||
#include "type_to_string.h"
|
||||
#include "utils.h"
|
||||
#include <assert.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
@@ -66,6 +67,8 @@ bool pubkey_eq(const struct pubkey *a, const struct pubkey *b)
|
||||
return structeq(&a->pubkey, &b->pubkey);
|
||||
}
|
||||
|
||||
REGISTER_TYPE_TO_STRING(pubkey, pubkey_to_hexstr);
|
||||
|
||||
int pubkey_cmp(const struct pubkey *a, const struct pubkey *b)
|
||||
{
|
||||
u8 keya[33], keyb[33];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "shadouble.h"
|
||||
#include "type_to_string.h"
|
||||
#include <ccan/mem/mem.h>
|
||||
|
||||
void sha256_double(struct sha256_double *shadouble, const void *p, size_t len)
|
||||
@@ -12,3 +13,5 @@ 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);
|
||||
|
||||
11
bitcoin/tx.c
11
bitcoin/tx.c
@@ -1,6 +1,7 @@
|
||||
#include "bitcoin/block.h"
|
||||
#include "bitcoin/pullpush.h"
|
||||
#include "bitcoin/tx.h"
|
||||
#include "type_to_string.h"
|
||||
#include <assert.h>
|
||||
#include <ccan/cast/cast.h>
|
||||
#include <ccan/crypto/sha256/sha256.h>
|
||||
@@ -492,3 +493,13 @@ bool bitcoin_txid_to_hex(const struct sha256_double *txid,
|
||||
reverse_bytes(rev.sha.u.u8, sizeof(rev.sha.u.u8));
|
||||
return hex_encode(&rev, sizeof(rev), hexstr, hexstr_len);
|
||||
}
|
||||
|
||||
static char *fmt_bitcoin_tx(const tal_t *ctx, const struct bitcoin_tx *tx)
|
||||
{
|
||||
u8 *lin = linearize_tx(ctx, tx);
|
||||
char *s = tal_hexstr(ctx, lin, tal_count(lin));
|
||||
tal_free(lin);
|
||||
return s;
|
||||
}
|
||||
|
||||
REGISTER_TYPE_TO_STRING(bitcoin_tx, fmt_bitcoin_tx);
|
||||
|
||||
Reference in New Issue
Block a user