Skip to content

Commit

Permalink
Merge pull request #151 from saratomaz/new_query_pool_state
Browse files Browse the repository at this point in the history
add helper function for new 'query pool-state' command
  • Loading branch information
mkoura committed Feb 8, 2023
2 parents a87b111 + 78196a3 commit a9fa2e9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cardano_clusterlib/query_group.py
Expand Up @@ -4,6 +4,7 @@
import functools
import json
import logging
import warnings
from pathlib import Path
from typing import Any
from typing import Dict
Expand Down Expand Up @@ -196,6 +197,10 @@ def get_pool_params(
Returns:
dict: A pool parameters.
"""
warnings.warn(
"`pool-params` deprecated by `pool-state` for node 1.35.4+", DeprecationWarning
)

pool_params: dict = json.loads(
self.query_cli(["pool-params", "--stake-pool-id", stake_pool_id])
)
Expand All @@ -212,6 +217,34 @@ def get_pool_params(
)
return pparams_top

def get_pool_state(
self,
stake_pool_id: str,
) -> structs.PoolParamsTop:
"""Return a pool state.
Args:
stake_pool_id: An ID of the stake pool (Bech32-encoded or hex-encoded).
Returns:
dict: A pool parameters.
"""
pool_state: dict = json.loads(
self.query_cli(["pool-state", "--stake-pool-id", stake_pool_id])
)

# the information is nested under hex encoded stake pool ID
if pool_state:
pool_state = next(iter(pool_state.values()))

retiring = pool_state.get("retiring") # pool retiring epoch
pparams_top = structs.PoolParamsTop(
pool_params=pool_state.get("poolParams") or {},
future_pool_params=pool_state.get("futurePoolParams") or {},
retiring=int(retiring) if retiring is not None else None,
)
return pparams_top

def get_stake_addr_info(self, stake_addr: str) -> structs.StakeAddrInfo:
"""Return the current delegations and reward accounts filtered by stake address.
Expand Down

0 comments on commit a9fa2e9

Please sign in to comment.