Browse Source

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 <decker.christian@gmail.com>
pr-2587
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
06f090c6a5
  1. 7
      lightningd/json.c
  2. 5
      lightningd/json.h

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

5
lightningd/json.h

@ -7,6 +7,7 @@
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <ccan/time/time.h>
#include <common/amount.h>
#include <stdbool.h>
#include <stddef.h>
@ -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 */

Loading…
Cancel
Save