Skip to content
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
79 changes: 7 additions & 72 deletions gittensor/cli/issue_commands/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from .help import StyledGroup
from .helpers import (
_make_contract_client,
console,
format_alpha,
get_contract_address,
Expand Down Expand Up @@ -73,19 +74,8 @@ def admin_cancel(issue_id: int, network: str, rpc_url: str, contract: str, walle
print_network_header(network_name, contract_addr)

try:
import bittensor as bt

from gittensor.validator.issue_competitions.contract_client import (
IssueCompetitionContractClient,
)

with console.status('[bold cyan]Connecting and reading issue...', spinner='dots'):
wallet = bt.Wallet(name=wallet_name, hotkey=wallet_hotkey)
subtensor = bt.Subtensor(network=ws_endpoint)
client = IssueCompetitionContractClient(
contract_address=contract_addr,
subtensor=subtensor,
)
wallet, client = _make_contract_client(contract_addr, ws_endpoint, wallet_name, wallet_hotkey)
issue = client.get_issue(issue_id)

if not issue:
Expand Down Expand Up @@ -148,19 +138,8 @@ def admin_payout(issue_id: int, network: str, rpc_url: str, contract: str, walle
print_network_header(network_name, contract_addr)

try:
import bittensor as bt

from gittensor.validator.issue_competitions.contract_client import (
IssueCompetitionContractClient,
)

with console.status('[bold cyan]Connecting and reading issue...', spinner='dots'):
wallet = bt.Wallet(name=wallet_name, hotkey=wallet_hotkey)
subtensor = bt.Subtensor(network=ws_endpoint)
client = IssueCompetitionContractClient(
contract_address=contract_addr,
subtensor=subtensor,
)
wallet, client = _make_contract_client(contract_addr, ws_endpoint, wallet_name, wallet_hotkey)
issue = client.get_issue(issue_id)

if not issue:
Expand Down Expand Up @@ -227,19 +206,8 @@ def admin_set_owner(new_owner: str, network: str, rpc_url: str, contract: str, w
)

try:
import bittensor as bt

from gittensor.validator.issue_competitions.contract_client import (
IssueCompetitionContractClient,
)

with console.status('[bold cyan]Transferring ownership...', spinner='dots'):
wallet = bt.Wallet(name=wallet_name, hotkey=wallet_hotkey)
subtensor = bt.Subtensor(network=ws_endpoint)
client = IssueCompetitionContractClient(
contract_address=contract_addr,
subtensor=subtensor,
)
wallet, client = _make_contract_client(contract_addr, ws_endpoint, wallet_name, wallet_hotkey)
result = client.set_owner(new_owner, wallet)

if result:
Expand Down Expand Up @@ -294,19 +262,8 @@ def admin_set_treasury(
)

try:
import bittensor as bt

from gittensor.validator.issue_competitions.contract_client import (
IssueCompetitionContractClient,
)

with console.status('[bold cyan]Updating treasury hotkey...', spinner='dots'):
wallet = bt.Wallet(name=wallet_name, hotkey=wallet_hotkey)
subtensor = bt.Subtensor(network=ws_endpoint)
client = IssueCompetitionContractClient(
contract_address=contract_addr,
subtensor=subtensor,
)
wallet, client = _make_contract_client(contract_addr, ws_endpoint, wallet_name, wallet_hotkey)
result = client.set_treasury_hotkey(new_treasury, wallet)

if result:
Expand Down Expand Up @@ -362,19 +319,8 @@ def admin_add_validator(hotkey: str, network: str, rpc_url: str, contract: str,
)

try:
import bittensor as bt

from gittensor.validator.issue_competitions.contract_client import (
IssueCompetitionContractClient,
)

with console.status('[bold cyan]Adding validator...', spinner='dots'):
wallet = bt.Wallet(name=wallet_name, hotkey=wallet_hotkey)
subtensor = bt.Subtensor(network=ws_endpoint)
client = IssueCompetitionContractClient(
contract_address=contract_addr,
subtensor=subtensor,
)
wallet, client = _make_contract_client(contract_addr, ws_endpoint, wallet_name, wallet_hotkey)
result = client.add_validator(hotkey, wallet)

if result:
Expand Down Expand Up @@ -431,19 +377,8 @@ def admin_remove_validator(
)

try:
import bittensor as bt

from gittensor.validator.issue_competitions.contract_client import (
IssueCompetitionContractClient,
)

with console.status('[bold cyan]Removing validator...', spinner='dots'):
wallet = bt.Wallet(name=wallet_name, hotkey=wallet_hotkey)
subtensor = bt.Subtensor(network=ws_endpoint)
client = IssueCompetitionContractClient(
contract_address=contract_addr,
subtensor=subtensor,
)
wallet, client = _make_contract_client(contract_addr, ws_endpoint, wallet_name, wallet_hotkey)
result = client.remove_validator(hotkey, wallet)

if result:
Expand Down
21 changes: 21 additions & 0 deletions gittensor/cli/issue_commands/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,27 @@ def _read_issues_from_child_storage(substrate, contract_addr: str, verbose: bool
return issues


def _make_contract_client(contract_addr: str, ws_endpoint: str, wallet_name: str, wallet_hotkey: str):
"""Instantiate a wallet and IssueCompetitionContractClient from CLI args.

Returns (wallet, client). Lazy-imports bittensor and the contract client so
that the top-level CLI remains importable without those heavy dependencies.
"""
import bittensor as bt

from gittensor.validator.issue_competitions.contract_client import (
IssueCompetitionContractClient,
)

wallet = bt.Wallet(name=wallet_name, hotkey=wallet_hotkey)
subtensor = bt.Subtensor(network=ws_endpoint)
client = IssueCompetitionContractClient(
contract_address=contract_addr,
subtensor=subtensor,
)
return wallet, client


def read_issues_from_contract(ws_endpoint: str, contract_addr: str, verbose: bool = False) -> List[Dict[str, Any]]:
"""
Read issues directly from the smart contract (no API dependency).
Expand Down
27 changes: 3 additions & 24 deletions gittensor/cli/issue_commands/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from .help import StyledGroup
from .helpers import (
_make_contract_client,
console,
get_contract_address,
print_error,
Expand Down Expand Up @@ -136,19 +137,8 @@ def val_vote_solution(
)

try:
import bittensor as bt

from gittensor.validator.issue_competitions.contract_client import (
IssueCompetitionContractClient,
)

with console.status('[bold cyan]Submitting vote...', spinner='dots'):
wallet = bt.Wallet(name=wallet_name, hotkey=wallet_hotkey)
subtensor = bt.Subtensor(network=ws_endpoint)
client = IssueCompetitionContractClient(
contract_address=contract_addr,
subtensor=subtensor,
)
wallet, client = _make_contract_client(contract_addr, ws_endpoint, wallet_name, wallet_hotkey)
result = client.vote_solution(issue_id, solver_hotkey, solver_coldkey, pr_number, wallet)

if result:
Expand Down Expand Up @@ -209,19 +199,8 @@ def val_vote_cancel_issue(
)

try:
import bittensor as bt

from gittensor.validator.issue_competitions.contract_client import (
IssueCompetitionContractClient,
)

with console.status('[bold cyan]Submitting cancel vote...', spinner='dots'):
wallet = bt.Wallet(name=wallet_name, hotkey=wallet_hotkey)
subtensor = bt.Subtensor(network=ws_endpoint)
client = IssueCompetitionContractClient(
contract_address=contract_addr,
subtensor=subtensor,
)
wallet, client = _make_contract_client(contract_addr, ws_endpoint, wallet_name, wallet_hotkey)
result = client.vote_cancel_issue(issue_id, reason, wallet)

if result:
Expand Down
Loading