From 06f090c6a511916f576a3fa233cf32f82363cd77 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 10 Apr 2019 17:09:20 +0200 Subject: [PATCH] json: Add timestampt primitives to print timestamps in results The timestamps are UNIX-Timestamps with 3 decimal places, even though we have the timestamp with nanosecond granularity. This is deliberate choice not to over overload the users :-) Signed-off-by: Christian Decker --- lightningd/json.c | 7 +++++++ lightningd/json.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/lightningd/json.c b/lightningd/json.c index 114c44fe3..d73f9be01 100644 --- a/lightningd/json.c +++ b/lightningd/json.c @@ -368,3 +368,10 @@ void json_add_amount_sat(struct json_stream *result, json_add_member(result, msatfieldname, "\"%s\"", type_to_string(tmpctx, struct amount_msat, &msat)); } + +void json_add_timeabs(struct json_stream *result, const char *fieldname, + struct timeabs t) +{ + json_add_member(result, fieldname, "%" PRIu64 ".%03" PRIu64, + (u64)t.ts.tv_sec, (u64)t.ts.tv_nsec / 1000000); +} diff --git a/lightningd/json.h b/lightningd/json.h index 80338fc91..3c2aa02bb 100644 --- a/lightningd/json.h +++ b/lightningd/json.h @@ -7,6 +7,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -170,4 +171,8 @@ enum address_parse_result json_tok_address_scriptpubkey(const tal_t *ctx, const struct chainparams *chainparams, const char *buffer, const jsmntok_t *tok, const u8 **scriptpubkey); + +void json_add_timeabs(struct json_stream *result, const char *fieldname, + struct timeabs t); + #endif /* LIGHTNING_LIGHTNINGD_JSON_H */