common: make json_add_timeabs full precision & renamed json_add_time

json_add_timeabs only printed in milliseconds and json_add_time outputs a string which is weird

Changelog-Changed: JSON-RPC time fields now have full nanosecond precision (i.e. 9 decimals not 3): `listfowards` `received_time` `resolved_time` `listpays`/`listsendpays` `created_at`.
This commit is contained in:
ShahanaFarooqui 2023-09-14 12:10:43 +09:30 committed by Rusty Russell
parent d745323f74
commit 3f95597a5e
6 changed files with 13 additions and 13 deletions

View file

@ -370,11 +370,11 @@ void json_add_timeabs(struct json_stream *result, const char *fieldname,
struct timeabs t)
{
json_add_primitive_fmt(result, fieldname,
"%" PRIu64 ".%03" PRIu64,
(u64)t.ts.tv_sec, (u64)t.ts.tv_nsec / 1000000);
"%" PRIu64 ".%09" PRIu64,
(u64)t.ts.tv_sec, (u64)t.ts.tv_nsec);
}
void json_add_time(struct json_stream *result, const char *fieldname,
void json_add_timestr(struct json_stream *result, const char *fieldname,
struct timespec ts)
{
char timebuf[100];

View file

@ -255,7 +255,7 @@ void json_add_timeabs(struct json_stream *result, const char *fieldname,
struct timeabs t);
/* used in log.c and notification.c*/
void json_add_time(struct json_stream *result, const char *fieldname,
void json_add_timestr(struct json_stream *result, const char *fieldname,
struct timespec ts);
/* Add ISO_8601 timestamp string, i.e. "2019-09-07T15:50+01:00" */

View file

@ -1087,7 +1087,7 @@ static void log_to_json(unsigned int skipped,
: level == LOG_IO_IN ? "IO_IN"
: level == LOG_IO_OUT ? "IO_OUT"
: "UNKNOWN");
json_add_time(info->response, "time", diff.ts);
json_add_timestr(info->response, "time", diff.ts);
if (node_id)
json_add_node_id(info->response, "node_id", node_id);
json_add_string(info->response, "source", prefix);
@ -1148,7 +1148,7 @@ static struct command_result *json_getlog(struct command *cmd,
response = json_stream_success(cmd);
/* Suppress logging for this stream, to not bloat io logs */
json_stream_log_suppress_for_cmd(response, cmd);
json_add_time(response, "created_at", log_book->init_time.ts);
json_add_timestr(response, "created_at", log_book->init_time.ts);
json_add_num(response, "bytes_used", (unsigned int)log_book->mem_used);
json_add_num(response, "bytes_max", (unsigned int)log_book->max_mem);
json_add_log(response, log_book, NULL, *minlevel);

View file

@ -136,7 +136,7 @@ static void warning_notification_serialize(struct json_stream *stream,
: "warn");
/* unsuaul/broken event is rare, plugin pay more attentions on
* the absolute time, like when channels failed. */
json_add_time(stream, "time", l->time.ts);
json_add_timestr(stream, "time", l->time.ts);
json_add_timeiso(stream, "timestamp", &l->time);
json_add_string(stream, "source", l->prefix->prefix);
json_add_string(stream, "log", l->log);

View file

@ -51,10 +51,10 @@ void json_add_string(struct json_stream *js UNNEEDED,
const char *fieldname UNNEEDED,
const char *str TAKES UNNEEDED)
{ fprintf(stderr, "json_add_string called!\n"); abort(); }
/* Generated stub for json_add_time */
void json_add_time(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
/* Generated stub for json_add_timestr */
void json_add_timestr(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
struct timespec ts UNNEEDED)
{ fprintf(stderr, "json_add_time called!\n"); abort(); }
{ fprintf(stderr, "json_add_timestr called!\n"); abort(); }
/* Generated stub for json_array_end */
void json_array_end(struct json_stream *js UNNEEDED)
{ fprintf(stderr, "json_array_end called!\n"); abort(); }

View file

@ -55,10 +55,10 @@ void json_add_string(struct json_stream *js UNNEEDED,
const char *fieldname UNNEEDED,
const char *str TAKES UNNEEDED)
{ fprintf(stderr, "json_add_string called!\n"); abort(); }
/* Generated stub for json_add_time */
void json_add_time(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
/* Generated stub for json_add_timestr */
void json_add_timestr(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
struct timespec ts UNNEEDED)
{ fprintf(stderr, "json_add_time called!\n"); abort(); }
{ fprintf(stderr, "json_add_timestr called!\n"); abort(); }
/* Generated stub for json_array_end */
void json_array_end(struct json_stream *js UNNEEDED)
{ fprintf(stderr, "json_array_end called!\n"); abort(); }