Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rest: added getTimestamp endpoint #234

Open
wants to merge 2 commits into
base: 0.1.4-dogebox-pre
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
goal: install
- name: x86_64-macos
host: x86_64-apple-darwin15
os: macos-12
os: macos-13
run-tests: true
dep-opts: "SPEED=slow V=1"
config-opts: "--enable-static --disable-shared --enable-test-passwd"
Expand Down
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
Loading