Skip to content

Commit

Permalink
rest: added getTimestamp endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
edtubbs committed Dec 4, 2024
1 parent 77cf47f commit 2a46b70
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <dogecoin/spv.h>
#include <dogecoin/wallet.h>

#define TIMESTAMP_MAX_LEN 32

/**
* This function is called when an http request is received
Expand Down Expand Up @@ -207,6 +208,13 @@ void dogecoin_http_request_cb(struct evhttp_request *req, void *arg) {
} else if (strcmp(path, "/getChaintip") == 0) {
dogecoin_blockindex* tip = client->headers_db->getchaintip(client->headers_db_ctx);
evbuffer_add_printf(evb, "Chain tip: %d\n", tip->height);
} else if (strcmp(path, "/getTimestamp") == 0) {
dogecoin_blockindex* tip = client->headers_db->getchaintip(client->headers_db_ctx);
char s[TIMESTAMP_MAX_LEN];
time_t t = tip->header.timestamp;
struct tm *p = localtime(&t);
strftime(s, sizeof(s), "%F %T", p);
evbuffer_add_printf(evb, "%s\n", s);
} else {
evhttp_send_error(req, HTTP_NOTFOUND, "Not Found");
evbuffer_free(evb);
Expand Down

0 comments on commit 2a46b70

Please sign in to comment.