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

count addresses endpionts #530

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

tdroxler
Copy link
Member

@tdroxler tdroxler commented Apr 18, 2024

We can first discussed if we want those endpoints or not. The idea comes from this discussion, we currently could have the number of addresses using the rich-list app, but it might not be the more reliable solution to depend on a third-party app, rather than using our explorer-backend.

We know that counting is slow in PG, but we can use our cache and have some long timeout, like 1 to 5min for such data IMO.

The first endpoint /infos/total-addresses returns every addresses that have at least 1 tx.
The second /infos/total-holders-estimation only return addresses with balance > 0. This is an estimation because if we want the real number, we would need to join the Outputs and Inputs, which is too much expensive. Here we only count the addresses with an empty finalized spent output, but to do the finalization time, we can have a difference.

The current estimation is 92228, so on our website and explorer, we could definitively show: More than 92K holders

there are around 90 addresses more when estimate.

explorer=#       
    SELECT count(DISTINCT outputs.address)
      FROM outputs
        LEFT JOIN inputs
        ON outputs.key = inputs.output_ref_key
        AND inputs.main_chain = true
      WHERE outputs.spent_finalized IS NULL
        AND outputs.main_chain = true
        AND inputs.block_hash IS NULL;
 count 
-------
 92133
(1 row)

explorer=#       
     SELECT count(DISTINCT outputs.address)
      FROM outputs
      WHERE outputs.spent_finalized IS NULL
        AND outputs.main_chain = true
;
 count 
-------
 92228
(1 row)

@tdroxler tdroxler requested a review from polarker April 18, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant