Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate proposal hashes in root senate-vote #77

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions bittensor_cli/src/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ async def get_proposal_call_data(p_hash: str) -> Optional[GenericCall]:
}


def _validate_proposal_hash(proposal_hash: str) -> bool:
if proposal_hash[0:2] != "0x" or len(proposal_hash) != 66:
return False
else:
return True


async def _is_senate_member(subtensor: SubtensorInterface, hotkey_ss58: str) -> bool:
"""
Checks if a given neuron (identified by its hotkey SS58 address) is a member of the Bittensor senate.
Expand Down Expand Up @@ -1040,8 +1047,13 @@ async def senate_vote(
"""Vote in Bittensor's governance protocol proposals"""

if not proposal_hash:
console.print(
'Aborting: Proposal hash not specified. View all proposals with the "proposals" command.'
err_console.print(
"Aborting: Proposal hash not specified. View all proposals with the `proposals` command."
)
return False
elif not _validate_proposal_hash(proposal_hash):
err_console.print(
"Aborting. Proposal hash is invalid. Proposal hashes should start with '0x' and be 32 bytes long"
)
return False

Expand Down
4 changes: 3 additions & 1 deletion bittensor_cli/src/commands/stake/children_hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,9 @@ def validate_take_value(take_value: float) -> bool:

def print_all_takes(takes: list[tuple[int, float]], ss58: str):
"""Print table with netuids and Takes"""
table = Table(title=f"Current Child Takes for [bright_magenta]{ss58}[/bright_magenta]")
table = Table(
title=f"Current Child Takes for [bright_magenta]{ss58}[/bright_magenta]"
)
table.add_column("Netuid", justify="center", style="cyan")
table.add_column("Take (%)", justify="right", style="magenta")

Expand Down
Loading