Skip to content

Conversation

pacu
Copy link

@pacu pacu commented May 16, 2025

CoinMarketCap is requesting a method to query the total supply of ZEC in the form of a raw value.

Example: https://avascan.info/api/v1/supply?q=totalSupply

Result:

455452110.20572644

I modified the blockchain-info method

 def blockchain_info_api(conn, _params) do
    {:ok, info} = Cachex.get(:app_cache, "metrics")
    {:ok, %{"build" => build}} = Cachex.get(:app_cache, "info")
    info = Map.put(info, "build", build)
    json(conn, info)
  end

so to create a total-supply that returns the raw value of chainValue

 def total_supply(conn, _params) do
    {:ok, info} = Cachex.get(:app_cache, "metrics")
    {:ok, %{"build" => build}} = Cachex.get(:app_cache, "info")
    info = Map.put(info, "build", build)
    # Extract the chainValue from the chainSupply map
    chain_value = get_in(info, ["chainSupply", "chainValue"])
    send_resp(conn, 200, to_string(chain_value))
  end

@matiasurbieta
Copy link

The change looks good to me.
I performed the following steps:

  • Checkout the code.
  • Run mix deps.getand then mix phx.server
  • Run the following cURL sentence:

curl 'http://localhost:4000/api/v1/total-supply' \ -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \ -H 'Accept-Language: en-US,en;q=0.9' \ -H 'Cache-Control: no-cache' \ -H 'Connection: keep-alive' \ -H 'Cookie: _zcash_explorer_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYdm1NN2UxeDVqNGpEeWVDcHFxUlB4RW01.E7qa3r_BPw8ZPvQhZQZmItpi-sFJrEs0kc7XBTT4YDg' \ -H 'Pragma: no-cache' \ -H 'Sec-Fetch-Dest: document' \ -H 'Sec-Fetch-Mode: navigate' \ -H 'Sec-Fetch-Site: none' \ -H 'Sec-Fetch-User: ?1' \ -H 'Upgrade-Insecure-Requests: 1' \ -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' \ -H 'sec-ch-ua: "Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'sec-ch-ua-platform: "macOS"'

I got the following output as plain test:
16698415.75335043%

Questions:

  • is there any chance that paramenters could be passed to the service?

@pacu
Copy link
Author

pacu commented May 19, 2025

Good catch! I've asked that to the people requesting this and they are just needing this value

This GET method will return the "valuePools" array when called
without parameters and accept the query param "q" whose valid
values are "totalSupply" and "circulatingSupply".

"api/v1/supply?q=totalSupply" will return the total chainValue
"api/v1/supply?q=circulatingSupply" will return totalSupply minus
the value that's present in the lockbox value pool at the time.
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.

3 participants