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,10 +1,13 @@
#include "channel.h"
#include "htlc.h"
#include "remove_dust.h"
#include "type_to_string.h"
#include <assert.h>
#include <ccan/array_size/array_size.h>
#include <ccan/mem/mem.h>
#include <ccan/structeq/structeq.h>
#include <ccan/tal/str/str.h>
#include <inttypes.h>
#include <string.h>
uint64_t fee_by_feerate(size_t txsize, uint64_t fee_rate)
@@ -325,3 +328,32 @@ bool balance_after_force(struct channel_state *cstate)
adjust_fee(cstate, cstate->fee_rate);
return true;
}
static char *fmt_channel_oneside(const tal_t *ctx,
const struct channel_oneside *co)
{
return tal_fmt(ctx, "{ pay_msat=%u"
" fee_msat=%u"
" num_htlcs=%u }",
co->pay_msat,
co->fee_msat,
co->num_htlcs);
}
static char *fmt_channel_state(const tal_t *ctx,
const struct channel_state *cs)
{
return tal_fmt(ctx, "{ anchor=%"PRIu64
" fee_rate=%"PRIu64
" num_nondust=%u"
" ours=%s"
" theirs=%s }",
cs->anchor,
cs->fee_rate,
cs->num_nondust,
fmt_channel_oneside(ctx, &cs->side[LOCAL]),
fmt_channel_oneside(ctx, &cs->side[REMOTE]));
}
REGISTER_TYPE_TO_STRING(channel_oneside, fmt_channel_oneside);
REGISTER_TYPE_TO_STRING(channel_state, fmt_channel_state);

View File

@@ -2,8 +2,10 @@
#include "htlc.h"
#include "log.h"
#include "peer.h"
#include "type_to_string.h"
#include "gen_htlc_state_names.h"
#include <ccan/array_size/array_size.h>
#include <ccan/tal/str/str.h>
#include <inttypes.h>
const char *htlc_state_name(enum htlc_state s)
@@ -203,3 +205,22 @@ void htlc_undostate(struct htlc *h,
h->state = newstate;
}
static char *fmt_htlc(const tal_t *ctx, const struct htlc *h)
{
return tal_fmt(ctx, "{ id=%"PRIu64
" msatoshi=%"PRIu64
" expiry=%s"
" rhash=%s"
" rval=%s"
" src=%s }",
h->id, h->msatoshi,
type_to_string(ctx, struct abs_locktime, &h->expiry),
type_to_string(ctx, struct sha256, &h->rhash),
h->r ? tal_hexstr(ctx, h->r, sizeof(*h->r))
: "UNKNOWN",
h->src ? type_to_string(ctx, struct pubkey,
h->src->peer->id)
: "local");
}
REGISTER_TYPE_TO_STRING(htlc, fmt_htlc);

View File

@@ -1,5 +1,6 @@
#include "bitcoin/pullpush.h"
#include "netaddr.h"
#include "type_to_string.h"
#include "utils.h"
#include <arpa/inet.h>
#include <assert.h>
@@ -86,3 +87,4 @@ bool netaddr_from_fd(int fd, int type, int protocol, struct netaddr *a)
return getpeername(fd, &a->saddr.s, &a->addrlen) == 0;
}
REGISTER_TYPE_TO_STRING(netaddr, netaddr_name);

View File

@@ -78,7 +78,7 @@ update-mocks-daemon/test/%: daemon/test/%
update-mocks: $(DAEMON_TEST_SRC:%=update-mocks-%)
$(DAEMON_TEST_PROGRAMS): $(CCAN_OBJS) $(BITCOIN_OBJS) libsecp256k1.a utils.o
$(DAEMON_TEST_PROGRAMS): $(CCAN_OBJS) $(BITCOIN_OBJS) $(CORE_OBJS) libsecp256k1.a utils.o
$(DAEMON_TEST_OBJS): $(DAEMON_HEADERS) $(DAEMON_JSMN_HEADERS) $(BITCOIN_HEADERS) $(CORE_HEADERS) $(GEN_HEADERS) $(DAEMON_GEN_HEADERS) $(CCAN_HEADERS)

View File

@@ -293,6 +293,11 @@ all_ok()
if grep ^== $DIR1/errors; then exit 1; fi
if grep ^== $DIR2/errors; then exit 1; fi
[ $NUM_LIGHTNINGD = 2 ] || if grep ^== $DIR3/errors; then exit 1; fi
# Look for unknown logging types.
if grep "UNKNOWN TYPE" $DIR1/output >&2; then exit 1; fi
if grep "UNKNOWN TYPE" $DIR2/output >&2; then exit 1; fi
[ $NUM_LIGHTNINGD = 2 ] || if grep "UNKNOWN TYPE" $DIR3/output >&2; then exit 1; fi
$SHUTDOWN_BITCOIN
trap "rm -rf $DIR1 $DIR2 $DIR3" EXIT