Skip to content

Commit

Permalink
feat: fixing circulating supply query
Browse files Browse the repository at this point in the history
  • Loading branch information
supreme committed Aug 15, 2024
1 parent 647f03f commit 6bca250
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 2 additions & 8 deletions src/communex/cli/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ def circulating_tokens(c_client: CommuneClient) -> int:

with c_client.get_conn(init=True) as substrate:
block_hash = substrate.get_block_hash()

balances = c_client.query_map_balances(block_hash=block_hash)
total_balance = c_client.get_total_free_issuance(block_hash=block_hash)
total_stake = c_client.get_total_stake(block_hash=block_hash)
format_balances: dict[Any, Any] = {
key: value["data"]["free"] for key, value in balances.items() if "data" in value and "free" in value["data"] # type: ignore
}

total_balance = sum(format_balances.values())

return total_stake + total_balance


Expand Down
4 changes: 0 additions & 4 deletions src/communex/cli/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,6 @@ def add_custom_proposal(ctx: Context, key: str, cid: str):
with context.progress_status("Adding a proposal..."):
client.add_custom_proposal(resolved_key, cid)

# TODO
# refactor this


@network_app.command()
def set_root_weights(ctx: Context, key: str):
"""
Expand Down
15 changes: 15 additions & 0 deletions src/communex/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,21 @@ def get_tempo(self, netuid: int = 0) -> int:

return self.query("Tempo", params=[netuid])

def get_total_free_issuance(self, block_hash: str | None = None) -> int:
"""
Queries the network for the total free issuance.
Fetches the total amount of free issuance tokens available
Returns:
The total free issuance amount.
Raises:
QueryError: If the query to the network fails or is invalid.
"""

return self.query("TotalIssuance", module="Balances", block_hash=block_hash)

def get_total_stake(self, block_hash: str | None = None) -> int:
"""
Retrieves a mapping of total stakes for keys on the network.
Expand Down

0 comments on commit 6bca250

Please sign in to comment.