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

Rename not_subtensor to subtensor #157

Merged
Merged
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
32 changes: 15 additions & 17 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ class CLIManager:
:var stake_app: the Typer app as it relates to stake commands
:var sudo_app: the Typer app as it relates to sudo commands
:var subnets_app: the Typer app as it relates to subnets commands
:var not_subtensor: the `SubtensorInterface` object passed to the various commands that require it
:var subtensor: the `SubtensorInterface` object passed to the various commands that require it
"""

not_subtensor: Optional[SubtensorInterface]
subtensor: Optional[SubtensorInterface]
app: typer.Typer
config_app: typer.Typer
wallet_app: typer.Typer
Expand Down Expand Up @@ -417,7 +417,7 @@ def __init__(self):
"COLDKEY": True,
},
}
self.not_subtensor = None
self.subtensor = None
self.config_base_path = os.path.expanduser(defaults.config.base_path)
self.config_path = os.path.expanduser(defaults.config.path)

Expand Down Expand Up @@ -741,22 +741,22 @@ def initialize_chain(
) -> SubtensorInterface:
"""
Intelligently initializes a connection to the chain, depending on the supplied (or in config) values. Sets the
`self.not_subtensor` object to this created connection.
`self.subtensor` object to this created connection.

:param network: Network name (e.g. finney, test, etc.) or
chain endpoint (e.g. ws://127.0.0.1:9945, wss://entrypoint-finney.opentensor.ai:443)
"""
if not self.not_subtensor:
if not self.subtensor:
if network:
self.not_subtensor = SubtensorInterface(network)
self.subtensor = SubtensorInterface(network)
elif self.config["network"]:
self.not_subtensor = SubtensorInterface(self.config["network"])
self.subtensor = SubtensorInterface(self.config["network"])
console.print(
f"Using the specified network [dark_orange]{self.config['network']}[/dark_orange] from config"
)
else:
self.not_subtensor = SubtensorInterface(defaults.subtensor.network)
return self.not_subtensor
self.subtensor = SubtensorInterface(defaults.subtensor.network)
return self.subtensor

def _run_command(self, cmd: Coroutine) -> None:
"""
Expand All @@ -765,16 +765,14 @@ def _run_command(self, cmd: Coroutine) -> None:

async def _run():
try:
if self.not_subtensor:
async with self.not_subtensor:
if self.subtensor:
async with self.subtensor:
result = await cmd
else:
result = await cmd
return result
except (ConnectionRefusedError, ssl.SSLError):
err_console.print(
f"Unable to connect to the chain: {self.not_subtensor}"
)
err_console.print(f"Unable to connect to the chain: {self.subtensor}")
asyncio.create_task(cmd).cancel()
raise typer.Exit()
except ConnectionClosed:
Expand Down Expand Up @@ -1429,7 +1427,7 @@ def wallet_swap_hotkey(
)
self.initialize_chain(network)
return self._run_command(
wallets.swap_hotkey(original_wallet, new_wallet, self.not_subtensor, prompt)
wallets.swap_hotkey(original_wallet, new_wallet, self.subtensor, prompt)
)

def wallet_inspect(
Expand Down Expand Up @@ -1499,7 +1497,7 @@ def wallet_inspect(
return self._run_command(
wallets.inspect(
wallet,
self.not_subtensor,
self.subtensor,
netuids_filter=netuids,
all_wallets=all_wallets,
)
Expand Down Expand Up @@ -1888,7 +1886,7 @@ def wallet_check_ck_swap(
self.verbosity_handler(quiet, verbose)
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey)
self.initialize_chain(network)
return self._run_command(wallets.check_coldkey_swap(wallet, self.not_subtensor))
return self._run_command(wallets.check_coldkey_swap(wallet, self.subtensor))

def wallet_create_wallet(
self,
Expand Down
Loading