diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0fd0e444..f39380e22 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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" diff --git a/include/dogecoin/spv.h b/include/dogecoin/spv.h index 600196681..902e6257a 100644 --- a/include/dogecoin/spv.h +++ b/include/dogecoin/spv.h @@ -54,6 +54,9 @@ typedef struct dogecoin_spv_client_ dogecoin_bool called_sync_completed; void *headers_db_ctx; const dogecoin_headers_db_interface *headers_db; + uint64_t last_block_size; + uint64_t last_block_tx_count; + uint64_t last_block_total_tx_size; /* callbacks */ /* ========= */ diff --git a/src/rest.c b/src/rest.c index 75cc7ae91..f7cbffd09 100644 --- a/src/rest.c +++ b/src/rest.c @@ -33,6 +33,7 @@ #include #include +#define TIMESTAMP_MAX_LEN 32 /** * This function is called when an http request is received @@ -207,6 +208,21 @@ 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 if (strcmp(path, "/getLastBlockInfo") == 0) { + uint64_t size = client->last_block_size; + uint64_t tx_count = client->last_block_tx_count; + uint64_t total_tx_size = client->last_block_total_tx_size; + + evbuffer_add_printf(evb, "Block size: %lu\n", size); + evbuffer_add_printf(evb, "Tx count: %lu\n", tx_count); + evbuffer_add_printf(evb, "Total tx size: %lu\n", total_tx_size); } else { evhttp_send_error(req, HTTP_NOTFOUND, "Not Found"); evbuffer_free(evb); diff --git a/src/spv.c b/src/spv.c index 3f4905c1b..c9b9b2b08 100644 --- a/src/spv.c +++ b/src/spv.c @@ -582,6 +582,12 @@ void dogecoin_net_spv_post_cmd(dogecoin_node *node, dogecoin_p2p_msg_hdr *hdr, s client->nodegroup->log_write_cb("Start parsing %d transactions...\n", (int)amount_of_txs); + // update the last block info for the client + client->last_block_tx_count = amount_of_txs; + client->last_block_size = hdr->data_len; + + uint64_t total_tx_size = 0; + size_t consumedlength = 0; unsigned int i; for (i = 0; i < amount_of_txs; i++) @@ -599,9 +605,10 @@ void dogecoin_net_spv_post_cmd(dogecoin_node *node, dogecoin_p2p_msg_hdr *hdr, s } deser_skip(buf, consumedlength); if (client->sync_transaction) { client->sync_transaction(client->sync_transaction_ctx, tx, i, pindex); } + total_tx_size += consumedlength; dogecoin_tx_free(tx); } - + client->last_block_total_tx_size = total_tx_size; client->nodegroup->log_write_cb("done (took %lld secs)\n", (unsigned long long)(time(NULL) - start)); } else