Skip to content

Commit

Permalink
Rename not_subtensor to subtensor (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewhaleking authored Oct 2, 2024
1 parent d2c1968 commit 1a3a944
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,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 @@ -419,7 +419,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 @@ -743,22 +743,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 @@ -767,16 +767,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 @@ -1431,7 +1429,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 @@ -1501,7 +1499,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 @@ -1890,7 +1888,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

0 comments on commit 1a3a944

Please sign in to comment.