Skip to content

Commit 8d8bacd

Browse files
Include get future pparams
1 parent 9054c54 commit 8d8bacd

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

cardano_clusterlib/query_group.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,5 +709,57 @@ def get_treasury(self) -> int:
709709
"""Get the treasury value."""
710710
return int(self.query_cli(["treasury"]))
711711

712+
def get_future_pparams(self) -> dict[str, tp.Any]:
713+
"""
714+
Return the protocol parameters that will apply at the next epoch.
715+
716+
Equivalent CLI:
717+
cardano-cli latest query future-pparams --testnet-magic <n> --socket-path <socket>
718+
719+
Returns:
720+
dict[str, Any]: Parameters scheduled for the next epoch, or {} if none.
721+
"""
722+
socket_path = str(self._clusterlib_obj.socket_path or "")
723+
if not socket_path:
724+
possible_socket = pl.Path(self._clusterlib_obj.state_dir) / "bft1.socket"
725+
if possible_socket.exists():
726+
socket_path = str(possible_socket)
727+
else:
728+
msg = "Socket path not set or found. Make sure the cluster is running."
729+
raise RuntimeError(msg)
730+
731+
cmd_args: list[str] = [
732+
"cardano-cli",
733+
"latest",
734+
"query",
735+
"future-pparams",
736+
*map(str, self._clusterlib_obj.magic_args),
737+
"--socket-path",
738+
socket_path,
739+
"--output-json",
740+
]
741+
742+
cli_out = self._clusterlib_obj.cli(cmd_args, add_default_args=False)
743+
out_str = cli_out.stdout.decode().strip()
744+
745+
if not out_str or out_str.lower() == "null":
746+
LOGGER.debug("No future protocol parameters scheduled.")
747+
return {}
748+
749+
try:
750+
result = json.loads(out_str)
751+
except json.JSONDecodeError as err:
752+
LOGGER.warning(f"Could not decode future-pparams output as JSON: {err}")
753+
return {}
754+
755+
# Type-safe
756+
if isinstance(result, dict):
757+
return result
758+
if isinstance(result, list):
759+
LOGGER.warning(f"Unexpected list returned from future-pparams query: {result}")
760+
return {"_list_result": result}
761+
LOGGER.warning(f"Unexpected output type for future-pparams: {type(result).__name__}")
762+
return {}
763+
712764
def __repr__(self) -> str:
713765
return f"<{self.__class__.__name__}: clusterlib_obj={id(self._clusterlib_obj)}>"

0 commit comments

Comments
 (0)