Skip to content

Commit

Permalink
rest: added getTotals endpoint
Browse files Browse the repository at this point in the history
spv: added totals for blockchain stats
  • Loading branch information
edtubbs committed Feb 7, 2025
1 parent 1a2a1c8 commit 3ed0150
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/dogecoin/spv.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ typedef struct dogecoin_spv_client_
uint64_t last_block_size;
uint64_t last_block_tx_count;
uint64_t last_block_total_tx_size;
uint64_t total_num_tx;
uint64_t total_num_addresses;
uint64_t total_blockchain_size;
uint64_t total_num_inputs;
uint64_t total_num_outputs;

/* callbacks */
/* ========= */
Expand Down
10 changes: 10 additions & 0 deletions src/rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ void dogecoin_http_request_cb(struct evhttp_request *req, void *arg) {
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 if (strcmp(path, "/getTotals") == 0) {
uint64_t num_tx = client->total_num_tx;
uint64_t blockchain_size = client->total_blockchain_size;
uint64_t num_inputs = client->total_num_inputs;
uint64_t num_outputs = client->total_num_outputs;

evbuffer_add_printf(evb, "Total number of transactions: %lu\n", num_tx);
evbuffer_add_printf(evb, "Total blockchain size: %lu\n", blockchain_size);
evbuffer_add_printf(evb, "Total number of inputs: %lu\n", num_inputs);
evbuffer_add_printf(evb, "Total number of outputs: %lu\n", num_outputs);
} else {
evhttp_send_error(req, HTTP_NOTFOUND, "Not Found");
evbuffer_free(evb);
Expand Down
8 changes: 8 additions & 0 deletions src/spv.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ void dogecoin_net_spv_post_cmd(dogecoin_node *node, dogecoin_p2p_msg_hdr *hdr, s
client->last_block_tx_count = amount_of_txs;
client->last_block_size = hdr->data_len;

// update totals for the client
client->total_num_tx += amount_of_txs;
client->total_blockchain_size += hdr->data_len;

uint64_t total_tx_size = 0;

size_t consumedlength = 0;
Expand All @@ -606,6 +610,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;

// update totals for the client
client->total_num_inputs += tx->vin->len;
client->total_num_outputs += tx->vout->len;
dogecoin_tx_free(tx);
}
client->last_block_total_tx_size = total_tx_size;
Expand Down

0 comments on commit 3ed0150

Please sign in to comment.