mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +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);
|
||||
|
||||
Reference in New Issue
Block a user