|
14 | 14 | from rich.console import Console |
15 | 15 | from rich.table import Table |
16 | 16 |
|
17 | | -from gittensor.cli.issue_commands.helpers import resolve_network |
18 | | -from gittensor.cli.miner_commands.helpers import _get_validator_axons |
| 17 | +from gittensor.cli.miner_commands.helpers import ( |
| 18 | + NETUID_DEFAULT, |
| 19 | + _error, |
| 20 | + _get_validator_axons, |
| 21 | + _load_config_value, |
| 22 | + _resolve_endpoint, |
| 23 | +) |
19 | 24 | from gittensor.constants import BASE_GITHUB_API_URL |
20 | 25 |
|
21 | 26 | console = Console() |
22 | 27 |
|
23 | | -# Shared CLI options for wallet/network configuration |
24 | | -NETUID_DEFAULT = 74 |
25 | | - |
26 | | - |
27 | | -def _resolve_endpoint(network: str | None, rpc_url: str | None) -> str: |
28 | | - """Resolve miner network options to a websocket endpoint.""" |
29 | | - ws_endpoint, _ = resolve_network(network=network, rpc_url=rpc_url) |
30 | | - return ws_endpoint |
31 | | - |
32 | 28 |
|
33 | 29 | @click.command() |
34 | 30 | @click.option('--wallet', 'wallet_name', default=None, help='Bittensor wallet name.') |
@@ -89,7 +85,7 @@ def miner_post(wallet_name, wallet_hotkey, netuid, network, rpc_url, pat, json_m |
89 | 85 | # 2. Resolve wallet and network |
90 | 86 | wallet_name = wallet_name or _load_config_value('wallet') or 'default' |
91 | 87 | wallet_hotkey = wallet_hotkey or _load_config_value('hotkey') or 'default' |
92 | | - ws_endpoint = _resolve_endpoint(network=network, rpc_url=rpc_url) |
| 88 | + ws_endpoint = _resolve_endpoint(network, rpc_url) |
93 | 89 |
|
94 | 90 | if not json_mode: |
95 | 91 | console.print(f'[dim]Wallet: {wallet_name}/{wallet_hotkey} | Network: {ws_endpoint} | Netuid: {netuid}[/dim]') |
@@ -223,25 +219,3 @@ def _validate_pat_locally(pat: str) -> bool: |
223 | 219 | return True |
224 | 220 | except requests.RequestException: |
225 | 221 | return False |
226 | | - |
227 | | - |
228 | | -def _load_config_value(key: str): |
229 | | - """Load a value from ~/.gittensor/config.json, or None.""" |
230 | | - from pathlib import Path |
231 | | - |
232 | | - config_file = Path.home() / '.gittensor' / 'config.json' |
233 | | - if not config_file.exists(): |
234 | | - return None |
235 | | - try: |
236 | | - config = json.loads(config_file.read_text()) |
237 | | - return config.get(key) |
238 | | - except (json.JSONDecodeError, OSError): |
239 | | - return None |
240 | | - |
241 | | - |
242 | | -def _error(msg: str, json_mode: bool): |
243 | | - """Print an error message in the appropriate format.""" |
244 | | - if json_mode: |
245 | | - click.echo(json.dumps({'success': False, 'error': msg})) |
246 | | - else: |
247 | | - console.print(f'[red]Error: {msg}[/red]') |
0 commit comments