Skip to content

Commit ac4a22b

Browse files
authored
Merge pull request #323 from input-output-hk/add_hex_data_support
feat(query): add hex fields to StakeAddrInfo
2 parents 0d482ef + 0940321 commit ac4a22b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

cardano_clusterlib/query_group.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,36 @@ def get_stake_addr_info(self, stake_addr: str) -> structs.StakeAddrInfo:
283283

284284
address_rec = next(iter(output_json))
285285
address = address_rec.get("address") or ""
286-
delegation = address_rec.get("delegation") or address_rec.get("stakeDelegation") or ""
287286
reward_account_balance = address_rec.get("rewardAccountBalance") or 0
288287
tmp_deposit = address_rec.get("stakeRegistrationDeposit") or address_rec.get(
289288
"delegationDeposit"
290289
)
291290
registration_deposit = -1 if tmp_deposit is None else tmp_deposit
292-
vote_delegation = address_rec.get("voteDelegation") or ""
291+
292+
delegation_raw = address_rec.get("delegation") or address_rec.get("stakeDelegation") or ""
293+
if isinstance(delegation_raw, dict):
294+
delegation = delegation_raw.get("stakePoolBech32") or ""
295+
delegation_hex = delegation_raw.get("stakePoolHex") or ""
296+
else:
297+
delegation = delegation_raw
298+
delegation_hex = ""
299+
300+
vote_delegation_raw = address_rec.get("voteDelegation") or ""
301+
if isinstance(vote_delegation_raw, dict):
302+
vote_delegation = vote_delegation_raw.get("keyHashBech32") or ""
303+
vote_delegation_hex = vote_delegation_raw.get("keyHashHex") or ""
304+
else:
305+
vote_delegation = vote_delegation_raw
306+
vote_delegation_hex = ""
307+
293308
return structs.StakeAddrInfo(
294309
address=address,
295310
delegation=delegation,
296311
reward_account_balance=reward_account_balance,
297312
registration_deposit=registration_deposit,
298313
vote_delegation=vote_delegation,
314+
delegation_hex=delegation_hex,
315+
vote_delegation_hex=vote_delegation_hex,
299316
)
300317

301318
def get_address_deposit(self, pparams: dict[str, tp.Any] | None = None) -> int:

cardano_clusterlib/structs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class StakeAddrInfo:
4040
reward_account_balance: int
4141
registration_deposit: int
4242
vote_delegation: str
43+
delegation_hex: str = ""
44+
vote_delegation_hex: str = ""
4345

4446
def __bool__(self) -> bool:
4547
return bool(self.address)

0 commit comments

Comments
 (0)