Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Aug 23, 2023
1 parent 1c2fd89 commit 9af0a3b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
11 changes: 4 additions & 7 deletions bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ def delegated_list_from_vec_u8(
]

return decoded



@dataclass
class StakeInfo:
r"""
Expand All @@ -731,13 +732,9 @@ def fix_decoded_values(cls, decoded: Any) -> "StakeInfo":
r"""Fixes the decoded values."""

return cls(
hotkey_ss58=ss58_encode(
decoded["hotkey"], bittensor.__ss58_format__
),
hotkey_ss58=ss58_encode(decoded["hotkey"], bittensor.__ss58_format__),
coldkey_ss58=ss58_encode(decoded["coldkey"], bittensor.__ss58_format__),
stake=Balance.from_rao(
decoded["stake"]
),
stake=Balance.from_rao(decoded["stake"]),
)

@classmethod
Expand Down
18 changes: 10 additions & 8 deletions bittensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ def get_stake_info_for_colkey(
) -> List[Tuple[DelegateInfo, Balance]]:
"""Returns the list of StakeInfo objects for this coldkey"""

encoded_coldkey = ss58_to_vec_u8(coldkey_ss58)
encoded_coldkey = ss58_to_vec_u8(coldkey_ss58)

hex_bytes_result = self.query_runtime_api(
runtime_api="StakeInfoRuntimeApi",
Expand All @@ -1803,19 +1803,21 @@ def get_stake_info_for_colkey(

if hex_bytes_result == None:
return None

if hex_bytes_result.startswith("0x"):
bytes_result = bytes.fromhex(hex_bytes_result[2:])
else:
bytes_result = bytes.fromhex(hex_bytes_result)

return StakeInfo.list_from_vec_u8(bytes_result)

def get_stake_info_for_colkeys(
self, coldkey_ss58_list: List[str], block: Optional[int] = None
) -> List[Tuple[DelegateInfo, Balance]]:
"""Returns the list of StakeInfo objects for all coldkeys in the list."""
encoded_coldkeys = [ss58_to_vec_u8(coldkey_ss58) for coldkey_ss58 in coldkey_ss58_list]
encoded_coldkeys = [
ss58_to_vec_u8(coldkey_ss58) for coldkey_ss58 in coldkey_ss58_list
]

hex_bytes_result = self.query_runtime_api(
runtime_api="StakeInfoRuntimeApi",
Expand All @@ -1826,14 +1828,14 @@ def get_stake_info_for_colkeys(

if hex_bytes_result == None:
return None

if hex_bytes_result.startswith("0x"):
bytes_result = bytes.fromhex(hex_bytes_result[2:])
else:
bytes_result = bytes.fromhex(hex_bytes_result)

return StakeInfo.list_from_vec_u8(bytes_result)

########################################
#### Neuron information per subnet ####
########################################
Expand Down
2 changes: 2 additions & 0 deletions bittensor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
U16_MAX = 65535
U64_MAX = 18446744073709551615


def ss58_to_vec_u8(ss58_address: str) -> List[int]:
ss58_bytes: bytes = bittensor.utils.ss58_address_to_bytes(ss58_address)
encoded_address: List[int] = [int(byte) for byte in ss58_bytes]
return encoded_address


def unbiased_topk(values, k, dim=0, sorted=True, largest=True):
r"""Selects topk as in torch.topk but does not bias lower indices when values are equal.
Args:
Expand Down

0 comments on commit 9af0a3b

Please sign in to comment.