@@ -23,6 +23,27 @@ class QueryGroup:
2323 def __init__ (self , clusterlib_obj : "itp.ClusterLib" ) -> None :
2424 self ._clusterlib_obj = clusterlib_obj
2525
26+ def _get_cred_args (
27+ self ,
28+ drep_script_hash : str = "" ,
29+ drep_vkey : str = "" ,
30+ drep_vkey_file : itp .FileType | None = None ,
31+ drep_key_hash : str = "" ,
32+ ) -> list [str ]:
33+ """Get arguments for script or verification key."""
34+ if drep_script_hash :
35+ cred_args = ["--drep-script-hash" , str (drep_script_hash )]
36+ elif drep_vkey :
37+ cred_args = ["--drep-verification-key" , str (drep_vkey )]
38+ elif drep_vkey_file :
39+ cred_args = ["--drep-verification-key-file" , str (drep_vkey_file )]
40+ elif drep_key_hash :
41+ cred_args = ["--drep-key-hash" , str (drep_key_hash )]
42+ else :
43+ cred_args = []
44+
45+ return cred_args
46+
2647 def query_cli (
2748 self , cli_args : itp .UnpackableSequence , cli_sub_args : itp .UnpackableSequence = ()
2849 ) -> str :
@@ -516,5 +537,91 @@ def get_slot_number(self, timestamp: datetime.datetime) -> int:
516537
517538 return slot_number
518539
540+ def get_constitution (self ) -> dict [str , tp .Any ]:
541+ """Get the constitution."""
542+ out : dict [str , tp .Any ] = json .loads (self .query_cli (["constitution" ]))
543+ return out
544+
545+ def get_gov_state (self ) -> dict [str , tp .Any ]:
546+ """Get the governance state."""
547+ out : dict [str , tp .Any ] = json .loads (self .query_cli (["gov-state" ]))
548+ return out
549+
550+ def get_drep_state (
551+ self ,
552+ drep_script_hash : str = "" ,
553+ drep_vkey : str = "" ,
554+ drep_vkey_file : itp .FileType | None = None ,
555+ drep_key_hash : str = "" ,
556+ ) -> list [list [dict [str , tp .Any ]]]:
557+ """Get the DRep state.
558+
559+ When no key is provided, query all DReps.
560+
561+ Args:
562+ drep_script_hash: DRep script hash (hex-encoded, optional).
563+ drep_vkey: DRep verification key (Bech32 or hex-encoded).
564+ drep_vkey_file: Filepath of the DRep verification key.
565+ drep_key_hash: DRep verification key hash (either Bech32-encoded or hex-encoded).
566+
567+ Returns:
568+ list[list[dict[str, Any]]]: DRep state.
569+ """
570+ cred_args = self ._get_cred_args (
571+ drep_script_hash = drep_script_hash ,
572+ drep_vkey = drep_vkey ,
573+ drep_vkey_file = drep_vkey_file ,
574+ drep_key_hash = drep_key_hash ,
575+ )
576+ if not cred_args :
577+ cred_args = ["--all-dreps" ]
578+
579+ out : list [list [dict [str , tp .Any ]]] = json .loads (self .query_cli (["drep-state" , * cred_args ]))
580+ return out
581+
582+ def get_drep_stake_distribution (
583+ self ,
584+ drep_script_hash : str = "" ,
585+ drep_vkey : str = "" ,
586+ drep_vkey_file : itp .FileType | None = None ,
587+ drep_key_hash : str = "" ,
588+ ) -> dict [str , tp .Any ]:
589+ """Get the DRep stake distribution.
590+
591+ When no key is provided, query all DReps.
592+
593+ Args:
594+ drep_script_hash: DRep script hash (hex-encoded, optional).
595+ drep_vkey: DRep verification key (Bech32 or hex-encoded).
596+ drep_vkey_file: Filepath of the DRep verification key.
597+ drep_key_hash: DRep verification key hash (either Bech32-encoded or hex-encoded).
598+
599+ Returns:
600+ dict[str, Any]: DRep stake distribution.
601+ """
602+ cred_args = self ._get_cred_args (
603+ drep_script_hash = drep_script_hash ,
604+ drep_vkey = drep_vkey ,
605+ drep_vkey_file = drep_vkey_file ,
606+ drep_key_hash = drep_key_hash ,
607+ )
608+ if not cred_args :
609+ cred_args = ["--all-dreps" ]
610+
611+ out : list [list ] | dict [str , tp .Any ] = json .loads (
612+ self .query_cli (["drep-stake-distribution" , * cred_args ])
613+ )
614+ recs : dict [str , tp .Any ] = {i [0 ]: i [1 ] for i in out } if isinstance (out , list ) else out
615+ return recs
616+
617+ def get_committee_state (self ) -> dict [str , tp .Any ]:
618+ """Get the committee state."""
619+ out : dict [str , tp .Any ] = json .loads (self .query_cli (["committee-state" ]))
620+ return out
621+
622+ def get_treasury (self ) -> int :
623+ """Get the treasury value."""
624+ return int (self .query_cli (["treasury" ]))
625+
519626 def __repr__ (self ) -> str :
520627 return f"<{ self .__class__ .__name__ } : clusterlib_obj={ id (self ._clusterlib_obj )} >"
0 commit comments