type_to_string: move formatting to appropriate files.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-01-04 14:07:15 +10:30
parent 5bd8063ddb
commit c7b69abdaa
12 changed files with 120 additions and 82 deletions

View File

@@ -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);