diff --git a/LICENSE b/LICENSE
index a2837ed..d3f52c2 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,5 @@
The MIT License (MIT)
-Copyright © 2023 cyber~Congress
+Copyright © 2024 cyber~Congress
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the “Software”), to deal in the Software without restriction, including without limitation
diff --git a/bin/ctcli b/bin/ctcli
index a863004..c2ec6bd 100755
--- a/bin/ctcli
+++ b/bin/ctcli
@@ -11,7 +11,7 @@ if __name__ == '__main__':
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
diff --git a/cybertensor/__init__.py b/cybertensor/__init__.py
index f75971a..0c45e7d 100644
--- a/cybertensor/__init__.py
+++ b/cybertensor/__init__.py
@@ -2,7 +2,7 @@
# Copyright © 2021 Yuma Rao
# Copyright © 2022-2023 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -18,7 +18,6 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
-from pathlib import Path
from typing import Optional, Union
# Install and apply nest asyncio to allow the async functions
@@ -31,14 +30,13 @@
nest_asyncio.apply()
# Cybertensor code and protocol version.
-__version__ = "0.1.4"
+__version__ = "0.1.5"
version_split = __version__.split(".")
__version_as_int__ = (
(100 * int(version_split[0]))
+ (10 * int(version_split[1]))
+ (1 * int(version_split[2]))
)
-__new_signature_version__ = 360
# Rich console.
__console__ = Console()
@@ -64,7 +62,7 @@ def turn_console_on():
__console__ = Console()
-turn_console_off()
+turn_console_on()
# Logging helpers.
@@ -170,37 +168,37 @@ def __init__(
contract_address="pussy1ddwq8rxgdsm27pvpxqdy2ep9enuen6t2yhrqujvj9qwl4dtukx0s8hpka9",
)
-__contract_path__ = Path(__file__).home() / ".cybertensor/contract/cybernet.wasm"
-__contract_schema_path__ = Path(__file__).home() / ".cybertensor/contract/schema"
+__contract_path__ = None
+__contract_schema_path__ = "contract/schema"
-__default_gas__ = 1_000_000
+__default_gas__ = None
__default_transfer_gas__ = 100_000
-from .errors import *
-from .config import *
-from .keyfile import *
-from .keypair import *
-from .wallet import *
-from .utils import *
-from .utils.balance import Balance as Balance
-from .chain_data import *
-from .cwtensor import cwtensor as cwtensor
-from .cli import cli as cli, COMMANDS as ALL_COMMANDS
-from .ctlogging import logging as logging
-from .metagraph import metagraph as metagraph
-from .threadpool import PriorityThreadPoolExecutor as PriorityThreadPoolExecutor
-
-from .synapse import *
-from .stream import *
-from .tensor import *
-from .axon import axon as axon
-from .dendrite import dendrite as dendrite
+from cybertensor.errors import *
+from cybertensor.keyfile import keyfile
+from cybertensor.keypair import Keypair
+from cybertensor.wallet import Wallet
+from cybertensor.utils import *
+from cybertensor.utils.balance import Balance
+from cybertensor.chain_data import AxonInfo, NeuronInfo, NeuronInfoLite, PrometheusInfo, StakeInfo, SubnetInfo, SubnetHyperparameters
+from cybertensor.cwtensor import cwtensor
+from cybertensor.cli import cli, COMMANDS as ALL_COMMANDS
+from cybertensor.ctlogging import logging
+from cybertensor.metagraph import metagraph
+from cybertensor.threadpool import PriorityThreadPoolExecutor
+
+from cybertensor.synapse import TerminalInfo, Synapse
+from cybertensor.stream import StreamingSynapse
+from cybertensor.tensor import tensor, Tensor
+from cybertensor.axon import axon
+from cybertensor.dendrite import dendrite
+from cybertensor.config import Config
configs = [
axon.config(),
- cybertensor.config(),
+ Config(),
PriorityThreadPoolExecutor.config(),
- wallet.config(),
+ Wallet.config(),
logging.config(),
]
-defaults = config.merge_all(configs)
+defaults = Config.merge_all(configs)
diff --git a/cybertensor/axon.py b/cybertensor/axon.py
index df74730..b5cbab8 100644
--- a/cybertensor/axon.py
+++ b/cybertensor/axon.py
@@ -2,7 +2,7 @@
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -41,6 +41,8 @@
import cybertensor
from cybertensor.keypair import Keypair
+from cybertensor.wallet import Wallet
+from cybertensor.config import Config
""" Create and init Axon, which services Forward and Backward requests from other neurons.
"""
@@ -167,8 +169,8 @@ def info(self) -> "cybertensor.AxonInfo":
def __init__(
self,
- wallet: "cybertensor.wallet" = None,
- config: Optional["cybertensor.config"] = None,
+ wallet: "Wallet" = None,
+ config: Optional["Config"] = None,
port: Optional[int] = None,
ip: Optional[str] = None,
external_ip: Optional[str] = None,
@@ -177,9 +179,9 @@ def __init__(
) -> "cybertensor.axon":
r"""Creates a new cybertensor.Axon object from passed arguments.
Args:
- config (:obj:`Optional[cybertensor.config]`, `optional`):
+ config (:obj:`Optional[Config]`, `optional`):
cybertensor.axon.config()
- wallet (:obj:`Optional[cybertensor.wallet]`, `optional`):
+ wallet (:obj:`Optional[Wallet]`, `optional`):
cybertensor wallet with hotkey and coldkeypub.
port (:type:`Optional[int]`, `optional`):
Binding port.
@@ -213,7 +215,7 @@ def __init__(
self.config = config
# Get wallet or use default.
- self.wallet = wallet or cybertensor.wallet()
+ self.wallet = wallet or Wallet()
# Build axon objects.
self.uuid = str(uuid.uuid1())
@@ -409,16 +411,16 @@ def attach(
return self
@classmethod
- def config(cls) -> "cybertensor.config":
+ def config(cls) -> "Config":
"""
Parses command-line arguments to form a cybertensor configuration object.
Returns:
- cybertensor.config: Configuration object with settings from command-line arguments.
+ Config: Configuration object with settings from command-line arguments.
"""
parser = argparse.ArgumentParser()
axon.add_args(parser) # Add specific axon-related arguments
- return cybertensor.config(parser, args=[])
+ return Config(parser, args=[])
@classmethod
def help(cls):
@@ -543,12 +545,12 @@ async def some_endpoint(body_dict: dict = Depends(verify_body_integrity)):
return body_dict
@classmethod
- def check_config(cls, config: "cybertensor.config"):
+ def check_config(cls, config: "Config"):
"""
This method checks the configuration for the axon's port and wallet.
Args:
- config (cybertensor.config): The config object holding axon settings.
+ config (Config): The config object holding axon settings.
Raises:
AssertionError: If the axon or external ports are not in range [1024, 65535]
diff --git a/cybertensor/chain_data.py b/cybertensor/chain_data.py
index 7105a80..b1a7451 100644
--- a/cybertensor/chain_data.py
+++ b/cybertensor/chain_data.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -22,8 +22,8 @@
import cybertensor
# from cybertensor import SubnetHyperparameters
-from .utils import networking as net, U16_MAX, U16_NORMALIZED_FLOAT, GIGA
-from .utils.balance import Balance
+from cybertensor.utils import networking as net, U16_MAX, U16_NORMALIZED_FLOAT, GIGA
+from cybertensor.utils.balance import Balance
# Dataclasses for chain data.
diff --git a/cybertensor/cli.py b/cybertensor/cli.py
index 65079f1..7157dd4 100644
--- a/cybertensor/cli.py
+++ b/cybertensor/cli.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -21,11 +21,10 @@
from typing import List, Optional
import cybertensor
-from .commands import *
-from .commands.network import SubnetSetWeightsCommand, SubnetGetWeightsCommand
-
-# Create a console instance for CLI display.
-console = cybertensor.__console__
+from cybertensor.commands import *
+from cybertensor.commands.network import SubnetSetWeightsCommand, SubnetGetWeightsCommand
+from cybertensor.config import Config
+from cybertensor import __console__ as console
ALIAS_TO_COMMAND = {
"subnets": "subnets",
@@ -139,14 +138,14 @@ class cli:
def __init__(
self,
- config: Optional["cybertensor.config"] = None,
+ config: Optional["Config"] = None,
args: Optional[List[str]] = None,
):
"""
Initializes a cybertensor.CLI object.
Args:
- config (cybertensor.config, optional): The configuration settings for the CLI.
+ config (Config, optional): The configuration settings for the CLI.
args (List[str], optional): List of command line arguments.
"""
# Turns on console for cli.
@@ -214,7 +213,7 @@ def __create_parser__() -> "argparse.ArgumentParser":
return parser
@staticmethod
- def create_config(args: List[str]) -> "cybertensor.config":
+ def create_config(args: List[str]) -> "Config":
"""
From the argument parser, add config to cybertensor.executor and local config
@@ -222,7 +221,7 @@ def create_config(args: List[str]) -> "cybertensor.config":
args (List[str]): List of command line arguments.
Returns:
- cybertensor.config: The configuration object for Cybertensor CLI.
+ Config: The configuration object for Cybertensor CLI.
"""
parser = cli.__create_parser__()
@@ -231,15 +230,15 @@ def create_config(args: List[str]) -> "cybertensor.config":
parser.print_help()
sys.exit()
- return cybertensor.config(parser, args=args)
+ return Config(parser, args=args)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
"""
Checks if the essential configuration exists under different command
Args:
- config (cybertensor.config): The configuration settings for the CLI.
+ config (Config): The configuration settings for the CLI.
"""
# Check if command exists, if so, run the corresponding check_config.
# If command doesn't exist, inform user and exit the program.
diff --git a/cybertensor/commands/__init__.py b/cybertensor/commands/__init__.py
index 6266583..a7c2a8f 100644
--- a/cybertensor/commands/__init__.py
+++ b/cybertensor/commands/__init__.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2023 Opentensor Technologies Inc
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -63,22 +63,22 @@
}
)
-from .overview import OverviewCommand
-from .stake import StakeCommand, StakeShow
-from .unstake import UnStakeCommand
-from .register import (
+from cybertensor.commands.overview import OverviewCommand
+from cybertensor.commands.stake import StakeCommand, StakeShow
+from cybertensor.commands.unstake import UnStakeCommand
+from cybertensor.commands.register import (
PowRegisterCommand,
RegisterCommand,
# RunFaucetCommand
)
-from .delegates import (
+from cybertensor.commands.delegates import (
NominateCommand,
ListDelegatesCommand,
DelegateStakeCommand,
DelegateUnstakeCommand,
MyDelegatesCommand,
)
-from .wallets import (
+from cybertensor.commands.wallets import (
NewColdkeyCommand,
NewHotkeyCommand,
RegenColdkeyCommand,
@@ -88,12 +88,12 @@
WalletCreateCommand,
WalletBalanceCommand,
)
-from .transfer import TransferCommand
-from .inspect import InspectCommand
-from .metagraph import MetagraphCommand
-from .list import ListCommand
-# from .misc import UpdateCommand
-from .network import (
+from cybertensor.commands.transfer import TransferCommand
+from cybertensor.commands.inspect import InspectCommand
+from cybertensor.commands.metagraph import MetagraphCommand
+from cybertensor.commands.list import ListCommand
+# from cybertensor.commands.misc import UpdateCommand
+from cybertensor.commands.network import (
RegisterSubnetworkCommand,
SubnetLockCostCommand,
SubnetListCommand,
@@ -101,7 +101,7 @@
SubnetHyperparamsCommand,
SubnetGetHyperparamsCommand,
)
-from .root import (
+from cybertensor.commands.root import (
RootRegisterCommand,
RootList,
RootSetWeightsCommand,
diff --git a/cybertensor/commands/delegates.py b/cybertensor/commands/delegates.py
index 4087a61..4688f8d 100644
--- a/cybertensor/commands/delegates.py
+++ b/cybertensor/commands/delegates.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2023 OpenTensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -22,33 +22,33 @@
from typing import List, Dict, Optional
from rich.console import Text
-from rich.prompt import Confirm
from rich.prompt import Prompt
from rich.table import Table
from tqdm import tqdm
import cybertensor
-from . import defaults
-from .utils import DelegatesDetails
+from cybertensor import __console__ as console
+from cybertensor.commands import defaults
+from cybertensor.commands.utils import DelegatesDetails
+from cybertensor.config import Config
+from cybertensor.utils.balance import Balance
+from cybertensor.wallet import Wallet
-def _get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]:
+def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]:
try:
wallet_names = next(os.walk(os.path.expanduser(path)))[1]
- return [cybertensor.wallet(path=path, name=name) for name in wallet_names]
+ return [Wallet(path=path, name=name) for name in wallet_names]
except StopIteration:
# No wallet files found.
wallets = []
return wallets
-console = cybertensor.__console__
-
-
# Uses rich console to pretty print a table of delegates.
def show_delegates(
# TODO revisit
- config: "cybertensor.config",
+ config: "Config",
delegates: List["cybertensor.DelegateInfo"],
prev_delegates: Optional[List["cybertensor.DelegateInfo"]],
width: Optional[int] = None,
@@ -115,7 +115,7 @@ def show_delegates(
] = cwtensor.get_delegates()
if registered_delegate_info is None:
- cybertensor.__console__.print(
+ console.print(
":warning:[yellow]Could not get delegate info from chain.[/yellow]"
)
registered_delegate_info = {}
@@ -168,7 +168,7 @@ def show_delegates(
lambda x: x[0] == delegate.owner, delegate.nominators
), # filter for owner
),
- cybertensor.Balance.from_boot(0), # default to 0 if no owner stake.
+ Balance.from_boot(0), # default to 0 if no owner stake.
)
if delegate.hotkey in registered_delegate_info:
delegate_name = registered_delegate_info[delegate.hotkey].name
@@ -215,12 +215,12 @@ def show_delegates(
rate_change_in_stake_str,
str(delegate.registrations),
f"{delegate.take * 100:.1f}%",
- f"{cybertensor.Balance.from_gboot(delegate.total_daily_return.gboot * (1000 / (0.001 + delegate.total_stake.gboot)))!s:6.6}",
- f"{cybertensor.Balance.from_gboot(delegate.total_daily_return.gboot * (0.18)) !s:6.6}",
+ f"{Balance.from_gboot(delegate.total_daily_return.gboot * (1000 / (0.001 + delegate.total_stake.gboot)))!s:6.6}",
+ f"{Balance.from_gboot(delegate.total_daily_return.gboot * (0.18)) !s:6.6}",
str(delegate_description),
end_section=True,
)
- cybertensor.__console__.print(table)
+ console.print(table)
class DelegateStakeCommand:
@@ -258,7 +258,7 @@ class DelegateStakeCommand:
def run(cli):
"""Delegates stake to a chain delegate."""
config = cli.config.copy()
- wallet = cybertensor.wallet(config=config)
+ wallet = Wallet(config=config)
cwtensor = cybertensor.cwtensor(config=config)
cwtensor.delegate(
wallet=wallet,
@@ -287,14 +287,14 @@ def add_args(parser: argparse.ArgumentParser):
delegate_stake_parser.add_argument(
"--amount", dest="amount", type=float, required=False
)
- cybertensor.wallet.add_args(delegate_stake_parser)
+ Wallet.add_args(delegate_stake_parser)
cybertensor.cwtensor.add_args(delegate_stake_parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.get("delegatekey"):
# Check for delegates.
- with cybertensor.__console__.status(":satellite: Loading delegates..."):
+ with console.status(":satellite: Loading delegates..."):
cwtensor = cybertensor.cwtensor(config=config)
delegates: List[cybertensor.DelegateInfo] = cwtensor.get_delegates()
try:
@@ -305,7 +305,7 @@ def check_config(config: "cybertensor.config"):
prev_delegates = None
if prev_delegates is None:
- cybertensor.__console__.print(
+ console.print(
":warning: [yellow]Could not fetch delegates history[/yellow]"
)
@@ -376,7 +376,7 @@ class DelegateUnstakeCommand:
def run(cli):
"""Undelegates stake from a chain delegate."""
config = cli.config.copy()
- wallet = cybertensor.wallet(config=config)
+ wallet = Wallet(config=config)
cwtensor = cybertensor.cwtensor(config=config)
cwtensor.undelegate(
wallet=wallet,
@@ -405,18 +405,18 @@ def add_args(parser: argparse.ArgumentParser):
undelegate_stake_parser.add_argument(
"--amount", dest="amount", type=float, required=False
)
- cybertensor.wallet.add_args(undelegate_stake_parser)
+ Wallet.add_args(undelegate_stake_parser)
cybertensor.cwtensor.add_args(undelegate_stake_parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
if not config.get("delegatekey"):
# Check for delegates.
- with cybertensor.__console__.status(":satellite: Loading delegates..."):
+ with console.status(":satellite: Loading delegates..."):
cwtensor = cybertensor.cwtensor(config=config)
delegates: List[cybertensor.DelegateInfo] = cwtensor.get_delegates()
try:
@@ -427,7 +427,7 @@ def check_config(config: "cybertensor.config"):
prev_delegates = None
if prev_delegates is None:
- cybertensor.__console__.print(
+ console.print(
":warning: [yellow]Could not fetch delegates history[/yellow]"
)
@@ -503,7 +503,7 @@ def run(cli):
# cli.config.cwtensor.network = "archive"
# cli.config.cwtensor.chain_endpoint = "wss://archive.chain.opentensor.ai:443"
cwtensor = cybertensor.cwtensor(config=cli.config)
- with cybertensor.__console__.status(":satellite: Loading delegates..."):
+ with console.status(":satellite: Loading delegates..."):
# TODO added list, check get_deletates
delegates: List[cybertensor.DelegateInfo] = cwtensor.get_delegates()
try:
@@ -512,7 +512,7 @@ def run(cli):
prev_delegates = None
if prev_delegates is None:
- cybertensor.__console__.print(
+ console.print(
":warning: [yellow]Could not fetch delegates history[/yellow]"
)
@@ -531,7 +531,7 @@ def add_args(parser: argparse.ArgumentParser):
cybertensor.cwtensor.add_args(list_delegates_parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
pass
@@ -569,7 +569,7 @@ class NominateCommand:
@staticmethod
def run(cli):
r"""Nominate wallet."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=cli.config)
# Unlock the wallet.
@@ -578,7 +578,7 @@ def run(cli):
# Check if the hotkey is already a delegate.
if cwtensor.is_hotkey_delegate(wallet.hotkey.address):
- cybertensor.__console__.print(
+ console.print(
"Aborting: Hotkey {} is already a delegate.".format(
wallet.hotkey.address
)
@@ -587,7 +587,7 @@ def run(cli):
result: bool = cwtensor.nominate(wallet)
if not result:
- cybertensor.__console__.print(
+ console.print(
"Could not became a delegate on [white]{}[/white]".format(
cwtensor.network
)
@@ -596,13 +596,13 @@ def run(cli):
# Check if we are a delegate.
is_delegate: bool = cwtensor.is_hotkey_delegate(wallet.hotkey.address)
if not is_delegate:
- cybertensor.__console__.print(
+ console.print(
"Could not became a delegate on [white]{}[/white]".format(
cwtensor.network
)
)
return
- cybertensor.__console__.print(
+ console.print(
"Successfully became a delegate on [white]{}[/white]".format(
cwtensor.network
)
@@ -613,11 +613,11 @@ def add_args(parser: argparse.ArgumentParser):
nominate_parser = parser.add_parser(
"nominate", help="""Become a delegate on the network"""
)
- cybertensor.wallet.add_args(nominate_parser)
+ Wallet.add_args(nominate_parser)
cybertensor.cwtensor.add_args(nominate_parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -676,7 +676,7 @@ def run(cli):
if config.get("all", d=None) is True:
wallets = _get_coldkey_wallets_for_path(config.wallet.path)
else:
- wallets = [cybertensor.wallet(config=config)]
+ wallets = [Wallet(config=config)]
cwtensor = cybertensor.cwtensor(config=config)
table = Table(show_footer=True, pad_edge=False, box=None, expand=True)
@@ -751,7 +751,7 @@ def run(cli):
] = cwtensor.get_delegates()
if registered_delegate_info is None:
- cybertensor.__console__.print(
+ console.print(
":warning:[yellow]Could not get delegate info from chain.[/yellow]"
)
registered_delegate_info = {}
@@ -765,7 +765,7 @@ def run(cli):
delegate[0].nominators,
), # filter for owner
),
- cybertensor.Balance.from_boot(0), # default to 0 if no owner stake.
+ Balance.from_boot(0), # default to 0 if no owner stake.
)
if delegate[0].hotkey in registered_delegate_info:
delegate_name = registered_delegate_info[
@@ -803,8 +803,8 @@ def run(cli):
# f'{delegate_profile.description:140.140}',
)
- cybertensor.__console__.print(table)
- cybertensor.__console__.print(f"Total delegated {cwtensor.giga_token_symbol}: {total_delegated}")
+ console.print(table)
+ console.print(f"Total delegated {cwtensor.giga_token_symbol}: {total_delegated}")
@staticmethod
def add_args(parser: argparse.ArgumentParser):
@@ -818,11 +818,11 @@ def add_args(parser: argparse.ArgumentParser):
help="""Check all coldkey wallets.""",
default=False,
)
- cybertensor.wallet.add_args(delegate_stake_parser)
+ Wallet.add_args(delegate_stake_parser)
cybertensor.cwtensor.add_args(delegate_stake_parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if (
not config.get("all", d=None)
and not config.is_set("wallet.name")
diff --git a/cybertensor/commands/inspect.py b/cybertensor/commands/inspect.py
index e01972b..815a769 100644
--- a/cybertensor/commands/inspect.py
+++ b/cybertensor/commands/inspect.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -25,23 +25,25 @@
from tqdm import tqdm
import cybertensor
-from . import defaults
-from .utils import get_delegates_details, DelegatesDetails
+from cybertensor import __console__ as console
+from cybertensor.commands import defaults
+from cybertensor.commands.utils import get_delegates_details, DelegatesDetails
+from cybertensor.config import Config
+from cybertensor.utils.balance import Balance
+from cybertensor.wallet import Wallet
-console = cybertensor.__console__
-
-def _get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]:
+def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]:
try:
wallet_names = next(os.walk(os.path.expanduser(path)))[1]
- return [cybertensor.wallet(path=path, name=name) for name in wallet_names]
+ return [Wallet(path=path, name=name) for name in wallet_names]
except StopIteration:
# No wallet files found.
wallets = []
return wallets
-def _get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]:
+def _get_hotkey_wallets_for_wallet(wallet) -> List["Wallet"]:
hotkey_wallets = []
hotkeys_path = wallet.path + "/" + wallet.name + "/hotkeys"
try:
@@ -50,7 +52,7 @@ def _get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]:
hotkey_files = []
for hotkey_file_name in hotkey_files:
try:
- hotkey_for_name = cybertensor.wallet(
+ hotkey_for_name = Wallet(
path=wallet.path, name=wallet.name, hotkey=hotkey_file_name
)
if (
@@ -110,7 +112,7 @@ def run(cli) -> None:
if cli.config.get("all", d=False) is True:
wallets = _get_coldkey_wallets_for_path(cli.config.wallet.path)
else:
- wallets = [cybertensor.wallet(config=cli.config)]
+ wallets = [Wallet(config=cli.config)]
cwtensor = cybertensor.cwtensor(config=cli.config)
netuids = cwtensor.get_all_subnet_netuids()
@@ -119,7 +121,7 @@ def run(cli) -> None:
Dict[str, DelegatesDetails]
] = get_delegates_details(url=cybertensor.__delegates_details_url__)
if registered_delegate_info is None:
- cybertensor.__console__.print(
+ console.print(
":warning:[yellow]Could not get delegate info from chain.[/yellow]"
)
registered_delegate_info = {}
@@ -159,7 +161,7 @@ def run(cli) -> None:
)
for wallet in tqdm(wallets):
delegates: List[
- Tuple[cybertensor.DelegateInfo, cybertensor.Balance]
+ Tuple[cybertensor.DelegateInfo, Balance]
] = cwtensor.get_delegated(delegatee=wallet.coldkeypub.address)
if not wallet.coldkeypub_file.exists_on_device():
continue
@@ -211,13 +213,13 @@ def run(cli) -> None:
str(netuid),
f"{hotkey_name}{neuron.hotkey}",
str(neuron.stake),
- str(cybertensor.Balance.from_boot(neuron.emission)),
+ str(Balance.from_boot(neuron.emission)),
)
- cybertensor.__console__.print(table)
+ console.print(table)
@staticmethod
- def check_config(config: "cybertensor.config") -> None:
+ def check_config(config: "Config") -> None:
if (
not config.get("all", d=None)
and not config.is_set("wallet.name")
@@ -238,5 +240,5 @@ def add_args(parser: argparse.ArgumentParser) -> None:
default=False,
)
- cybertensor.wallet.add_args(inspect_parser)
+ Wallet.add_args(inspect_parser)
cybertensor.cwtensor.add_args(inspect_parser)
diff --git a/cybertensor/commands/list.py b/cybertensor/commands/list.py
index b8d2ea8..de1f53f 100644
--- a/cybertensor/commands/list.py
+++ b/cybertensor/commands/list.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -23,8 +23,8 @@
from rich.tree import Tree
import cybertensor
-
-console = cybertensor.__console__
+from cybertensor.config import Config
+from cybertensor.wallet import Wallet
class ListCommand:
@@ -64,7 +64,7 @@ def run(cli):
root = Tree("Wallets")
for w_name in wallets:
- wallet_for_name = cybertensor.wallet(path=cli.config.wallet.path, name=w_name)
+ wallet_for_name = Wallet(path=cli.config.wallet.path, name=w_name)
try:
if (
wallet_for_name.coldkeypub_file.exists_on_device()
@@ -84,7 +84,7 @@ def run(cli):
hotkeys = next(os.walk(os.path.expanduser(hotkeys_path)))
if len(hotkeys) > 1:
for h_name in hotkeys[2]:
- hotkey_for_name = cybertensor.wallet(
+ hotkey_for_name = Wallet(
path=cli.config.wallet.path, name=w_name, hotkey=h_name
)
try:
@@ -108,11 +108,11 @@ def run(cli):
print(root)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
pass
@staticmethod
def add_args(parser: argparse.ArgumentParser):
list_parser = parser.add_parser("list", help="""List wallets""")
- cybertensor.wallet.add_args(list_parser)
+ Wallet.add_args(list_parser)
cybertensor.cwtensor.add_args(list_parser)
diff --git a/cybertensor/commands/metagraph.py b/cybertensor/commands/metagraph.py
index f56ad23..c2be7e8 100644
--- a/cybertensor/commands/metagraph.py
+++ b/cybertensor/commands/metagraph.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -21,9 +21,11 @@
from rich.table import Table
import cybertensor
-from .utils import check_netuid_set
+from cybertensor import __console__ as console
+from cybertensor.commands.utils import check_netuid_set
+from cybertensor.config import Config
+from cybertensor.utils.balance import Balance
-console = cybertensor.__console__
# TODO change tokens in table to boot and gigaboot
class MetagraphCommand:
@@ -74,7 +76,6 @@ class MetagraphCommand:
@staticmethod
def run(cli):
r"""Prints an entire metagraph."""
- console = cybertensor.__console__
cwtensor = cybertensor.cwtensor(config=cli.config)
console.print(
":satellite: Syncing with chain: [white]{}[/white] ...".format(
@@ -84,10 +85,10 @@ def run(cli):
metagraph: cybertensor.metagraph = cwtensor.metagraph(netuid=cli.config.netuid)
metagraph.save()
difficulty = cwtensor.difficulty(cli.config.netuid)
- # subnet_emission = cybertensor.Balance.from_gboot(
+ # subnet_emission = Balance.from_gboot(
# cwtensor.get_emission_value_by_subnet(cli.config.netuid)
# )
- total_issuance = cybertensor.Balance.from_boot(cwtensor.total_issuance().boot)
+ total_issuance = Balance.from_boot(cwtensor.total_issuance().boot)
TABLE_DATA = []
total_stake = 0.0
@@ -137,7 +138,7 @@ def run(cli):
metagraph.block.item(),
sum(metagraph.active.tolist()),
metagraph.n.item(),
- cybertensor.Balance.from_gboot(total_stake),
+ Balance.from_gboot(total_stake),
total_issuance,
difficulty,
)
@@ -233,7 +234,7 @@ def run(cli):
console.print(table)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
check_netuid_set(config, cwtensor=cybertensor.cwtensor(config=config))
@staticmethod
diff --git a/cybertensor/commands/network.py b/cybertensor/commands/network.py
index ca93014..ba25df2 100644
--- a/cybertensor/commands/network.py
+++ b/cybertensor/commands/network.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -26,10 +26,11 @@
from rich.table import Table
import cybertensor
-from . import defaults
-from .utils import DelegatesDetails, check_netuid_set
-
-console = cybertensor.__console__
+from cybertensor import __console__ as console
+from cybertensor.commands import defaults
+from cybertensor.commands.utils import DelegatesDetails, check_netuid_set
+from cybertensor.config import Config
+from cybertensor.wallet import Wallet
class RegisterSubnetworkCommand:
@@ -70,7 +71,7 @@ class RegisterSubnetworkCommand:
def run(cli):
r"""Register a subnetwork"""
config = cli.config.copy()
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=config)
# Call register command.
cwtensor.register_subnetwork(
@@ -79,7 +80,7 @@ def run(cli):
)
@classmethod
- def check_config(cls, config: "cybertensor.config"):
+ def check_config(cls, config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -91,7 +92,7 @@ def add_args(cls, parser: argparse.ArgumentParser):
help="""Create a new cybertensor subnetwork on this chain.""",
)
- cybertensor.wallet.add_args(parser)
+ Wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)
class SubnetLockCostCommand:
@@ -127,17 +128,17 @@ def run(cli):
config = cli.config.copy()
cwtensor = cybertensor.cwtensor(config=config)
try:
- cybertensor.__console__.print(
+ console.print(
f"Subnet lock cost: [green]{cybertensor.utils.balance.Balance( cwtensor.get_subnet_burn_cost() )}[/green]"
)
except Exception as e:
- cybertensor.__console__.print(
+ console.print(
f"Subnet lock cost: [red]Failed to get subnet lock cost[/red]"
f"Error: {e}"
)
@classmethod
- def check_config(cls, config: "cybertensor.config"):
+ def check_config(cls, config: "Config"):
pass
@classmethod
@@ -246,10 +247,10 @@ def run(cli):
table.add_column("[overline white]METADATA", style="white")
for row in rows:
table.add_row(*row)
- cybertensor.__console__.print(table)
+ console.print(table)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
pass
@staticmethod
@@ -296,7 +297,7 @@ class SubnetSudoCommand:
def run(cli):
r"""Set subnet hyperparameters."""
config = cli.config.copy()
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=config)
print("\n")
SubnetHyperparamsCommand.run(cli)
@@ -316,7 +317,7 @@ def run(cli):
)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -333,7 +334,7 @@ def add_args(parser: argparse.ArgumentParser):
parser.add_argument("--param", dest="param", type=str, required=False)
parser.add_argument("--value", dest="value", type=str, required=False)
- cybertensor.wallet.add_args(parser)
+ Wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)
@@ -401,10 +402,10 @@ def run(cli):
for param in subnet.__dict__:
table.add_row(" " + param, str(subnet.__dict__[param]))
- cybertensor.__console__.print(table)
+ console.print(table)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("netuid") and not config.no_prompt:
check_netuid_set(config, cybertensor.cwtensor(config=config))
@@ -482,10 +483,10 @@ def run(cli):
for param in subnet.__dict__:
table.add_row(param, str(subnet.__dict__[param]))
- cybertensor.__console__.print(table)
+ console.print(table)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("netuid") and not config.no_prompt:
check_netuid_set(config, cybertensor.cwtensor(config=config))
@@ -512,7 +513,7 @@ class SubnetSetWeightsCommand:
@staticmethod
def run(cli):
r"""Set weights for subnetwork."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=cli.config)
# Get values if not set.
@@ -559,11 +560,11 @@ def add_args(parser: argparse.ArgumentParser):
"--netuid", dest="netuid", type=int, required=False, default=False
)
- cybertensor.wallet.add_args(parser)
+ Wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -674,7 +675,7 @@ def run(cli):
table.box = None
table.pad_edge = False
table.width = None
- cybertensor.__console__.print(table)
+ console.print(table)
@staticmethod
def add_args(parser: argparse.ArgumentParser):
@@ -685,10 +686,10 @@ def add_args(parser: argparse.ArgumentParser):
"--netuid", dest="netuid", type=int, required=False, default=False
)
- cybertensor.wallet.add_args(parser)
+ Wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("netuid") and not config.no_prompt:
check_netuid_set(config, cybertensor.cwtensor(config=config))
diff --git a/cybertensor/commands/overview.py b/cybertensor/commands/overview.py
index 7081d11..29e82a9 100644
--- a/cybertensor/commands/overview.py
+++ b/cybertensor/commands/overview.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -18,7 +18,6 @@
import argparse
from collections import defaultdict
-from concurrent.futures import ProcessPoolExecutor
from typing import List, Optional, Dict, Tuple
from fuzzywuzzy import fuzz
@@ -28,14 +27,16 @@
from tqdm import tqdm
import cybertensor
-from . import defaults
-from .utils import (
+from cybertensor import __console__ as console
+from cybertensor.commands import defaults
+from cybertensor.commands.utils import (
get_hotkey_wallets_for_wallet,
get_coldkey_wallets_for_path,
get_all_wallets_for_path,
)
-
-console = cybertensor.__console__
+from cybertensor.config import Config
+from cybertensor.utils.balance import Balance
+from cybertensor.wallet import Wallet
class OverviewCommand:
@@ -77,14 +78,13 @@ class OverviewCommand:
"""
@staticmethod
- def run(cli: "cybertensor.cli"):
+ def run(cli: "cybertensor.cli", max_len_netuids: int = 5, max_len_keys: int = 5):
r"""Prints an overview for the wallet's colkey."""
- console = cybertensor.__console__
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor: "cybertensor.cwtensor" = cybertensor.cwtensor(config=cli.config)
all_hotkeys = []
- total_balance = cybertensor.Balance(0)
+ total_balance = Balance(0)
# We are printing for every coldkey.
if cli.config.get("all", d=None):
@@ -100,7 +100,7 @@ def run(cli: "cybertensor.cli"):
all_hotkeys = get_all_wallets_for_path(cli.config.wallet.path)
else:
# We are only printing keys for a single coldkey
- coldkey_wallet = cybertensor.wallet(config=cli.config)
+ coldkey_wallet = Wallet(config=cli.config)
if (
coldkey_wallet.coldkeypub_file.exists_on_device()
and not coldkey_wallet.coldkeypub_file.is_encrypted()
@@ -148,7 +148,7 @@ def run(cli: "cybertensor.cli"):
all_wallet_names = set([wallet.name for wallet in all_hotkeys])
all_coldkey_wallets = [
- cybertensor.wallet(name=wallet_name) for wallet_name in all_wallet_names
+ Wallet(name=wallet_name, path=cli.config.wallet.path) for wallet_name in all_wallet_names
]
hotkey_coldkey_to_hotkey_wallet = {}
@@ -168,36 +168,25 @@ def run(cli: "cybertensor.cli"):
)
)
):
- # Create a copy of the config without the parser and formatter_class.
- ## This is needed to pass to the ProcessPoolExecutor, which cannot pickle the parser.
- copy_config = cli.config.copy()
- copy_config["__parser"] = None
- copy_config["formatter_class"] = None
# Pull neuron info for all keys.
## Max len(netuids) or 5 threads.
- with ProcessPoolExecutor(max_workers=max(len(netuids), 5)) as executor:
- results = executor.map(
- OverviewCommand._get_neurons_for_netuid,
- [(copy_config, netuid, all_hotkey_addresses) for netuid in netuids],
- )
- executor.shutdown(wait=True) # wait for all complete
-
- for result in results:
- netuid, neurons_result, err_msg = result
- if err_msg is not None:
- console.print(err_msg)
- if len(neurons_result) == 0:
- # Remove netuid from overview if no neurons are found.
- netuids.remove(netuid)
- del neurons[str(netuid)]
- else:
- # Add neurons to overview.
- neurons[str(netuid)] = neurons_result
+ for netuid in netuids[:max_len_netuids]:
+ netuid, neurons_result, err_msg = \
+ OverviewCommand._get_neurons_for_netuid((cli.config, netuid, all_hotkey_addresses))
+ if err_msg is not None:
+ console.print(err_msg)
+ if len(neurons_result) == 0:
+ # Remove netuid from overview if no neurons are found.
+ netuids.remove(netuid)
+ del neurons[str(netuid)]
+ else:
+ # Add neurons to overview.
+ neurons[str(netuid)] = neurons_result
total_coldkey_stake_from_metagraph = defaultdict(
- lambda: cybertensor.Balance(0.0)
+ lambda: Balance(0.0)
)
checked_hotkeys = set()
for neuron_list in neurons.values():
@@ -239,21 +228,11 @@ def run(cli: "cybertensor.cli"):
if "-1" not in neurons:
neurons["-1"] = []
- # Use process pool to check each coldkey wallet for de-registered stake.
- with ProcessPoolExecutor(
- max_workers=max(len(coldkeys_to_check), 5)
- ) as executor:
- results = executor.map(
- OverviewCommand._get_de_registered_stake_for_coldkey_wallet,
- [
- (cli.config, all_hotkey_addresses, coldkey_wallet)
- for coldkey_wallet in coldkeys_to_check
- ],
- )
- executor.shutdown(wait=True) # wait for all complete
+ for coldkey_wallet in coldkeys_to_check:
+ coldkey_wallet, de_registered_stake, err_msg = \
+ OverviewCommand._get_de_registered_stake_for_coldkey_wallet(
+ (cli.config, all_hotkey_addresses, coldkey_wallet))
- for result in results:
- coldkey_wallet, de_registered_stake, err_msg = result
if err_msg is not None:
console.print(err_msg)
@@ -268,16 +247,16 @@ def run(cli: "cybertensor.cli"):
de_registered_neuron.coldkey = (
coldkey_wallet.coldkeypub.address
)
- de_registered_neuron.total_stake = cybertensor.Balance(our_stake)
+ de_registered_neuron.total_stake = Balance(our_stake)
de_registered_neurons.append(de_registered_neuron)
# Add this hotkey to the wallets dict
- wallet_ = cybertensor.Wallet(
+ wallet_ = Wallet(
name=wallet,
)
wallet_.hotkey = hotkey_addr
- wallet.hotkey_str = hotkey_addr[:5] # Max length of 5 characters
+ wallet.hotkey_str = hotkey_addr[:max_len_keys] # Max length of 5 characters
hotkey_coldkey_to_hotkey_wallet[hotkey_addr][
coldkey_wallet.coldkeypub.address
] = wallet_
@@ -552,7 +531,7 @@ def overview_sort_function(row):
@staticmethod
def _get_neurons_for_netuid(
- args_tuple: Tuple["cybertensor.Config", int, List[str]]
+ args_tuple: Tuple["Config", int, List[str]]
) -> Tuple[int, List["cybertensor.NeuronInfoLite"], Optional[str]]:
cwtensor_config, netuid, hot_wallets = args_tuple
@@ -580,12 +559,12 @@ def _get_neurons_for_netuid(
def _get_de_registered_stake_for_coldkey_wallet(
args_tuple,
) -> Tuple[
- "cybertensor.Wallet", List[Tuple[str, "cybertensor.Balance"]], Optional[str]
+ "Wallet", List[Tuple[str, "Balance"]], Optional[str]
]:
cwtensor_config, all_hotkey_addresses, coldkey_wallet = args_tuple
# List of (hotkey_addr, our_stake) tuples.
- result: List[Tuple[str, "cybertensor.Balance"]] = []
+ result: List[Tuple[str, "Balance"]] = []
try:
cwtensor = cybertensor.cwtensor(config=cwtensor_config)
@@ -686,11 +665,11 @@ def add_args(parser: argparse.ArgumentParser):
help="""Set the netuid(s) to filter by.""",
default=[],
)
- cybertensor.wallet.add_args(overview_parser)
+ Wallet.add_args(overview_parser)
cybertensor.cwtensor.add_args(overview_parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if (
not config.is_set("wallet.name")
and not config.no_prompt
diff --git a/cybertensor/commands/register.py b/cybertensor/commands/register.py
index 4c62c5c..3009af5 100644
--- a/cybertensor/commands/register.py
+++ b/cybertensor/commands/register.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -22,11 +22,12 @@
from rich.prompt import Prompt, Confirm
import cybertensor
-from cybertensor import Balance
from cybertensor.commands import defaults
from cybertensor.commands.utils import check_netuid_set, check_for_cuda_reg_config
-
-console = cybertensor.__console__
+from cybertensor import __console__ as console
+from cybertensor.config import Config
+from cybertensor.utils.balance import Balance
+from cybertensor.wallet import Wallet
class RegisterCommand:
@@ -63,12 +64,12 @@ class RegisterCommand:
def run(cli):
r"""Register neuron by recycling some GBOOT."""
config = cli.config.copy()
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=config)
# Verify subnet exists
if not cwtensor.subnet_exists(netuid=cli.config.netuid):
- cybertensor.__console__.print(
+ console.print(
f"[red]Subnet {cli.config.netuid} does not exist[/red]"
)
sys.exit(1)
@@ -79,7 +80,7 @@ def run(cli):
# Check balance is sufficient
if balance < current_recycle:
- cybertensor.__console__.print(
+ console.print(
f"[red]Insufficient balance {balance} to register neuron. Current recycle is {current_recycle}[/red]"
)
sys.exit(1)
@@ -101,7 +102,7 @@ def run(cli):
)
@classmethod
- def check_config(cls, config: "cybertensor.config"):
+ def check_config(cls, config: "Config"):
check_netuid_set(config, cwtensor=cybertensor.cwtensor(config=config))
if not config.is_set("wallet.name") and not config.no_prompt:
@@ -124,7 +125,7 @@ def add_args(cls, parser: argparse.ArgumentParser):
default=argparse.SUPPRESS,
)
- cybertensor.wallet.add_args(register_parser)
+ Wallet.add_args(register_parser)
cybertensor.cwtensor.add_args(register_parser)
@@ -165,12 +166,12 @@ class PowRegisterCommand:
@staticmethod
def run(cli):
r"""Register neuron."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=cli.config)
# Verify subnet exists
if not cwtensor.subnet_exists(netuid=cli.config.netuid):
- cybertensor.__console__.print(
+ console.print(
f"[red]Subnet {cli.config.netuid} does not exist[/red]"
)
sys.exit(1)
@@ -279,11 +280,11 @@ def add_args(parser: argparse.ArgumentParser):
required=False,
)
- cybertensor.wallet.add_args(register_parser)
+ Wallet.add_args(register_parser)
cybertensor.cwtensor.add_args(register_parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
# if (
# not config.is_set("cwtensor.network")
# and not config.no_prompt
diff --git a/cybertensor/commands/root.py b/cybertensor/commands/root.py
index fdd37b8..b792bc7 100644
--- a/cybertensor/commands/root.py
+++ b/cybertensor/commands/root.py
@@ -27,10 +27,11 @@
from rich.table import Table
import cybertensor
-from . import defaults
-from .utils import DelegatesDetails
-
-console = cybertensor.__console__
+from cybertensor.commands import defaults
+from cybertensor.commands.utils import DelegatesDetails
+from cybertensor import __console__ as console
+from cybertensor.config import Config
+from cybertensor.wallet import Wallet
class RootRegisterCommand:
@@ -55,7 +56,7 @@ class RootRegisterCommand:
@staticmethod
def run(cli):
r"""Register to root network."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=cli.config)
cwtensor.root_register(wallet=wallet, prompt=not cli.config.no_prompt)
@@ -66,11 +67,11 @@ def add_args(parser: argparse.ArgumentParser):
"register", help="""Register a wallet to the root network."""
)
- cybertensor.wallet.add_args(parser)
+ Wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -189,7 +190,7 @@ def run(cli):
table.box = None
table.pad_edge = False
table.width = None
- cybertensor.__console__.print(table)
+ console.print(table)
@staticmethod
def add_args(parser: argparse.ArgumentParser):
@@ -197,7 +198,7 @@ def add_args(parser: argparse.ArgumentParser):
cybertensor.cwtensor.add_args(parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
pass
@@ -225,7 +226,7 @@ class RootSetWeightsCommand:
@staticmethod
def run(cli):
r"""Set weights for root network."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=cli.config)
subnets: List[cybertensor.SubnetInfo] = cwtensor.get_all_subnets_info()
@@ -276,11 +277,11 @@ def add_args(parser: argparse.ArgumentParser):
parser.add_argument("--netuids", dest="netuids", type=str, required=False)
parser.add_argument("--weights", dest="weights", type=str, required=False)
- cybertensor.wallet.add_args(parser)
+ Wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -387,7 +388,7 @@ def run(cli):
table.box = None
table.pad_edge = False
table.width = None
- cybertensor.__console__.print(table)
+ console.print(table)
@staticmethod
def add_args(parser: argparse.ArgumentParser):
@@ -395,9 +396,9 @@ def add_args(parser: argparse.ArgumentParser):
"get_weights", help="""Get weights for root network."""
)
- cybertensor.wallet.add_args(parser)
+ Wallet.add_args(parser)
cybertensor.cwtensor.add_args(parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
pass
diff --git a/cybertensor/commands/stake.py b/cybertensor/commands/stake.py
index 770f0fe..399fc66 100644
--- a/cybertensor/commands/stake.py
+++ b/cybertensor/commands/stake.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -21,11 +21,9 @@
from rich.prompt import Confirm
-import cybertensor
+from cybertensor.commands.utils import get_hotkey_wallets_for_wallet
+from cybertensor.config import Config
from cybertensor.utils.balance import Balance
-from .utils import get_hotkey_wallets_for_wallet
-
-console = cybertensor.__console__
class StakeCommand:
@@ -60,14 +58,14 @@ class StakeCommand:
def run(cli):
r"""Stake token of amount to hotkey(s)."""
config = cli.config.copy()
- wallet = cybertensor.wallet(config=config)
+ wallet = Wallet(config=config)
cwtensor = cybertensor.cwtensor(config=config)
# Get the hotkey_names (if any) and the hotkeys.
hotkeys_to_stake_to: List[Tuple[Optional[str], str]] = []
if config.get("all_hotkeys"):
# Stake to all hotkeys.
- all_hotkeys: List[cybertensor.wallet] = get_hotkey_wallets_for_wallet(
+ all_hotkeys: List[Wallet] = get_hotkey_wallets_for_wallet(
wallet=wallet
)
# Get the hotkeys to exclude. (d)efault to no exclusions.
@@ -88,7 +86,7 @@ def run(cli):
else:
# If the hotkey is not a valid address, we assume it is a hotkey name.
# We then get the hotkey from the wallet and add it to the list.
- wallet_ = cybertensor.wallet(
+ wallet_ = Wallet(
config=config, hotkey=hotkey_or_hotkey_name
)
hotkeys_to_stake_to.append(
@@ -102,7 +100,7 @@ def run(cli):
hotkeys_to_stake_to = [(None, hotkey_or_name)]
else:
# Hotkey is not a valid address, so we assume it is a hotkey name.
- wallet_ = cybertensor.wallet(config=config, hotkey=hotkey_or_name)
+ wallet_ = Wallet(config=config, hotkey=hotkey_or_name)
hotkeys_to_stake_to = [
(wallet_.hotkey_str, wallet_.hotkey.address)
]
@@ -111,7 +109,7 @@ def run(cli):
# so we stake to that single hotkey.
assert config.wallet.hotkey is not None
hotkeys_to_stake_to = [
- (None, cybertensor.wallet(config=config).hotkey.address)
+ (None, Wallet(config=config).hotkey.address)
]
# Get coldkey balance
@@ -124,13 +122,13 @@ def run(cli):
# Hotkey is not registered.
if len(hotkeys_to_stake_to) == 1:
# Only one hotkey, error
- cybertensor.__console__.print(
+ console.print(
f"[red]Hotkey [bold]{hotkey[1]}[/bold] is not registered. Aborting.[/red]"
)
return None
else:
# Otherwise, print warning and skip
- cybertensor.__console__.print(
+ console.print(
f"[yellow]Hotkey [bold]{hotkey[1]}[/bold] is not registered. Skipping.[/yellow]"
)
continue
@@ -161,7 +159,7 @@ def run(cli):
if len(final_hotkeys) == 0:
# No hotkeys to stake to.
- cybertensor.__console__.print(
+ console.print(
"Not enough balance to stake to any hotkeys or max_stake is less than current stake."
)
return None
@@ -199,7 +197,7 @@ def run(cli):
)
@classmethod
- def check_config(cls, config: "cybertensor.config"):
+ def check_config(cls, config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
@@ -267,11 +265,13 @@ def add_args(cls, parser: argparse.ArgumentParser):
default=False,
help="""To specify all hotkeys. Specifying hotkeys will exclude them from this all.""",
)
- cybertensor.wallet.add_args(stake_parser)
+ Wallet.add_args(stake_parser)
cybertensor.cwtensor.add_args(stake_parser)
### Stake list.
+import os
+from typing import List, Tuple, Optional, Dict
import argparse
import cybertensor
from tqdm import tqdm
@@ -279,26 +279,24 @@ def add_args(cls, parser: argparse.ArgumentParser):
from rich.prompt import Prompt
from typing import Union
from concurrent.futures import ThreadPoolExecutor
-from .utils import DelegatesDetails
-from . import defaults
-console = cybertensor.__console__
-
-import os
-from typing import List, Tuple, Optional, Dict
+from cybertensor.commands.utils import DelegatesDetails
+from cybertensor.commands import defaults
+from cybertensor.wallet import Wallet
+from cybertensor import __console__ as console
-def _get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]:
+def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]:
try:
wallet_names = next(os.walk(os.path.expanduser(path)))[1]
- return [cybertensor.wallet(path=path, name=name) for name in wallet_names]
+ return [Wallet(path=path, name=name) for name in wallet_names]
except StopIteration:
# No wallet files found.
wallets = []
return wallets
-def _get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]:
+def _get_hotkey_wallets_for_wallet(wallet) -> List["Wallet"]:
hotkey_wallets = []
hotkeys_path = wallet.path + "/" + wallet.name + "/hotkeys"
try:
@@ -307,7 +305,7 @@ def _get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]:
hotkey_files = []
for hotkey_file_name in hotkey_files:
try:
- hotkey_for_name = cybertensor.wallet(
+ hotkey_for_name = Wallet(
path=wallet.path, name=wallet.name, hotkey=hotkey_file_name
)
if (
@@ -353,7 +351,7 @@ def run(cli):
if cli.config.get("all", d=False) is True:
wallets = _get_coldkey_wallets_for_path(cli.config.wallet.path)
else:
- wallets = [cybertensor.wallet(config=cli.config)]
+ wallets = [Wallet(config=cli.config)]
# TODO revisit
# registered_delegate_info: Optional[
@@ -521,10 +519,10 @@ def get_all_wallet_accounts(
table.add_row(
"", "", value["name"], value["stake"], str(value["rate"]) + "/d"
)
- cybertensor.__console__.print(table)
+ console.print(table)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if (
not config.get("all", d=None)
and not config.is_set("wallet.name")
@@ -545,5 +543,5 @@ def add_args(parser: argparse.ArgumentParser):
default=False,
)
- cybertensor.wallet.add_args(list_parser)
+ Wallet.add_args(list_parser)
cybertensor.cwtensor.add_args(list_parser)
diff --git a/cybertensor/commands/transfer.py b/cybertensor/commands/transfer.py
index 5ae3957..75b71b0 100644
--- a/cybertensor/commands/transfer.py
+++ b/cybertensor/commands/transfer.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -23,9 +23,10 @@
from rich.prompt import Prompt
import cybertensor
-from . import defaults
-
-console = cybertensor.__console__
+from cybertensor import __console__ as console
+from cybertensor.commands import defaults
+from cybertensor.config import Config
+from cybertensor.wallet import Wallet
class TransferCommand:
@@ -56,7 +57,7 @@ class TransferCommand:
@staticmethod
def run(cli):
r"""Transfer token of amount to destination."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
cwtensor = cybertensor.cwtensor(config=cli.config)
cwtensor.transfer(
wallet=wallet,
@@ -67,7 +68,7 @@ def run(cli):
)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -82,11 +83,11 @@ def check_config(config: "cybertensor.config"):
# Get current balance and print to user.
if not config.no_prompt:
- wallet = cybertensor.wallet(config=config)
+ wallet = Wallet(config=config)
cwtensor = cybertensor.cwtensor(config=config)
- with cybertensor.__console__.status(":satellite: Checking Balance..."):
+ with console.status(":satellite: Checking Balance..."):
account_balance = cwtensor.get_balance(wallet.coldkeypub.address)
- cybertensor.__console__.print(
+ console.print(
"Balance: [green]{}[/green]".format(account_balance)
)
@@ -99,12 +100,12 @@ def check_config(config: "cybertensor.config"):
if config.amount <= 0:
raise ValueError("Zero or negative amount")
except ValueError:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark:[red] Invalid GBOOT amount[/red] [bold white]{amount}[/bold white]"
)
sys.exit()
else:
- cybertensor.__console__.print(
+ console.print(
":cross_mark:[red] Invalid GBOOT amount[/red] [bold white]{}[/bold white]".format(
None
)
@@ -121,5 +122,5 @@ def add_args(parser: argparse.ArgumentParser):
"--amount", dest="amount", type=float, required=False
)
- cybertensor.wallet.add_args(transfer_parser)
+ Wallet.add_args(transfer_parser)
cybertensor.cwtensor.add_args(transfer_parser)
diff --git a/cybertensor/commands/unstake.py b/cybertensor/commands/unstake.py
index 4be7c61..ae5cfe3 100644
--- a/cybertensor/commands/unstake.py
+++ b/cybertensor/commands/unstake.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -23,11 +23,12 @@
from tqdm import tqdm
import cybertensor
+from cybertensor import __console__ as console
+from cybertensor.commands import defaults
+from cybertensor.commands.utils import get_hotkey_wallets_for_wallet
+from cybertensor.config import Config
from cybertensor.utils.balance import Balance
-from . import defaults
-from .utils import get_hotkey_wallets_for_wallet
-
-console = cybertensor.__console__
+from cybertensor.wallet import Wallet
class UnStakeCommand:
@@ -58,7 +59,7 @@ class UnStakeCommand:
"""
@classmethod
- def check_config(cls, config: "cybertensor.config"):
+ def check_config(cls, config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -148,14 +149,14 @@ def add_args(command_parser):
default=False,
help="""To specify all hotkeys. Specifying hotkeys will exclude them from this all.""",
)
- cybertensor.wallet.add_args(unstake_parser)
+ Wallet.add_args(unstake_parser)
cybertensor.cwtensor.add_args(unstake_parser)
@staticmethod
def run(cli):
r"""Unstake token of amount from hotkey(s)."""
config = cli.config.copy()
- wallet = cybertensor.wallet(config=config)
+ wallet = Wallet(config=config)
cwtensor: cybertensor.cwtensor = cybertensor.cwtensor(config=cli.config)
# Get the hotkey_names (if any) and the hotkeys.
@@ -165,7 +166,7 @@ def run(cli):
hotkeys_to_unstake_from = [(None, cli.config.get("hotkey_address"))]
elif cli.config.get("all_hotkeys"):
# Stake to all hotkeys.
- all_hotkeys: List[cybertensor.wallet] = get_hotkey_wallets_for_wallet(
+ all_hotkeys: List[Wallet] = get_hotkey_wallets_for_wallet(
wallet=wallet
)
# Get the hotkeys to exclude. (d)efault to no exclusions.
@@ -186,7 +187,7 @@ def run(cli):
else:
# If the hotkey is not a valid address, we assume it is a hotkey name.
# We then get the hotkey from the wallet and add it to the list.
- wallet_ = cybertensor.wallet(
+ wallet_ = Wallet(
config=cli.config, hotkey=hotkey_or_hotkey_name
)
hotkeys_to_unstake_from.append(
@@ -200,7 +201,7 @@ def run(cli):
hotkeys_to_unstake_from = [(None, hotkey_or_name)]
else:
# Hotkey is not a valid address, so we assume it is a hotkey name.
- wallet_ = cybertensor.wallet(
+ wallet_ = Wallet(
config=cli.config, hotkey=hotkey_or_name
)
hotkeys_to_unstake_from = [
@@ -211,7 +212,7 @@ def run(cli):
# so we stake to that single hotkey.
assert cli.config.wallet.hotkey is not None
hotkeys_to_unstake_from = [
- (None, cybertensor.wallet(config=cli.config).hotkey.address)
+ (None, Wallet(config=cli.config).hotkey.address)
]
final_hotkeys: List[Tuple[str, str]] = []
@@ -247,7 +248,7 @@ def run(cli):
if len(final_hotkeys) == 0:
# No hotkeys to unstake from.
- cybertensor.__console__.print(
+ console.print(
"Not enough stake to unstake from any hotkeys or max_stake is more than current stake."
)
return None
diff --git a/cybertensor/commands/utils.py b/cybertensor/commands/utils.py
index 5a8d01f..260ec62 100644
--- a/cybertensor/commands/utils.py
+++ b/cybertensor/commands/utils.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -26,9 +26,10 @@
from rich.prompt import Confirm, PromptBase
import cybertensor
-from . import defaults
-
-console = cybertensor.__console__
+from cybertensor import __console__ as console
+from cybertensor.commands import defaults
+from cybertensor.config import Config
+from cybertensor.wallet import Wallet
class IntListPrompt(PromptBase):
@@ -47,7 +48,7 @@ def check_choice(self, value: str) -> bool:
def check_netuid_set(
- config: "cybertensor.config",
+ config: "Config",
cwtensor: "cybertensor.cwtensor",
allow_none: bool = False,
):
@@ -78,7 +79,7 @@ def check_netuid_set(
raise ValueError('netuid must be an integer or "None" (if applicable)')
-def check_for_cuda_reg_config(config: "cybertensor.config") -> None:
+def check_for_cuda_reg_config(config: "Config") -> None:
"""Checks, when CUDA is available, if the user would like to register with their CUDA device."""
if torch.cuda.is_available():
if not config.no_prompt:
@@ -131,7 +132,7 @@ def check_for_cuda_reg_config(config: "cybertensor.config") -> None:
config.pow_register.cuda.use_cuda = defaults.pow_register.cuda.use_cuda
-def get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]:
+def get_hotkey_wallets_for_wallet(wallet) -> List["Wallet"]:
hotkey_wallets = []
hotkeys_path = wallet.path + "/" + wallet.name + "/hotkeys"
try:
@@ -140,7 +141,7 @@ def get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]:
hotkey_files = []
for hotkey_file_name in hotkey_files:
try:
- hotkey_for_name = cybertensor.wallet(
+ hotkey_for_name = Wallet(
path=wallet.path, name=wallet.name, hotkey=hotkey_file_name
)
if (
@@ -153,17 +154,17 @@ def get_hotkey_wallets_for_wallet(wallet) -> List["cybertensor.wallet"]:
return hotkey_wallets
-def get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]:
+def get_coldkey_wallets_for_path(path: str) -> List["Wallet"]:
try:
wallet_names = next(os.walk(os.path.expanduser(path)))[1]
- return [cybertensor.wallet(path=path, name=name) for name in wallet_names]
+ return [Wallet(path=path, name=name) for name in wallet_names]
except StopIteration:
# No wallet files found.
wallets = []
return wallets
-def get_all_wallets_for_path(path: str) -> List["cybertensor.wallet"]:
+def get_all_wallets_for_path(path: str) -> List["Wallet"]:
all_wallets = []
cold_wallets = get_coldkey_wallets_for_path(path)
for cold_wallet in cold_wallets:
diff --git a/cybertensor/commands/wallets.py b/cybertensor/commands/wallets.py
index 6f3bbed..039078c 100644
--- a/cybertensor/commands/wallets.py
+++ b/cybertensor/commands/wallets.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -25,7 +25,10 @@
from rich.table import Table
import cybertensor
-from . import defaults
+from cybertensor import __console__ as console
+from cybertensor.commands import defaults
+from cybertensor.config import Config
+from cybertensor.wallet import Wallet
# TODO rewrite to use raw pubkey against hex or rewrite keypair/keyfile to use hex
@@ -57,7 +60,7 @@ class RegenColdkeyCommand:
def run(cli):
r"""Creates a new coldkey under this wallet."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
json_str: Optional[str] = None
json_password: Optional[str] = None
@@ -80,7 +83,7 @@ def run(cli):
)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -150,7 +153,7 @@ def add_args(parser: argparse.ArgumentParser):
action="store_false",
help="""Overwrite the old coldkey with the newly generated coldkey""",
)
- cybertensor.wallet.add_args(regen_coldkey_parser)
+ Wallet.add_args(regen_coldkey_parser)
cybertensor.cwtensor.add_args(regen_coldkey_parser)
@@ -178,7 +181,7 @@ class RegenColdkeypubCommand:
def run(cli):
r"""Creates a new coldkeypub under this wallet."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
wallet.regenerate_coldkeypub(
address=cli.config.get("address"),
public_key=cli.config.get("public_key_hex"),
@@ -186,7 +189,7 @@ def run(cli):
)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -235,7 +238,7 @@ def add_args(parser: argparse.ArgumentParser):
action="store_true",
help="""Overwrite the old coldkeypub file with the newly generated coldkeypub""",
)
- cybertensor.wallet.add_args(regen_coldkeypub_parser)
+ Wallet.add_args(regen_coldkeypub_parser)
cybertensor.cwtensor.add_args(regen_coldkeypub_parser)
@@ -267,7 +270,7 @@ class RegenHotkeyCommand:
def run(cli):
r"""Creates a new coldkey under this wallet."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
json_str: Optional[str] = None
json_password: Optional[str] = None
@@ -290,7 +293,7 @@ def run(cli):
)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -365,7 +368,7 @@ def add_args(parser: argparse.ArgumentParser):
default=False,
help="""Overwrite the old hotkey with the newly generated hotkey""",
)
- cybertensor.wallet.add_args(regen_hotkey_parser)
+ Wallet.add_args(regen_hotkey_parser)
cybertensor.cwtensor.add_args(regen_hotkey_parser)
@@ -393,7 +396,7 @@ class NewHotkeyCommand:
def run(cli):
"""Creates a new hotke under this wallet."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
wallet.create_new_hotkey(
n_words=cli.config.n_words,
use_password=cli.config.use_password,
@@ -401,7 +404,7 @@ def run(cli):
)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -442,7 +445,7 @@ def add_args(parser: argparse.ArgumentParser):
default=False,
help="""Overwrite the old hotkey with the newly generated hotkey""",
)
- cybertensor.wallet.add_args(new_hotkey_parser)
+ Wallet.add_args(new_hotkey_parser)
cybertensor.cwtensor.add_args(new_hotkey_parser)
@@ -470,7 +473,7 @@ class NewColdkeyCommand:
def run(cli):
r"""Creates a new coldkey under this wallet."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
wallet.create_new_coldkey(
n_words=cli.config.n_words,
use_password=cli.config.use_password,
@@ -478,7 +481,7 @@ def run(cli):
)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -515,7 +518,7 @@ def add_args(parser: argparse.ArgumentParser):
default=False,
help="""Overwrite the old coldkey with the newly generated coldkey""",
)
- cybertensor.wallet.add_args(new_coldkey_parser)
+ Wallet.add_args(new_coldkey_parser)
cybertensor.cwtensor.add_args(new_coldkey_parser)
@@ -544,7 +547,7 @@ class WalletCreateCommand:
def run(cli):
r"""Creates a new coldkey and hotkey under this wallet."""
- wallet = cybertensor.wallet(config=cli.config)
+ wallet = Wallet(config=cli.config)
wallet.create_new_coldkey(
n_words=cli.config.n_words,
use_password=cli.config.use_password,
@@ -557,7 +560,7 @@ def run(cli):
)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default=defaults.wallet.name)
config.wallet.name = str(wallet_name)
@@ -603,15 +606,15 @@ def add_args(parser: argparse.ArgumentParser):
default=False,
help="""Overwrite the old hotkey with the newly generated hotkey""",
)
- cybertensor.wallet.add_args(new_coldkey_parser)
+ Wallet.add_args(new_coldkey_parser)
cybertensor.cwtensor.add_args(new_coldkey_parser)
-def _get_coldkey_wallets_for_path(path: str) -> List["cybertensor.wallet"]:
+def _get_coldkey_wallets_for_path(path: str) -> List["Wallet"]:
"""Get all coldkey wallet names from path."""
try:
wallet_names = next(os.walk(os.path.expanduser(path)))[1]
- return [cybertensor.wallet(path=path, name=name) for name in wallet_names]
+ return [Wallet(path=path, name=name) for name in wallet_names]
except StopIteration:
# No wallet files found.
wallets = []
@@ -646,7 +649,7 @@ def run(cli):
if config.get("all", d=False) is True:
wallets = _get_coldkey_wallets_for_path(config.wallet.path)
else:
- wallets = [cybertensor.wallet(config=config)]
+ wallets = [Wallet(config=config)]
for wallet in wallets:
print("\n===== ", wallet, " =====")
@@ -666,11 +669,11 @@ def add_args(parser: argparse.ArgumentParser):
help="""Set true to avoid prompting the user.""",
default=False,
)
- cybertensor.wallet.add_args(update_wallet_parser)
+ Wallet.add_args(update_wallet_parser)
cybertensor.cwtensor.add_args(update_wallet_parser)
@staticmethod
- def check_config(config: "cybertensor.Config"):
+ def check_config(config: "Config"):
if config.get("all", d=False) is False:
if not config.no_prompt:
if Confirm.ask("Do you want to update all legacy wallets?"):
@@ -804,18 +807,18 @@ def run(cli):
table.box = None
table.pad_edge = False
table.width = None
- cybertensor.__console__.print(table)
+ console.print(table)
@staticmethod
def add_args(parser: argparse.ArgumentParser):
balance_parser = parser.add_parser(
- "balance", help="""Checks the balance of the wallet."""
+ "balance", help="""Checks balances of wallets in the wallet path."""
)
- cybertensor.wallet.add_args(balance_parser)
+ Wallet.add_args(balance_parser)
cybertensor.cwtensor.add_args(balance_parser)
@staticmethod
- def check_config(config: "cybertensor.config"):
+ def check_config(config: "Config"):
if not config.is_set("wallet.path") and not config.no_prompt:
path = Prompt.ask("Enter wallets path", default=defaults.wallet.path)
config.wallet.path = str(path)
diff --git a/cybertensor/config.py b/cybertensor/config.py
index ca05f79..b0fc335 100644
--- a/cybertensor/config.py
+++ b/cybertensor/config.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -33,7 +33,7 @@ class InvalidConfigFile(Exception):
pass
-class config(DefaultMunch):
+class Config(DefaultMunch):
"""
Implementation of the config class, which manages the config of different cybertensor modules.
"""
@@ -52,7 +52,7 @@ class config(DefaultMunch):
Default value for the Config. Defaults to None.
This default will be returned for attributes that are undefined.
Returns:
- config (cybertensor.config):
+ config (Config):
Nested config object created from parser arguments.
"""
@@ -130,7 +130,7 @@ def __init__(
config_file_path = None
# Parse args not strict
- config_params = config.__parse_args__(args=args, parser=parser, strict=False)
+ config_params = Config.__parse_args__(args=args, parser=parser, strict=False)
# 2. Optionally check for --strict
## strict=True when passed in OR when --strict is set
@@ -147,12 +147,12 @@ def __init__(
print("Error in loading: {} using default parser settings".format(e))
# 2. Continue with loading in params.
- params = config.__parse_args__(args=args, parser=parser, strict=strict)
+ params = Config.__parse_args__(args=args, parser=parser, strict=strict)
_config = self
# Splits params and add to config
- config.__split_params__(params=params, _config=_config)
+ Config.__split_params__(params=params, _config=_config)
# Make the is_set map
_config["__is_set"] = {}
@@ -203,7 +203,7 @@ def __init__(
cmd_parser._defaults.clear() # Needed for quirk of argparse
## Reparse the args, but this time with the defaults as argparse.SUPPRESS
- params_no_defaults = config.__parse_args__(
+ params_no_defaults = Config.__parse_args__(
args=args, parser=parser_no_defaults, strict=strict
)
@@ -220,8 +220,8 @@ def __init__(
}
@staticmethod
- def __split_params__(params: argparse.Namespace, _config: "config"):
- # Splits params on dot syntax i.e neuron.axon_port and adds to _config
+ def __split_params__(params: argparse.Namespace, _config: "Config"):
+ # Splits params on dot syntax i.e. neuron.axon_port and adds to _config
for arg_key, arg_val in params.__dict__.items():
split_keys = arg_key.split(".")
head = _config
@@ -233,7 +233,7 @@ def __split_params__(params: argparse.Namespace, _config: "config"):
head = getattr(head, keys[0])
keys = keys[1:]
else:
- head[keys[0]] = config()
+ head[keys[0]] = Config()
head = head[keys[0]]
keys = keys[1:]
if len(keys) == 1:
@@ -268,11 +268,11 @@ def __parse_args__(
return params
- def __deepcopy__(self, memo) -> "config":
+ def __deepcopy__(self, memo) -> "Config":
_default = self.__default__
config_state = self.__getstate__()
- config_copy = config()
+ config_copy = Config()
memo[id(self)] = config_copy
config_copy.__setstate__(config_state)
@@ -293,7 +293,7 @@ def _remove_private_keys(d):
d.pop("__is_set", None)
for k, v in list(d.items()):
if isinstance(v, dict):
- config._remove_private_keys(v)
+ Config._remove_private_keys(v)
return d
def __str__(self) -> str:
@@ -301,10 +301,10 @@ def __str__(self) -> str:
visible = copy.deepcopy(self.toDict())
visible.pop("__parser", None)
visible.pop("__is_set", None)
- cleaned = config._remove_private_keys(visible)
+ cleaned = Config._remove_private_keys(visible)
return "\n" + yaml.dump(cleaned, sort_keys=False)
- def copy(self) -> "config":
+ def copy(self) -> "Config":
return copy.deepcopy(self)
def to_string(self, items) -> str:
@@ -341,7 +341,7 @@ def merge(self, b):
self = self._merge(self, b)
@classmethod
- def merge_all(cls, configs: List["config"]) -> "config":
+ def merge_all(cls, configs: List["Config"]) -> "Config":
"""
Merge all configs in the list into one config.
If there is a conflict, the value from the last configuration in the list will take precedence.
@@ -372,7 +372,7 @@ def is_set(self, param_name: str) -> bool:
T = TypeVar("T", bound="DefaultConfig")
-class DefaultConfig(config):
+class DefaultConfig(Config):
"""
A Config with a set of default values.
"""
diff --git a/cybertensor/contract/schema/execute.json b/cybertensor/contract/schema/execute.json
new file mode 100644
index 0000000..a9599e1
--- /dev/null
+++ b/cybertensor/contract/schema/execute.json
@@ -0,0 +1,1453 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "title": "ExecuteMsg",
+ "oneOf": [
+ {
+ "type": "object",
+ "required": [
+ "activate"
+ ],
+ "properties": {
+ "activate": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "deactivate"
+ ],
+ "properties": {
+ "deactivate": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "block_step"
+ ],
+ "properties": {
+ "block_step": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "set_weights"
+ ],
+ "properties": {
+ "set_weights": {
+ "type": "object",
+ "required": [
+ "dests",
+ "netuid",
+ "version_key",
+ "weights"
+ ],
+ "properties": {
+ "dests": {
+ "type": "array",
+ "items": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "version_key": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "weights": {
+ "type": "array",
+ "items": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "become_delegate"
+ ],
+ "properties": {
+ "become_delegate": {
+ "type": "object",
+ "required": [
+ "hotkey"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "add_stake"
+ ],
+ "properties": {
+ "add_stake": {
+ "type": "object",
+ "required": [
+ "hotkey"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "remove_stake"
+ ],
+ "properties": {
+ "remove_stake": {
+ "type": "object",
+ "required": [
+ "amount",
+ "hotkey"
+ ],
+ "properties": {
+ "amount": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "serve_axon"
+ ],
+ "properties": {
+ "serve_axon": {
+ "type": "object",
+ "required": [
+ "ip",
+ "ip_type",
+ "netuid",
+ "placeholder1",
+ "placeholder2",
+ "port",
+ "protocol",
+ "version"
+ ],
+ "properties": {
+ "ip": {
+ "type": "integer",
+ "format": "uint128",
+ "minimum": 0.0
+ },
+ "ip_type": {
+ "type": "integer",
+ "format": "uint8",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "placeholder1": {
+ "type": "integer",
+ "format": "uint8",
+ "minimum": 0.0
+ },
+ "placeholder2": {
+ "type": "integer",
+ "format": "uint8",
+ "minimum": 0.0
+ },
+ "port": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "protocol": {
+ "type": "integer",
+ "format": "uint8",
+ "minimum": 0.0
+ },
+ "version": {
+ "type": "integer",
+ "format": "uint32",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "serve_prometheus"
+ ],
+ "properties": {
+ "serve_prometheus": {
+ "type": "object",
+ "required": [
+ "ip",
+ "ip_type",
+ "netuid",
+ "port",
+ "version"
+ ],
+ "properties": {
+ "ip": {
+ "type": "integer",
+ "format": "uint128",
+ "minimum": 0.0
+ },
+ "ip_type": {
+ "type": "integer",
+ "format": "uint8",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "port": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "version": {
+ "type": "integer",
+ "format": "uint32",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "register"
+ ],
+ "properties": {
+ "register": {
+ "type": "object",
+ "required": [
+ "block_number",
+ "coldkey",
+ "hotkey",
+ "netuid",
+ "nonce",
+ "work"
+ ],
+ "properties": {
+ "block_number": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "coldkey": {
+ "type": "string"
+ },
+ "hotkey": {
+ "type": "string"
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "nonce": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "work": {
+ "type": "array",
+ "items": {
+ "type": "integer",
+ "format": "uint8",
+ "minimum": 0.0
+ }
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "root_register"
+ ],
+ "properties": {
+ "root_register": {
+ "type": "object",
+ "required": [
+ "hotkey"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "burned_register"
+ ],
+ "properties": {
+ "burned_register": {
+ "type": "object",
+ "required": [
+ "hotkey",
+ "netuid"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "register_network"
+ ],
+ "properties": {
+ "register_network": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "dissolve_network"
+ ],
+ "properties": {
+ "dissolve_network": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_register"
+ ],
+ "properties": {
+ "sudo_register": {
+ "type": "object",
+ "required": [
+ "coldkey",
+ "hotkey",
+ "netuid"
+ ],
+ "properties": {
+ "coldkey": {
+ "type": "string"
+ },
+ "hotkey": {
+ "type": "string"
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_default_take"
+ ],
+ "properties": {
+ "sudo_set_default_take": {
+ "type": "object",
+ "required": [
+ "default_take"
+ ],
+ "properties": {
+ "default_take": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_serving_rate_limit"
+ ],
+ "properties": {
+ "sudo_set_serving_rate_limit": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "serving_rate_limit"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "serving_rate_limit": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_tx_rate_limit"
+ ],
+ "properties": {
+ "sudo_set_tx_rate_limit": {
+ "type": "object",
+ "required": [
+ "tx_rate_limit"
+ ],
+ "properties": {
+ "tx_rate_limit": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_max_burn"
+ ],
+ "properties": {
+ "sudo_set_max_burn": {
+ "type": "object",
+ "required": [
+ "max_burn",
+ "netuid"
+ ],
+ "properties": {
+ "max_burn": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_min_burn"
+ ],
+ "properties": {
+ "sudo_set_min_burn": {
+ "type": "object",
+ "required": [
+ "min_burn",
+ "netuid"
+ ],
+ "properties": {
+ "min_burn": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_max_difficulty"
+ ],
+ "properties": {
+ "sudo_set_max_difficulty": {
+ "type": "object",
+ "required": [
+ "max_difficulty",
+ "netuid"
+ ],
+ "properties": {
+ "max_difficulty": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_min_difficulty"
+ ],
+ "properties": {
+ "sudo_set_min_difficulty": {
+ "type": "object",
+ "required": [
+ "min_difficulty",
+ "netuid"
+ ],
+ "properties": {
+ "min_difficulty": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_weights_set_rate_limit"
+ ],
+ "properties": {
+ "sudo_set_weights_set_rate_limit": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "weights_set_rate_limit"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "weights_set_rate_limit": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_weights_version_key"
+ ],
+ "properties": {
+ "sudo_set_weights_version_key": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "weights_version_key"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "weights_version_key": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_bonds_moving_average"
+ ],
+ "properties": {
+ "sudo_set_bonds_moving_average": {
+ "type": "object",
+ "required": [
+ "bonds_moving_average",
+ "netuid"
+ ],
+ "properties": {
+ "bonds_moving_average": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_max_allowed_validators"
+ ],
+ "properties": {
+ "sudo_set_max_allowed_validators": {
+ "type": "object",
+ "required": [
+ "max_allowed_validators",
+ "netuid"
+ ],
+ "properties": {
+ "max_allowed_validators": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_difficulty"
+ ],
+ "properties": {
+ "sudo_set_difficulty": {
+ "type": "object",
+ "required": [
+ "difficulty",
+ "netuid"
+ ],
+ "properties": {
+ "difficulty": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_adjustment_interval"
+ ],
+ "properties": {
+ "sudo_set_adjustment_interval": {
+ "type": "object",
+ "required": [
+ "adjustment_interval",
+ "netuid"
+ ],
+ "properties": {
+ "adjustment_interval": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_target_registrations_per_interval"
+ ],
+ "properties": {
+ "sudo_set_target_registrations_per_interval": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "target_registrations_per_interval"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "target_registrations_per_interval": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_activity_cutoff"
+ ],
+ "properties": {
+ "sudo_set_activity_cutoff": {
+ "type": "object",
+ "required": [
+ "activity_cutoff",
+ "netuid"
+ ],
+ "properties": {
+ "activity_cutoff": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_rho"
+ ],
+ "properties": {
+ "sudo_set_rho": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "rho"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "rho": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_kappa"
+ ],
+ "properties": {
+ "sudo_set_kappa": {
+ "type": "object",
+ "required": [
+ "kappa",
+ "netuid"
+ ],
+ "properties": {
+ "kappa": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_max_allowed_uids"
+ ],
+ "properties": {
+ "sudo_set_max_allowed_uids": {
+ "type": "object",
+ "required": [
+ "max_allowed_uids",
+ "netuid"
+ ],
+ "properties": {
+ "max_allowed_uids": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_min_allowed_weights"
+ ],
+ "properties": {
+ "sudo_set_min_allowed_weights": {
+ "type": "object",
+ "required": [
+ "min_allowed_weights",
+ "netuid"
+ ],
+ "properties": {
+ "min_allowed_weights": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_validator_prune_len"
+ ],
+ "properties": {
+ "sudo_set_validator_prune_len": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "validator_prune_len"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "validator_prune_len": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_immunity_period"
+ ],
+ "properties": {
+ "sudo_set_immunity_period": {
+ "type": "object",
+ "required": [
+ "immunity_period",
+ "netuid"
+ ],
+ "properties": {
+ "immunity_period": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_max_weight_limit"
+ ],
+ "properties": {
+ "sudo_set_max_weight_limit": {
+ "type": "object",
+ "required": [
+ "max_weight_limit",
+ "netuid"
+ ],
+ "properties": {
+ "max_weight_limit": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_max_registrations_per_block"
+ ],
+ "properties": {
+ "sudo_set_max_registrations_per_block": {
+ "type": "object",
+ "required": [
+ "max_registrations_per_block",
+ "netuid"
+ ],
+ "properties": {
+ "max_registrations_per_block": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_total_issuance"
+ ],
+ "properties": {
+ "sudo_set_total_issuance": {
+ "type": "object",
+ "required": [
+ "total_issuance"
+ ],
+ "properties": {
+ "total_issuance": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_tempo"
+ ],
+ "properties": {
+ "sudo_set_tempo": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "tempo"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "tempo": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_rao_recycled"
+ ],
+ "properties": {
+ "sudo_set_rao_recycled": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "rao_recycled"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "rao_recycled": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_registration_allowed"
+ ],
+ "properties": {
+ "sudo_set_registration_allowed": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "registration_allowed"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "registration_allowed": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_adjustment_alpha"
+ ],
+ "properties": {
+ "sudo_set_adjustment_alpha": {
+ "type": "object",
+ "required": [
+ "adjustment_alpha",
+ "netuid"
+ ],
+ "properties": {
+ "adjustment_alpha": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_subnet_owner_cut"
+ ],
+ "properties": {
+ "sudo_set_subnet_owner_cut": {
+ "type": "object",
+ "required": [
+ "cut"
+ ],
+ "properties": {
+ "cut": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_network_rate_limit"
+ ],
+ "properties": {
+ "sudo_set_network_rate_limit": {
+ "type": "object",
+ "required": [
+ "rate_limit"
+ ],
+ "properties": {
+ "rate_limit": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_network_immunity_period"
+ ],
+ "properties": {
+ "sudo_set_network_immunity_period": {
+ "type": "object",
+ "required": [
+ "immunity_period"
+ ],
+ "properties": {
+ "immunity_period": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_network_min_lock_cost"
+ ],
+ "properties": {
+ "sudo_set_network_min_lock_cost": {
+ "type": "object",
+ "required": [
+ "lock_cost"
+ ],
+ "properties": {
+ "lock_cost": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_subnet_limit"
+ ],
+ "properties": {
+ "sudo_set_subnet_limit": {
+ "type": "object",
+ "required": [
+ "max_subnets"
+ ],
+ "properties": {
+ "max_subnets": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_lock_reduction_interval"
+ ],
+ "properties": {
+ "sudo_set_lock_reduction_interval": {
+ "type": "object",
+ "required": [
+ "interval"
+ ],
+ "properties": {
+ "interval": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_validator_permit_for_uid"
+ ],
+ "properties": {
+ "sudo_set_validator_permit_for_uid": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "permit",
+ "uid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "permit": {
+ "type": "boolean"
+ },
+ "uid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_block_emission"
+ ],
+ "properties": {
+ "sudo_set_block_emission": {
+ "type": "object",
+ "required": [
+ "emission"
+ ],
+ "properties": {
+ "emission": {
+ "type": "integer",
+ "format": "uint64",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "sudo_set_subnet_metadata"
+ ],
+ "properties": {
+ "sudo_set_subnet_metadata": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "particle"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "particle": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ }
+ ]
+}
diff --git a/cybertensor/contract/schema/instantiate.json b/cybertensor/contract/schema/instantiate.json
new file mode 100644
index 0000000..1352613
--- /dev/null
+++ b/cybertensor/contract/schema/instantiate.json
@@ -0,0 +1,6 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "title": "InstantiateMsg",
+ "type": "object",
+ "additionalProperties": false
+}
diff --git a/cybertensor/contract/schema/query.json b/cybertensor/contract/schema/query.json
new file mode 100644
index 0000000..d2bf796
--- /dev/null
+++ b/cybertensor/contract/schema/query.json
@@ -0,0 +1,856 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "title": "QueryMsg",
+ "oneOf": [
+ {
+ "type": "object",
+ "required": [
+ "get_delegates"
+ ],
+ "properties": {
+ "get_delegates": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_delegate"
+ ],
+ "properties": {
+ "get_delegate": {
+ "type": "object",
+ "required": [
+ "delegate"
+ ],
+ "properties": {
+ "delegate": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_delegated"
+ ],
+ "properties": {
+ "get_delegated": {
+ "type": "object",
+ "required": [
+ "delegatee"
+ ],
+ "properties": {
+ "delegatee": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_neurons_lite"
+ ],
+ "properties": {
+ "get_neurons_lite": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_neuron_lite"
+ ],
+ "properties": {
+ "get_neuron_lite": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "uid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "uid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_neurons"
+ ],
+ "properties": {
+ "get_neurons": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_neuron"
+ ],
+ "properties": {
+ "get_neuron": {
+ "type": "object",
+ "required": [
+ "netuid",
+ "uid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ },
+ "uid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_subnet_info"
+ ],
+ "properties": {
+ "get_subnet_info": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_subnets_info"
+ ],
+ "properties": {
+ "get_subnets_info": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_subnet_hyperparams"
+ ],
+ "properties": {
+ "get_subnet_hyperparams": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_stake_info_for_coldkey"
+ ],
+ "properties": {
+ "get_stake_info_for_coldkey": {
+ "type": "object",
+ "required": [
+ "coldkey"
+ ],
+ "properties": {
+ "coldkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_stake_info_for_coldkeys"
+ ],
+ "properties": {
+ "get_stake_info_for_coldkeys": {
+ "type": "object",
+ "required": [
+ "coldkeys"
+ ],
+ "properties": {
+ "coldkeys": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_total_stake_for_hotkey"
+ ],
+ "properties": {
+ "get_total_stake_for_hotkey": {
+ "type": "object",
+ "required": [
+ "address"
+ ],
+ "properties": {
+ "address": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_total_stake_for_coldkey"
+ ],
+ "properties": {
+ "get_total_stake_for_coldkey": {
+ "type": "object",
+ "required": [
+ "address"
+ ],
+ "properties": {
+ "address": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_stake_for_coldkey_and_hotkey"
+ ],
+ "properties": {
+ "get_stake_for_coldkey_and_hotkey": {
+ "type": "object",
+ "required": [
+ "coldkey",
+ "hotkey"
+ ],
+ "properties": {
+ "coldkey": {
+ "type": "string"
+ },
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_hotkey_owner"
+ ],
+ "properties": {
+ "get_hotkey_owner": {
+ "type": "object",
+ "required": [
+ "hotkey"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_uid_for_hotkey_on_subnet"
+ ],
+ "properties": {
+ "get_uid_for_hotkey_on_subnet": {
+ "type": "object",
+ "required": [
+ "hotkey",
+ "netuid"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_netuids_for_hotkey"
+ ],
+ "properties": {
+ "get_netuids_for_hotkey": {
+ "type": "object",
+ "required": [
+ "hotkey"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_hotkey_exist"
+ ],
+ "properties": {
+ "get_hotkey_exist": {
+ "type": "object",
+ "required": [
+ "hotkey"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_stake"
+ ],
+ "properties": {
+ "get_stake": {
+ "type": "object",
+ "required": [
+ "hotkey"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_delegate_take"
+ ],
+ "properties": {
+ "get_delegate_take": {
+ "type": "object",
+ "required": [
+ "hotkey"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_subnet_exist"
+ ],
+ "properties": {
+ "get_subnet_exist": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_subnet_owner"
+ ],
+ "properties": {
+ "get_subnet_owner": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_max_weight_limit"
+ ],
+ "properties": {
+ "get_max_weight_limit": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_min_allowed_weights"
+ ],
+ "properties": {
+ "get_min_allowed_weights": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_burn"
+ ],
+ "properties": {
+ "get_burn": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_difficulty"
+ ],
+ "properties": {
+ "get_difficulty": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_tempo"
+ ],
+ "properties": {
+ "get_tempo": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_emission_value_by_subnet"
+ ],
+ "properties": {
+ "get_emission_value_by_subnet": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_network_registration_cost"
+ ],
+ "properties": {
+ "get_network_registration_cost": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_total_networks"
+ ],
+ "properties": {
+ "get_total_networks": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_networks_added"
+ ],
+ "properties": {
+ "get_networks_added": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_all_subnet_netuids"
+ ],
+ "properties": {
+ "get_all_subnet_netuids": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_total_issuance"
+ ],
+ "properties": {
+ "get_total_issuance": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_total_stake"
+ ],
+ "properties": {
+ "get_total_stake": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_tx_rate_limit"
+ ],
+ "properties": {
+ "get_tx_rate_limit": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_axon_info"
+ ],
+ "properties": {
+ "get_axon_info": {
+ "type": "object",
+ "required": [
+ "hotkey",
+ "netuid"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_prometheus_info"
+ ],
+ "properties": {
+ "get_prometheus_info": {
+ "type": "object",
+ "required": [
+ "hotkey",
+ "netuid"
+ ],
+ "properties": {
+ "hotkey": {
+ "type": "string"
+ },
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_weights"
+ ],
+ "properties": {
+ "get_weights": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_weights_sparse"
+ ],
+ "properties": {
+ "get_weights_sparse": {
+ "type": "object",
+ "required": [
+ "netuid"
+ ],
+ "properties": {
+ "netuid": {
+ "type": "integer",
+ "format": "uint16",
+ "minimum": 0.0
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "required": [
+ "get_state"
+ ],
+ "properties": {
+ "get_state": {
+ "type": "object",
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ }
+ ]
+}
diff --git a/cybertensor/ctlogging.py b/cybertensor/ctlogging.py
index b85905f..cfa0a0f 100644
--- a/cybertensor/ctlogging.py
+++ b/cybertensor/ctlogging.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -25,7 +25,8 @@
import torch
from loguru import logger
-import cybertensor
+from cybertensor.config import Config
+
logger = logger.opt(colors=True)
# Remove default sink.
@@ -51,7 +52,7 @@ class logging:
def __new__(
cls,
- config: "cybertensor.config" = None,
+ config: "Config" = None,
debug: bool = None,
trace: bool = None,
record_log: bool = None,
@@ -59,7 +60,7 @@ def __new__(
):
r"""Instantiate cybertensor logging system backend.
Args:
- config (:obj:`cybertensor.config`, `optional`):
+ config (:obj:`Config`, `optional`):
cybertensor.logging.config()
debug (:obj:`bool`, `optional`):
Turn on debug.
@@ -100,7 +101,7 @@ def __new__(
# Add filtered sys.stdout.
cls.__std_sink__ = logger.add(
sys.stdout,
- level=0,
+ level=40,
filter=cls.log_filter,
colorize=True,
enqueue=True,
@@ -129,11 +130,11 @@ def __new__(
@classmethod
def config(cls):
"""Get config from the argument parser
- Return: cybertensor.config object
+ Return: Config object
"""
parser = argparse.ArgumentParser()
logging.add_args(parser)
- return cybertensor.config(parser, args=[])
+ return Config(parser, args=[])
@classmethod
def help(cls):
@@ -183,7 +184,7 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None):
pass
@classmethod
- def check_config(cls, config: "cybertensor.config"):
+ def check_config(cls, config: "Config"):
"""Check config"""
assert config.logging
diff --git a/cybertensor/cwtensor.py b/cybertensor/cwtensor.py
index c3427fc..971faf4 100644
--- a/cybertensor/cwtensor.py
+++ b/cybertensor/cwtensor.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -20,7 +20,7 @@
import argparse
import copy
import os
-from typing import List, Dict, Union, Optional, Tuple, TypedDict
+from typing import List, Dict, Union, Optional, Tuple
import torch
from cosmpy.aerial.client import LedgerClient
@@ -32,7 +32,8 @@
from retry import retry
import cybertensor
-from .chain_data import (
+from cybertensor import __console__ as console
+from cybertensor.chain_data import (
NeuronInfo,
DelegateInfo,
PrometheusInfo,
@@ -42,32 +43,34 @@
NeuronInfoLite,
AxonInfo,
)
-from .commands.utils import DelegatesDetails
-from .errors import *
-from .messages.delegation import (
+from cybertensor.commands.utils import DelegatesDetails
+from cybertensor.config import Config
+from cybertensor.errors import *
+from cybertensor.messages.delegation import (
delegate_message,
nominate_message,
undelegate_message,
)
-from .messages.network import (
+from cybertensor.messages.network import (
register_subnetwork_message,
set_hyperparameter_message,
)
-from .messages.prometheus import prometheus_message
-from .messages.registration import (
+from cybertensor.messages.prometheus import prometheus_message
+from cybertensor.messages.registration import (
register_message,
burned_register_message,
)
-from .messages.root import root_register_message, set_root_weights_message
-from .messages.serving import serve_message, serve_axon_message
-from .messages.set_weights import set_weights_message
-from .messages.staking import add_stake_message, add_stake_multiple_message
-from .messages.transfer import transfer_message
-from .messages.unstaking import unstake_message, unstake_multiple_message
-from .types import AxonServeCallParams, PrometheusServeCallParams
-from .utils import U16_NORMALIZED_FLOAT, coin_from_str
-from .utils.balance import Balance
-from .utils.registration import POWSolution
+from cybertensor.messages.root import root_register_message, set_root_weights_message
+from cybertensor.messages.serving import serve_message, serve_axon_message
+from cybertensor.messages.set_weights import set_weights_message
+from cybertensor.messages.staking import add_stake_message, add_stake_multiple_message
+from cybertensor.messages.transfer import transfer_message
+from cybertensor.messages.unstaking import unstake_message, unstake_multiple_message
+from cybertensor.types import AxonServeCallParams, PrometheusServeCallParams
+from cybertensor.utils import U16_NORMALIZED_FLOAT, coin_from_str
+from cybertensor.utils.balance import Balance
+from cybertensor.utils.registration import POWSolution
+from cybertensor.wallet import Wallet
logger = logger.opt(colors=True)
@@ -80,10 +83,10 @@ class cwtensor:
"""
@staticmethod
- def config() -> "cybertensor.config":
+ def config() -> "Config":
parser = argparse.ArgumentParser()
cwtensor.add_args(parser)
- return cybertensor.config(parser, args=[])
+ return Config(parser, args=[])
@classmethod
def help(cls):
@@ -159,7 +162,7 @@ def determine_chain_endpoint_and_network(
return "unknown", {}
@staticmethod
- def setup_config(network: str, config: "cybertensor.config"):
+ def setup_config(network: str, config: "Config"):
if network is not None:
(
evaluated_network,
@@ -197,12 +200,12 @@ def setup_config(network: str, config: "cybertensor.config"):
def __init__(
self,
network: str = None,
- config: "cybertensor.config" = None,
+ config: "Config" = None,
_mock: bool = False,
) -> None:
r"""Initializes a cwtensor chain interface.
Args:
- config (:obj:`cybertensor.config`, `optional`):
+ config (:obj:`Config`, `optional`):
cybertensor.cwtensor.config()
network (default='local or ws://127.0.0.1:9946', type=str)
The cwtensor network flag. The likely choices are:
@@ -250,12 +253,96 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return self.__str__()
+ # TODO check decorator and improve error handling
+ @retry(delay=3, tries=3, backoff=2, max_delay=8)
+ def make_call_with_retry(self, wait_for_finalization: bool,
+ msg: dict,
+ signer_wallet: LocalWallet,
+ error,
+ gas: Optional[int] = cybertensor.__default_gas__,
+ funds: Optional[str] = None) -> Optional[bool]:
+ if not wait_for_finalization:
+ self.contract.execute(msg, signer_wallet, gas, funds=funds)
+ return True
+ else:
+ tx = self.contract.execute(msg, signer_wallet, gas, funds=funds)
+ try:
+ tx.wait_to_complete()
+ if tx.response.is_successful():
+ print(f'Gas used: {tx.response.gas_used}')
+ return True
+ else:
+ raise error(tx.response.logs)
+ except Exception as e:
+ raise error(e.__str__())
+
+ def _execute_contract(self, wait_for_finalization: bool,
+ msg: dict,
+ wallet: Wallet,
+ error,
+ logging_prefix: str,
+ use_hotkey: bool = True,
+ success_text: str = 'Finalized',
+ exception_text: str = 'Failed',
+ gas: Optional[int] = cybertensor.__default_gas__,
+ funds: Optional[str] = None):
+ try:
+ _private_key = wallet.hotkey.private_key if use_hotkey else wallet.coldkey.private_key
+ signer_wallet = LocalWallet(
+ PrivateKey(_private_key), self.address_prefix
+ )
+ res = self.make_call_with_retry(
+ wait_for_finalization=wait_for_finalization,
+ msg=msg,
+ signer_wallet=signer_wallet,
+ error=error,
+ gas=gas,
+ funds=funds)
+ if res is True:
+ console.print(
+ f":white_heavy_check_mark: [green]{success_text}[/green]"
+ )
+ cybertensor.logging.success(
+ prefix=logging_prefix,
+ sufix=f"{success_text}",
+ )
+ return True
+ except Exception as e:
+ console.print(
+ f":cross_mark: [red]{exception_text}[/red]: error:{e}"
+ )
+ cybertensor.logging.warning(
+ prefix=logging_prefix,
+ sufix=f"[red]{exception_text}[/red]: error:{e}",
+ )
+
+ return False
+
+ @retry(delay=3, tries=3, backoff=2, max_delay=8)
+ def make_call_with_retry_2(self, wait_for_finalization: bool,
+ msg: dict, signer_wallet: LocalWallet, gas: Optional[int] = cybertensor.__default_gas__,
+ funds: Optional[str] = None) -> [bool, Optional[str]]:
+ if not wait_for_finalization:
+ self.contract.execute(msg, signer_wallet, gas, funds=funds)
+ return True, None
+ else:
+ tx = self.contract.execute(msg, signer_wallet, gas, funds=funds)
+ try:
+ tx.wait_to_complete()
+ if tx.response.is_successful():
+ print(f'Gas used: {tx.response.gas_used}')
+ return True, None
+ else:
+ return False, tx.response.code
+ except Exception as e:
+ return False, e.__str__()
+
#####################
#### Delegation #####
#####################
def nominate(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
wait_for_finalization: bool = True,
) -> bool:
"""Becomes a delegate for the hotkey."""
@@ -267,36 +354,23 @@ def nominate(
def _do_nominate(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
wait_for_finalization: bool = True,
) -> bool:
nominate_msg = {"become_delegate": {"hotkey": wallet.hotkey.address}}
signer_wallet = LocalWallet(
PrivateKey(wallet.coldkey.private_key), self.address_prefix
)
- gas = cybertensor.__default_gas__
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(nominate_msg, signer_wallet, gas)
- return True
- else:
- tx = self.contract.execute(nominate_msg, signer_wallet, gas)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True
- else:
- raise NominationError(tx.response.logs)
- except Exception as e:
- raise NominationError(e.__str__())
-
- return make_call_with_retry()
+ return self.make_call_with_retry(
+ wait_for_finalization=wait_for_finalization,
+ msg=nominate_msg,
+ signer_wallet=signer_wallet,
+ error=NominationError)
def delegate(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
delegate: Optional[str] = None,
amount: Union[Balance, float] = None,
wait_for_finalization: bool = True,
@@ -314,7 +388,7 @@ def delegate(
def _do_delegation(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
delegate: str,
amount: "Balance",
wait_for_finalization: bool = True,
@@ -323,30 +397,18 @@ def _do_delegation(
signer_wallet = LocalWallet(
PrivateKey(wallet.coldkey.private_key), self.address_prefix
)
- gas = cybertensor.__default_gas__
funds = amount.boot.__str__().__add__(self.token)
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(delegation_msg, signer_wallet, gas, funds)
- return True
- else:
- tx = self.contract.execute(delegation_msg, signer_wallet, gas, funds)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True
- else:
- raise StakeError(tx.response.code)
- except Exception as e:
- raise StakeError(e.__str__())
-
- return make_call_with_retry()
+ return self.make_call_with_retry(
+ wait_for_finalization=wait_for_finalization,
+ msg=delegation_msg,
+ funds=funds,
+ signer_wallet=signer_wallet,
+ error=StakeError)
def undelegate(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
delegate: Optional[str] = None,
amount: Union[Balance, float] = None,
wait_for_finalization: bool = True,
@@ -364,7 +426,7 @@ def undelegate(
def _do_undelegation(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
delegate: str,
amount: "Balance",
wait_for_finalization: bool = True,
@@ -373,25 +435,12 @@ def _do_undelegation(
signer_wallet = LocalWallet(
PrivateKey(wallet.coldkey.private_key), self.address_prefix
)
- gas = cybertensor.__default_gas__
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(undelegation_msg, signer_wallet, gas)
- return True
- else:
- tx = self.contract.execute(undelegation_msg, signer_wallet, gas)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True
- else:
- raise StakeError(tx.response.code)
- except Exception as e:
- raise StakeError(e.__str__())
-
- return make_call_with_retry()
+ return self.make_call_with_retry(
+ wait_for_finalization=wait_for_finalization,
+ msg=undelegation_msg,
+ signer_wallet=signer_wallet,
+ error=StakeError)
#####################
#### Set Weights ####
@@ -399,7 +448,7 @@ def make_call_with_retry():
def set_weights(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuid: int,
uids: Union[torch.LongTensor, torch.Tensor, list],
weights: Union[torch.FloatTensor, torch.Tensor, list],
@@ -420,13 +469,14 @@ def set_weights(
def _do_set_weights(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
uids: List[int],
vals: List[int],
netuid: int,
version_key: int = cybertensor.__version_as_int__,
wait_for_finalization: bool = True,
- ) -> Tuple[bool, Optional[str]]: # (success, error_message)
+ ) -> bool:
+
set_weights_msg = {
"set_weights": {
"netuid": netuid,
@@ -435,35 +485,21 @@ def _do_set_weights(
"version_key": version_key,
}
}
- signer_wallet = LocalWallet(
- PrivateKey(wallet.hotkey.private_key), self.address_prefix
- )
- gas = cybertensor.__default_gas__
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(set_weights_msg, signer_wallet, gas)
- return True, None
- else:
- tx = self.contract.execute(set_weights_msg, signer_wallet, gas)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True, None
- else:
- return False, tx.response.code
- except Exception as e:
- return False, e.__str__()
-
- return make_call_with_retry()
+ return self._execute_contract(
+ wait_for_finalization=wait_for_finalization,
+ msg=set_weights_msg,
+ wallet=wallet,
+ error=NotSetWeightError,
+ logging_prefix='Set weights'
+ )
######################
#### Registration ####
######################
def register(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuid: int,
wait_for_finalization: bool = True,
prompt: bool = False,
@@ -496,14 +532,14 @@ def register(
def _do_pow_register(
self,
netuid: int,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
pow_result: POWSolution,
wait_for_finalization: bool = True,
) -> Tuple[bool, Optional[str]]:
"""Sends a (POW) register extrinsic to the chain.
Args:
netuid (int): the subnet to register on.
- wallet (cybertensor.wallet): the wallet to register.
+ wallet (Wallet): the wallet to register.
pow_result (POWSolution): the pow result to register.
wait_for_finalization (bool): if true, waits for the extrinsic to be finalized.
Returns:
@@ -524,30 +560,15 @@ def _do_pow_register(
signer_wallet = LocalWallet(
PrivateKey(wallet.hotkey.private_key), self.address_prefix
)
- gas = cybertensor.__default_gas__
- # TODO check decorator and improve error handling
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(register_msg, signer_wallet, gas)
- return True, None
- else:
- tx = self.contract.execute(register_msg, signer_wallet, gas)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True, None
- else:
- return False, tx.response.code
- except Exception as e:
- return False, e.__str__()
-
- return make_call_with_retry()
+ return self.make_call_with_retry_2(
+ wait_for_finalization=wait_for_finalization,
+ msg=register_msg,
+ signer_wallet=signer_wallet)
def burned_register(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuid: int,
wait_for_finalization: bool = True,
prompt: bool = False,
@@ -565,7 +586,7 @@ def _do_burned_register(
self,
netuid: int,
burn: int,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
wait_for_finalization: bool = True,
) -> Tuple[bool, Optional[str]]:
burned_register_msg = {
@@ -574,35 +595,20 @@ def _do_burned_register(
signer_wallet = LocalWallet(
PrivateKey(wallet.coldkey.private_key), self.address_prefix
)
- gas = cybertensor.__default_gas__
funds = burn.__str__().__add__(self.token)
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(burned_register_msg, signer_wallet, gas, funds)
- return True, None
- else:
- tx = self.contract.execute(
- burned_register_msg, signer_wallet, gas, funds
- )
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True, None
- else:
- return False, tx.response.code
- except Exception as e:
- return False, e.__str__()
-
- return make_call_with_retry()
+ return self.make_call_with_retry_2(
+ wait_for_finalization=wait_for_finalization,
+ msg=burned_register_msg,
+ funds=funds,
+ signer_wallet=signer_wallet)
##################
#### Transfer ####
##################
def transfer(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
dest: str,
amount: Union[Balance, float],
wait_for_inclusion: bool = True,
@@ -629,7 +635,7 @@ def get_transfer_fee(
def _do_transfer(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
dest: Address,
transfer_balance: Balance,
wait_for_inclusion: bool = True,
@@ -637,7 +643,7 @@ def _do_transfer(
) -> Tuple[bool, Optional[str], Optional[str]]:
"""Sends a transfer extrinsic to the chain.
Args:
- wallet (:obj:`cybertensor.wallet`): Wallet object.
+ wallet (:obj:`Wallet`): Wallet object.
dest (:obj:`str`): Destination public key address.
transfer_balance (:obj:`Balance`): Amount to transfer.
wait_for_inclusion (:obj:`bool`): If true, waits for inclusion.
@@ -680,7 +686,7 @@ def get_existential_deposit(self, block: Optional[int] = None) -> Optional[Balan
#################
def register_subnetwork(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
wait_for_finalization=True,
prompt: bool = False,
) -> bool:
@@ -693,7 +699,7 @@ def register_subnetwork(
def set_hyperparameter(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuid: int,
parameter: str,
value,
@@ -716,7 +722,7 @@ def set_hyperparameter(
def serve(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
ip: str,
port: int,
protocol: int,
@@ -749,36 +755,22 @@ def serve_axon(
def _do_serve_axon(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
call_params: AxonServeCallParams,
wait_for_finalization: bool = True,
) -> Tuple[bool, Optional[str]]:
signer_wallet = LocalWallet(
PrivateKey(wallet.hotkey.private_key), self.address_prefix
)
- gas = cybertensor.__default_gas__
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(call_params, signer_wallet, gas)
- return True, None
- else:
- tx = self.contract.execute(call_params, signer_wallet, gas)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True, None
- else:
- return False, tx.response.code
- except Exception as e:
- return False, e.__str__()
-
- return make_call_with_retry()
+ return self.make_call_with_retry_2(
+ wait_for_finalization=wait_for_finalization,
+ msg=call_params,
+ signer_wallet=signer_wallet)
def serve_prometheus(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
port: int,
netuid: int,
wait_for_finalization: bool = True,
@@ -793,14 +785,14 @@ def serve_prometheus(
def _do_serve_prometheus(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
call_params: PrometheusServeCallParams,
wait_for_finalization: bool = True,
) -> Tuple[bool, Optional[str]]:
"""
Sends a serve prometheus extrinsic to the chain.
Args:
- wallet (:obj:`cybertensor.wallet`): Wallet object.
+ wallet (:obj:`Wallet`): Wallet object.
call_params (:obj:`PrometheusServeCallParams`): Prometheus serve call parameters.
wait_for_finalization (:obj:`bool`): If true, waits for finalization.
Returns:
@@ -811,32 +803,18 @@ def _do_serve_prometheus(
signer_wallet = LocalWallet(
PrivateKey(wallet.hotkey.private_key), self.address_prefix
)
- gas = cybertensor.__default_gas__
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(call_params, signer_wallet, gas)
- return True, None
- else:
- tx = self.contract.execute(call_params, signer_wallet, gas)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True, None
- else:
- return False, tx.response.code
- except Exception as e:
- return False, e.__str__()
-
- return make_call_with_retry()
+ return self.make_call_with_retry_2(
+ wait_for_finalization=wait_for_finalization,
+ msg=call_params,
+ signer_wallet=signer_wallet)
#################
#### Staking ####
#################
def add_stake(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkey: Optional[str] = None,
amount: Union[Balance, float] = None,
wait_for_finalization: bool = True,
@@ -854,7 +832,7 @@ def add_stake(
def add_stake_multiple(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkeys: List[str],
amounts: List[Union[Balance, float]] = None,
wait_for_finalization: bool = True,
@@ -872,14 +850,14 @@ def add_stake_multiple(
def _do_stake(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkey: str,
amount: Balance,
wait_for_finalization: bool = True,
) -> bool:
"""Sends a stake extrinsic to the chain.
Args:
- wallet (:obj:`cybertensor.wallet`): Wallet object that can sign the extrinsic.
+ wallet (:obj:`Wallet`): Wallet object that can sign the extrinsic.
hotkey (:obj:`str`): Hotkey address to stake to.
amount (:obj:`Balance`): Amount to stake.
wait_for_finalization (:obj:`bool`): If true, waits for finalization before returning.
@@ -893,33 +871,21 @@ def _do_stake(
signer_wallet = LocalWallet(
PrivateKey(wallet.coldkey.private_key), self.address_prefix
)
- gas = cybertensor.__default_gas__
funds = amount.boot.__str__().__add__(self.token)
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(add_stake_msg, signer_wallet, gas, funds)
- return True
- else:
- tx = self.contract.execute(add_stake_msg, signer_wallet, gas, funds)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True
- else:
- raise StakeError(tx.response.code)
- except Exception as e:
- raise StakeError(e.__str__())
-
- return make_call_with_retry()
+ return self.make_call_with_retry(
+ wait_for_finalization=wait_for_finalization,
+ msg=add_stake_msg,
+ signer_wallet=signer_wallet,
+ funds=funds,
+ error=StakeError)
###################
#### Unstaking ####
###################
def unstake_multiple(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkeys: List[str],
amounts: List[Union[Balance, float]] = None,
wait_for_finalization: bool = True,
@@ -937,7 +903,7 @@ def unstake_multiple(
def unstake(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkey: Optional[str] = None,
amount: Union[Balance, float] = None,
wait_for_finalization: bool = True,
@@ -955,14 +921,14 @@ def unstake(
def _do_unstake(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkey: str,
amount: Balance,
wait_for_finalization: bool = False,
) -> bool:
"""Sends an unstake extrinsic to the chain.
Args:
- wallet (:obj:`cybertensor.wallet`): Wallet object that can sign the extrinsic.
+ wallet (:obj:`Wallet`): Wallet object that can sign the extrinsic.
hotkey (:obj:`str`): Hotkey address to unstake from.
amount (:obj:`Balance`): Amount to unstake.
wait_for_finalization (:obj:`bool`): If true, waits for finalization before returning.
@@ -976,25 +942,12 @@ def _do_unstake(
signer_wallet = LocalWallet(
PrivateKey(wallet.coldkey.private_key), self.address_prefix
)
- gas = cybertensor.__default_gas__
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(remove_stake_msg, signer_wallet, gas)
- return True
- else:
- tx = self.contract.execute(remove_stake_msg, signer_wallet, gas)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True
- else:
- raise StakeError(tx.response.code)
- except Exception as e:
- raise StakeError(e.__str__())
-
- return make_call_with_retry()
+ return self.make_call_with_retry(
+ wait_for_finalization=wait_for_finalization,
+ msg=remove_stake_msg,
+ signer_wallet=signer_wallet,
+ error=StakeError)
##############
#### Root ####
@@ -1002,7 +955,7 @@ def make_call_with_retry():
def root_register(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
wait_for_finalization: bool = True,
prompt: bool = False,
) -> bool:
@@ -1016,36 +969,24 @@ def root_register(
def _do_root_register(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
wait_for_finalization: bool = True,
- ) -> Tuple[bool, Optional[str]]:
+ ) -> bool:
+
root_register_msg = {"root_register": {"hotkey": wallet.hotkey.address}}
- signer_wallet = LocalWallet(
- PrivateKey(wallet.coldkey.private_key), self.address_prefix
- )
- gas = cybertensor.__default_gas__
- @retry(delay=2, tries=3, backoff=2, max_delay=4)
- def make_call_with_retry():
- if not wait_for_finalization:
- self.contract.execute(root_register_msg, signer_wallet, gas)
- return True, None
- else:
- tx = self.contract.execute(root_register_msg, signer_wallet, gas)
- try:
- tx.wait_to_complete()
- if tx.response.is_successful():
- return True, None
- else:
- return False, tx.response.code
- except Exception as e:
- return False, e.__str__()
-
- return make_call_with_retry()
+ return self._execute_contract(
+ wait_for_finalization=wait_for_finalization,
+ msg=root_register_msg,
+ wallet=wallet,
+ error=RegistrationError,
+ use_hotkey=False,
+ logging_prefix='root register',
+ exception_text='Neuron was not registered in root')
def root_set_weights(
self,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuids: Union[torch.LongTensor, torch.Tensor, list],
weights: Union[torch.FloatTensor, torch.Tensor, list],
version_key: int = 0,
diff --git a/cybertensor/dendrite.py b/cybertensor/dendrite.py
index 91286c0..ab823d5 100644
--- a/cybertensor/dendrite.py
+++ b/cybertensor/dendrite.py
@@ -2,7 +2,7 @@
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -30,6 +30,7 @@
from fastapi import Response
import cybertensor
+from cybertensor.wallet import Wallet
class dendrite(torch.nn.Module):
@@ -80,7 +81,7 @@ class dendrite(torch.nn.Module):
NOTE: When working with async aiohttp client sessions, it is recommended to use a context manager.
Example with a context manager:
- >>> aysnc with dendrite(wallet = cybertensor.wallet()) as d:
+ >>> aysnc with dendrite(wallet = Wallet()) as d:
>>> print(d)
>>> d( ) # ping axon
>>> d( [] ) # ping multiple
@@ -89,7 +90,7 @@ class dendrite(torch.nn.Module):
However, you are able to safely call dendrite.query() without a context manager in a synchronous setting.
Example without a context manager:
- >>> d = dendrite(wallet = cybertensor.wallet() )
+ >>> d = dendrite(wallet = Wallet() )
>>> print(d)
>>> d( ) # ping axon
>>> d( [] ) # ping multiple
@@ -97,15 +98,15 @@ class dendrite(torch.nn.Module):
"""
def __init__(
- self, wallet: Optional[Union[cybertensor.wallet, cybertensor.keypair]] = None
+ self, wallet: Optional[Union[Wallet, cybertensor.keypair]] = None
):
"""
Initializes the Dendrite object, setting up essential properties.
Args:
- wallet (Optional[Union['cybertensor.wallet', 'cybertensor.keypair']], optional):
+ wallet (Optional[Union['Wallet', 'cybertensor.keypair']], optional):
The user's wallet or keypair used for signing messages. Defaults to None,
- in which case a new cybertensor.wallet().hotkey is generated and used.
+ in which case a new Wallet().hotkey is generated and used.
"""
# Initialize the parent class
super(dendrite, self).__init__()
@@ -118,8 +119,8 @@ def __init__(
# If a wallet or keypair is provided, use its hotkey. If not, generate a new one.
self.keypair = (
- wallet.hotkey if isinstance(wallet, cybertensor.wallet) else wallet
- ) or cybertensor.wallet().hotkey
+ wallet.hotkey if isinstance(wallet, Wallet) else wallet
+ ) or Wallet().hotkey
self.synapse_history: list = []
diff --git a/cybertensor/errors.py b/cybertensor/errors.py
index 270b3ba..69f0bf7 100644
--- a/cybertensor/errors.py
+++ b/cybertensor/errors.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -77,6 +77,11 @@ class NotDelegateError(StakeError):
pass
+class NotSetWeightError(ChainTransactionError):
+ r"""Error raised when a hotkey you are trying to set weight is not set."""
+ pass
+
+
class KeyFileError(Exception):
r"""Error thrown when the keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid."""
pass
diff --git a/cybertensor/keyfile.py b/cybertensor/keyfile.py
index abe3adf..01b8c94 100644
--- a/cybertensor/keyfile.py
+++ b/cybertensor/keyfile.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -39,14 +39,16 @@
import cybertensor
from cybertensor import __chain_address_prefix__
from cybertensor.errors import KeyFileError
+from cybertensor.keypair import Keypair
+from cybertensor import __console__ as console
NACL_SALT = b"\x13q\x83\xdf\xf1Z\t\xbc\x9c\x90\xb5Q\x879\xe9\xb1"
-def serialized_keypair_to_keyfile_data(keypair: "cybertensor.Keypair") -> bytes:
+def serialized_keypair_to_keyfile_data(keypair: "Keypair") -> bytes:
"""Serializes keypair object into keyfile data.
Args:
- keypair (cybertensor.Keypair): The keypair object to be serialized.
+ keypair (Keypair): The keypair object to be serialized.
Returns:
data (bytes): Serialized keypair data.
"""
@@ -59,12 +61,12 @@ def serialized_keypair_to_keyfile_data(keypair: "cybertensor.Keypair") -> bytes:
return data
-def deserialize_keypair_from_keyfile_data(keyfile_data: bytes) -> "cybertensor.Keypair":
+def deserialize_keypair_from_keyfile_data(keyfile_data: bytes) -> "Keypair":
"""Deserializes Keypair object from passed keyfile data.
Args:
keyfile_data (bytes): The keyfile data as bytes to be loaded.
Returns:
- keypair (cybertensor.Keypair): The Keypair loaded from bytes.
+ keypair (Keypair): The Keypair loaded from bytes.
Raises:
KeyFileError: Raised if the passed bytes cannot construct a keypair object.
"""
@@ -73,23 +75,23 @@ def deserialize_keypair_from_keyfile_data(keyfile_data: bytes) -> "cybertensor.K
keyfile_dict = dict(json.loads(keyfile_data))
except:
string_value = str(keyfile_data)
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keypair could not be created from keyfile data: {}".format(string_value)
)
if "secretPhrase" in keyfile_dict and keyfile_dict["secretPhrase"] is not None:
- return cybertensor.Keypair.create_from_mnemonic(
+ return Keypair.create_from_mnemonic(
mnemonic=keyfile_dict["secretPhrase"],
prefix=__chain_address_prefix__,
)
if "address" in keyfile_dict and keyfile_dict["address"] is not None:
- return cybertensor.Keypair(
+ return Keypair(
address=keyfile_dict["address"], public_key=keyfile_dict["publicKey"]
)
else:
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keypair could not be created from keyfile data: {}".format(keyfile_dict)
)
@@ -198,7 +200,6 @@ def keyfile_data_encryption_method(keyfile_data: bytes) -> bool:
def legacy_encrypt_keyfile_data(keyfile_data: bytes, password: str = None) -> bytes:
password = ask_password_to_encrypt() if password is None else password
- console = cybertensor.__console__
with console.status(
":exclamation_mark: Encrypting key with legacy encrpytion method..."
):
@@ -214,7 +215,7 @@ def encrypt_keyfile_data(keyfile_data: bytes, password: str = None) -> bytes:
Returns:
encrypted_data (bytes): The encrypted data.
"""
- password = cybertensor.ask_password_to_encrypt() if password is None else password
+ password = ask_password_to_encrypt() if password is None else password
password = bytes(password, "utf-8")
kdf = pwhash.argon2i.kdf
key = kdf(
@@ -267,7 +268,6 @@ def decrypt_keyfile_data(
if password is None
else password
)
- console = cybertensor.__console__
with console.status(":key: Decrypting key..."):
# NaCl SecretBox decrypt.
if keyfile_data_is_encrypted_nacl(keyfile_data):
@@ -288,7 +288,7 @@ def decrypt_keyfile_data(
try:
decrypted_keyfile_data = vault.load(keyfile_data)
except AnsibleVaultError:
- raise cybertensor.KeyFileError("Invalid password")
+ raise KeyFileError("Invalid password")
# Legacy decrypt.
elif keyfile_data_is_encrypted_legacy(keyfile_data):
__SALT = (
@@ -306,12 +306,12 @@ def decrypt_keyfile_data(
decrypted_keyfile_data = cipher_suite.decrypt(keyfile_data)
# Unknown.
else:
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"keyfile data: {} is corrupt".format(keyfile_data)
)
except (InvalidSignature, InvalidKey, InvalidToken):
- raise cybertensor.KeyFileError("Invalid password")
+ raise KeyFileError("Invalid password")
if not isinstance(decrypted_keyfile_data, bytes):
decrypted_keyfile_data = json.dumps(decrypted_keyfile_data).encode()
@@ -340,10 +340,10 @@ def __repr__(self):
return self.__str__()
@property
- def keypair(self) -> "cybertensor.Keypair":
+ def keypair(self) -> "Keypair":
"""Returns the keypair from path, decrypts data if the file is encrypted.
Returns:
- keypair (cybertensor.Keypair): The keypair stored under the path.
+ keypair (Keypair): The keypair stored under the path.
Raises:
KeyFileError: Raised if the file does not exist, is not readable, writable, corrupted, or if the password is incorrect.
"""
@@ -371,14 +371,14 @@ def keyfile_data(self) -> bytes:
def set_keypair(
self,
- keypair: "cybertensor.Keypair",
+ keypair: "Keypair",
encrypt: bool = True,
overwrite: bool = False,
password: str = None,
):
"""Writes the keypair to the file and optionally encrypts data.
Args:
- keypair (cybertensor.Keypair): The keypair to store under the path.
+ keypair (Keypair): The keypair to store under the path.
encrypt (bool, optional): If True, encrypts the file under the path. Default is True.
overwrite (bool, optional): If True, forces overwrite of the current file. Default is False.
password (str, optional): The password used to encrypt the file. If None, asks for user input.
@@ -388,15 +388,15 @@ def set_keypair(
self.make_dirs()
keyfile_data = serialized_keypair_to_keyfile_data(keypair)
if encrypt:
- keyfile_data = cybertensor.encrypt_keyfile_data(keyfile_data, password)
+ keyfile_data = encrypt_keyfile_data(keyfile_data, password)
self._write_keyfile_data_to_file(keyfile_data, overwrite=overwrite)
- def get_keypair(self, password: str = None) -> "cybertensor.Keypair":
+ def get_keypair(self, password: str = None) -> "Keypair":
"""Returns the keypair from the path, decrypts data if the file is encrypted.
Args:
password (str, optional): The password used to decrypt the file. If None, asks for user input.
Returns:
- keypair (cybertensor.Keypair): The keypair stored under the path.
+ keypair (Keypair): The keypair stored under the path.
Raises:
KeyFileError: Raised if the file does not exist, is not readable, writable, corrupted, or if the password is incorrect.
"""
@@ -481,15 +481,15 @@ def check_and_update_encryption(
"""
if not self.exists_on_device():
if print_result:
- cybertensor.__console__.print(f"Keyfile does not exist. {self.path}")
+ console.print(f"Keyfile does not exist. {self.path}")
return False
if not self.is_readable():
if print_result:
- cybertensor.__console__.print(f"Keyfile is not redable. {self.path}")
+ console.print(f"Keyfile is not redable. {self.path}")
return False
if not self.is_writable():
if print_result:
- cybertensor.__console__.print(f"Keyfile is not writable. {self.path}")
+ console.print(f"Keyfile is not writable. {self.path}")
return False
update_keyfile = False
@@ -501,14 +501,14 @@ def check_and_update_encryption(
keyfile_data
) and not keyfile_data_is_encrypted_nacl(keyfile_data):
terminate = False
- cybertensor.__console__.print(
+ console.print(
f"You may update the keyfile to improve the security for storing your keys.\nWhile the key and the password stays the same, it would require providing your password once.\n:key:{self}\n"
)
update_keyfile = Confirm.ask("Update keyfile?")
if update_keyfile:
stored_mnemonic = False
while not stored_mnemonic:
- cybertensor.__console__.print(
+ console.print(
f"\nPlease make sure you have the mnemonic stored in case an error occurs during the transfer.",
style="white on red",
)
@@ -547,19 +547,19 @@ def check_and_update_encryption(
keyfile_data = self._read_keyfile_data_from_file()
if not keyfile_data_is_encrypted(keyfile_data):
if print_result:
- cybertensor.__console__.print(
+ console.print(
f"\nKeyfile is not encrypted. \n:key: {self}"
)
return False
elif keyfile_data_is_encrypted_nacl(keyfile_data):
if print_result:
- cybertensor.__console__.print(
+ console.print(
f"\n:white_heavy_check_mark: Keyfile is updated. \n:key: {self}"
)
return True
else:
if print_result:
- cybertensor.__console__.print(
+ console.print(
f'\n:cross_mark: Keyfile is outdated, please update with "ctcli wallet update" \n:key: {self}'
)
return False
@@ -573,15 +573,15 @@ def encrypt(self, password: str = None):
KeyFileError: Raised if the file does not exist, is not readable, or writable.
"""
if not self.exists_on_device():
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keyfile at: {} does not exist".format(self.path)
)
if not self.is_readable():
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keyfile at: {} is not readable".format(self.path)
)
if not self.is_writable():
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keyfile at: {} is not writable".format(self.path)
)
keyfile_data = self._read_keyfile_data_from_file()
@@ -599,15 +599,15 @@ def decrypt(self, password: str = None):
KeyFileError: Raised if the file does not exist, is not readable, writable, corrupted, or if the password is incorrect.
"""
if not self.exists_on_device():
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keyfile at: {} does not exist".format(self.path)
)
if not self.is_readable():
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keyfile at: {} is not readable".format(self.path)
)
if not self.is_writable():
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keyfile at: {} is not writable".format(self.path)
)
keyfile_data = self._read_keyfile_data_from_file()
@@ -627,11 +627,11 @@ def _read_keyfile_data_from_file(self) -> bytes:
KeyFileError: Raised if the file does not exist or is not readable.
"""
if not self.exists_on_device():
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keyfile at: {} does not exist".format(self.path)
)
if not self.is_readable():
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keyfile at: {} is not readable".format(self.path)
)
with open(self.path, "rb") as file:
@@ -649,7 +649,7 @@ def _write_keyfile_data_to_file(self, keyfile_data: bytes, overwrite: bool = Fal
# Check overwrite.
if self.exists_on_device() and not overwrite:
if not self._may_overwrite():
- raise cybertensor.KeyFileError(
+ raise KeyFileError(
"Keyfile at: {} is not writable".format(self.path)
)
with open(self.path, "wb") as keyfile:
@@ -701,7 +701,7 @@ def keypair(self):
Returns the mock keypair stored in the keyfile.
Returns:
- cybertensor.Keypair: The mock keypair.
+ Keypair: The mock keypair.
"""
return self._mock_keypair
@@ -720,7 +720,7 @@ def set_keypair(self, keypair, encrypt=True, overwrite=False, password=None):
Sets the mock keypair in the keyfile. The `encrypt` and `overwrite` parameters are ignored.
Args:
- keypair (cybertensor.Keypair): The mock keypair to be set.
+ keypair (Keypair): The mock keypair to be set.
encrypt (bool, optional): Ignored in this context. Defaults to True.
overwrite (bool, optional): Ignored in this context. Defaults to False.
password (str, optional): Ignored in this context. Defaults to None.
@@ -736,7 +736,7 @@ def get_keypair(self, password=None):
password (str, optional): Ignored in this context. Defaults to None.
Returns:
- cybertensor.Keypair: The mock keypair stored in the keyfile.
+ Keypair: The mock keypair stored in the keyfile.
"""
return self._mock_keypair
diff --git a/cybertensor/keypair.py b/cybertensor/keypair.py
index a8f3117..416aa05 100644
--- a/cybertensor/keypair.py
+++ b/cybertensor/keypair.py
@@ -1,5 +1,5 @@
# The MIT License (MIT)
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -26,7 +26,7 @@
validate_mnemonic_and_normalise,
)
-import cybertensor
+from cybertensor import __chain_address_prefix__
class Keypair:
@@ -49,7 +49,7 @@ def __init__(
"""
if prefix is None:
- prefix = cybertensor.__chain_address_prefix__
+ prefix = __chain_address_prefix__
self.prefix = prefix
@@ -120,7 +120,7 @@ def create_from_mnemonic(
"""
if prefix is None:
- prefix = cybertensor.__chain_address_prefix__
+ prefix = __chain_address_prefix__
mnemonic = validate_mnemonic_and_normalise(mnemonic)
@@ -149,7 +149,7 @@ def create_from_private_key(
"""
if prefix is None:
- prefix = cybertensor.__chain_address_prefix__
+ prefix = __chain_address_prefix__
return cls(
public_key=PrivateKey(private_key).public_key.public_key,
diff --git a/cybertensor/messages/__init__.py b/cybertensor/messages/__init__.py
index 2e27c35..1a7544b 100644
--- a/cybertensor/messages/__init__.py
+++ b/cybertensor/messages/__init__.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
diff --git a/cybertensor/messages/delegation.py b/cybertensor/messages/delegation.py
index 1cb43a3..2aaac0d 100644
--- a/cybertensor/messages/delegation.py
+++ b/cybertensor/messages/delegation.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -24,20 +24,22 @@
from rich.prompt import Confirm
import cybertensor
+from cybertensor import __console__ as console
+from cybertensor.errors import *
from cybertensor.utils.balance import Balance
-from ..errors import *
+from cybertensor.wallet import Wallet
logger = logger.opt(colors=True)
def nominate_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
wait_for_finalization: bool = True,
) -> bool:
r"""Becomes a delegate for the hotkey.
Args:
- wallet ( cybertensor.wallet ):
+ wallet ( Wallet ):
The wallet to become a delegate for.
Returns:
success (bool):
@@ -54,7 +56,7 @@ def nominate_message(
)
return False
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Sending nominate call on [white]{cwtensor.network}[/white] ..."
):
try:
@@ -64,7 +66,7 @@ def nominate_message(
)
if success is True:
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
cybertensor.logging.success(
@@ -76,14 +78,14 @@ def nominate_message(
return success
except Exception as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error:{e}"
)
# cybertensor.logging.warning(
# prefix="Set weights", sufix=f"Failed: {e}"
# )
except NominationError as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error:{e}"
)
# cybertensor.logging.warning(
@@ -95,7 +97,7 @@ def nominate_message(
def delegate_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
delegate: Optional[str] = None,
amount: Union[Balance, float] = None,
wait_for_finalization: bool = False,
@@ -103,7 +105,7 @@ def delegate_message(
) -> bool:
r"""Delegates the specified amount of stake to the passed delegate.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
delegate (Optional[str]):
address of the delegate.
@@ -138,24 +140,24 @@ def delegate_message(
coldkey=wallet.coldkeypub.address, hotkey=delegate
)
- # Convert to cybertensor.Balance
+ # Convert to Balance
if amount is None:
# Stake it all.
- staking_balance = cybertensor.Balance.from_gboot(my_prev_coldkey_balance.gboot)
- elif not isinstance(amount, cybertensor.Balance):
- staking_balance = cybertensor.Balance.from_gboot(amount)
+ staking_balance = Balance.from_gboot(my_prev_coldkey_balance.gboot)
+ elif not isinstance(amount, Balance):
+ staking_balance = Balance.from_gboot(amount)
else:
staking_balance = amount
# Remove existential balance to keep key alive.
- if staking_balance > cybertensor.Balance.from_boot(1000000):
- staking_balance = staking_balance - cybertensor.Balance.from_boot(1000000)
+ if staking_balance > Balance.from_boot(1000000):
+ staking_balance = staking_balance - Balance.from_boot(1000000)
else:
staking_balance = staking_balance
# Check enough balance to stake.
if staking_balance > my_prev_coldkey_balance:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Not enough balance[/red]:[bold white]\n"
f" balance:{my_prev_coldkey_balance}\n"
f" amount: {staking_balance}\n"
@@ -174,7 +176,7 @@ def delegate_message(
return False
try:
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Staking to: [bold white]{cwtensor.network}[/bold white] ..."
):
staking_response: bool = cwtensor._do_delegation(
@@ -189,10 +191,10 @@ def delegate_message(
if not wait_for_finalization:
return True
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..."
):
new_balance = cwtensor.get_balance(address=wallet.coldkey.address)
@@ -203,33 +205,33 @@ def delegate_message(
block=block,
) # Get current stake
- cybertensor.__console__.print(
+ console.print(
f"Balance:\n"
f" [blue]{my_prev_coldkey_balance}[/blue] :arrow_right: [green]{new_balance}[/green]"
)
- cybertensor.__console__.print(
+ console.print(
f"Stake:\n [blue]{my_prev_delegated_stake}[/blue] :arrow_right: [green]{new_delegate_stake}[/green]"
)
return True
else:
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Failed[/red]: Error unknown."
)
return False
except NotRegisteredError as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Hotkey: {wallet.hotkey_str} is not registered.[/red]"
)
return False
except StakeError as e:
- cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]")
+ console.print(f":cross_mark: [red]Stake Error: {e}[/red]")
return False
def undelegate_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
delegate: Optional[str] = None,
amount: Union[Balance, float] = None,
wait_for_finalization: bool = True,
@@ -237,7 +239,7 @@ def undelegate_message(
) -> bool:
r"""Un-delegates stake from the passed delegate.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
delegate (Optional[str]):
address of the delegate.
@@ -272,20 +274,20 @@ def undelegate_message(
coldkey=wallet.coldkeypub.address, hotkey=delegate
)
- # Convert to cybertensor.Balance
+ # Convert to Balance
if amount is None:
# Stake it all.
- unstaking_balance = cybertensor.Balance.from_gboot(my_prev_delegated_stake.gboot)
+ unstaking_balance = Balance.from_gboot(my_prev_delegated_stake.gboot)
- elif not isinstance(amount, cybertensor.Balance):
- unstaking_balance = cybertensor.Balance.from_gboot(amount)
+ elif not isinstance(amount, Balance):
+ unstaking_balance = Balance.from_gboot(amount)
else:
unstaking_balance = amount
# Check enough stake to unstake.
if unstaking_balance > my_prev_delegated_stake:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Not enough delegated stake[/red]:[bold white]\n"
f" stake:{my_prev_delegated_stake}\n"
f" amount: {unstaking_balance}\n"
@@ -304,7 +306,7 @@ def undelegate_message(
return False
try:
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Unstaking from: [bold white]{cwtensor.network}[/bold white] ..."
):
staking_response: bool = cwtensor._do_undelegation(
@@ -319,10 +321,10 @@ def undelegate_message(
if not wait_for_finalization:
return True
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..."
):
new_balance = cwtensor.get_balance(address=wallet.coldkey.address)
@@ -333,26 +335,26 @@ def undelegate_message(
block=block,
) # Get current stake
- cybertensor.__console__.print(
+ console.print(
f"Balance:\n"
f" [blue]{my_prev_coldkey_balance}[/blue] :arrow_right: [green]{new_balance}[/green]"
)
- cybertensor.__console__.print(
+ console.print(
f"Stake:\n"
f" [blue]{my_prev_delegated_stake}[/blue] :arrow_right: [green]{new_delegate_stake}[/green]"
)
return True
else:
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Failed[/red]: Error unknown."
)
return False
except NotRegisteredError as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Hotkey: {wallet.hotkey_str} is not registered.[/red]"
)
return False
except StakeError as e:
- cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]")
+ console.print(f":cross_mark: [red]Stake Error: {e}[/red]")
return False
diff --git a/cybertensor/messages/log_utilities.py b/cybertensor/messages/log_utilities.py
index ab1317c..a824b4e 100644
--- a/cybertensor/messages/log_utilities.py
+++ b/cybertensor/messages/log_utilities.py
@@ -1,7 +1,7 @@
import datetime
import math
import time
-from typing import List, Dict, Set
+from typing import List, Dict, Set, Optional
from prometheus_client import Counter, Info, Histogram, Gauge
import torch
@@ -11,6 +11,8 @@
from rich.table import Table
import cybertensor
+from cybertensor.wallet import Wallet
+from cybertensor.config import Config
class ValidatorLogger:
@@ -19,11 +21,11 @@ class ValidatorLogger:
Including console log styling, console table print and prometheus.
Args:
- config (:obj:`cybertensor.Config`, `optional`):
+ config (:obj:`Config`, `optional`):
cybertensor.server.config()
"""
- def __init__(self, config=None):
+ def __init__(self, config: Optional[Config] = None):
# Neuron stats recorded by validator neuron/nucleus
# [Column_name, key_name, format_string, rich_style] # description
self.config = config
@@ -576,7 +578,7 @@ def print_weights_table(
)
def print_console_validator_identifier(
- self, uid: int, wallet: "cybertensor.wallet", external_ip: str
+ self, uid: int, wallet: "Wallet", external_ip: str
):
r"""Console print for validator identifier."""
@@ -670,11 +672,11 @@ class ValidatorPrometheus:
r"""
Prometheis logging object for validator.
Args:
- config (:obj:`cybertensor.Config`, `optional`):
+ config (:obj:`Config`, `optional`):
cybertensor.server.config()
"""
- def __init__(self, config):
+ def __init__(self, config: Config):
self.config = config
self.info = Info("neuron_info", "Info summaries for the running server-miner.")
self.gauges = Gauge(
@@ -698,7 +700,7 @@ def log_run_info(
parameters: torch.nn.parameter.Parameter,
uid: int,
network: str,
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
):
r"""Set up prometheus running info."""
diff --git a/cybertensor/messages/network.py b/cybertensor/messages/network.py
index 8ee4923..e426208 100644
--- a/cybertensor/messages/network.py
+++ b/cybertensor/messages/network.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -22,12 +22,14 @@
from rich.prompt import Confirm
import cybertensor
-from cybertensor import Balance
+from cybertensor import __console__ as console
+from cybertensor.utils.balance import Balance
+from cybertensor.wallet import Wallet
def register_subnetwork_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
wait_for_finalization: bool = True,
prompt: bool = False,
) -> bool:
@@ -35,7 +37,7 @@ def register_subnetwork_message(
Args:
cwtensor (cybertensor.cwtensor):
the CWTensor
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
wait_for_finalization (bool):
If set, waits for the transaction to be finalized on the chain before returning true,
@@ -50,14 +52,14 @@ def register_subnetwork_message(
your_balance = cwtensor.get_balance(wallet.coldkeypub.address)
burn_cost = Balance(cwtensor.get_subnet_burn_cost())
if burn_cost > your_balance:
- cybertensor.__console__.print(
+ console.print(
f"Your balance of: [green]{your_balance}[/green] is not enough to pay the subnet lock cost of: "
f"[green]{burn_cost}[/green]"
)
return False
if prompt:
- cybertensor.__console__.print(f"Your balance is: [green]{your_balance}[/green]")
+ console.print(f"Your balance is: [green]{your_balance}[/green]")
if not Confirm.ask(
f"Do you want to register a subnet for [green]{burn_cost}[/green]?"
):
@@ -65,7 +67,7 @@ def register_subnetwork_message(
wallet.coldkey # unlock coldkey
- with cybertensor.__console__.status(":satellite: Registering subnet..."):
+ with console.status(":satellite: Registering subnet..."):
create_register_network_msg = {"register_network": {}}
signer_wallet = LocalWallet(
PrivateKey(wallet.coldkey.private_key), cwtensor.address_prefix
@@ -77,7 +79,7 @@ def register_subnetwork_message(
tx = cwtensor.contract.execute(
create_register_network_msg, signer_wallet, gas, funds
)
- cybertensor.__console__.print(
+ console.print(
f":exclamation_mark: [yellow]Warning[/yellow]: TX {tx.tx_hash} broadcasted without finalization "
f"confirmation..."
)
@@ -85,25 +87,25 @@ def register_subnetwork_message(
tx = cwtensor.contract.execute(
create_register_network_msg, signer_wallet, gas, funds
)
- cybertensor.__console__.print(
+ console.print(
f":satellite: [green]Processing..[/green]: TX {tx.tx_hash} waiting to complete..."
)
try:
tx.wait_to_complete()
if tx.response.is_successful():
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [green]Registered subnetwork with netuid: "
f"{tx.response.events.get('wasm').get('netuid_to_register')}[/green]"
)
return True
else:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error:{tx.response.raw_log}"
)
time.sleep(0.5)
return False
except Exception as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error:{e}"
)
return False
@@ -114,7 +116,7 @@ def register_subnetwork_message(
def set_hyperparameter_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuid: int,
parameter: str,
value,
@@ -125,7 +127,7 @@ def set_hyperparameter_message(
Args:
cwtensor (cybertensor.cwtensor):
the CWTensor
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
netuid (int):
Subnetwork uid.
@@ -145,7 +147,7 @@ def set_hyperparameter_message(
"""
if cwtensor.get_subnet_owner(netuid) != wallet.coldkeypub.address:
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]This wallet doesn't own the specified subnet.[/red]"
)
return False
@@ -154,12 +156,12 @@ def set_hyperparameter_message(
message = HYPERPARAMS.get(parameter)
if message is None:
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Invalid hyperparameter specified.[/red]"
)
return False
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Setting hyperparameter {parameter} to {value} on subnet: {netuid} ..."
):
sudo_msg = {
@@ -172,29 +174,29 @@ def set_hyperparameter_message(
if not wait_for_finalization:
tx = cwtensor.contract.execute(sudo_msg, signer_wallet, gas)
- cybertensor.__console__.print(
+ console.print(
f":exclamation_mark: [yellow]Warning[/yellow]: TX {tx.tx_hash} broadcasted without confirmation..."
)
else:
tx = cwtensor.contract.execute(sudo_msg, signer_wallet, gas)
- cybertensor.__console__.print(
+ console.print(
f":satellite: [green]Processing..[/green]: TX {tx.tx_hash} waiting to complete..."
)
try:
tx.wait_to_complete()
if tx.response.is_successful():
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [green]Hyper parameter {parameter} changed to {value}[/green]"
)
return True
else:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error:{tx.response.raw_log}"
)
time.sleep(0.5)
return False
except Exception as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error:{e}"
)
return False
diff --git a/cybertensor/messages/prometheus.py b/cybertensor/messages/prometheus.py
index c073df5..c83a93c 100644
--- a/cybertensor/messages/prometheus.py
+++ b/cybertensor/messages/prometheus.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -20,13 +20,15 @@
import json
import cybertensor
-import cybertensor.utils.networking as net
+from cybertensor import __console__ as console
from cybertensor.types import PrometheusServeCallParams
+from cybertensor.utils import networking as net
+from cybertensor.wallet import Wallet
def prometheus_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
port: int,
netuid: int,
ip: int = None,
@@ -36,7 +38,7 @@ def prometheus_message(
Args:
cwtensor (cybertensor.cwtensor):
cybertensor cwtensor object.
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
ip (str):
endpoint host port i.e. 192.122.31.4
@@ -57,7 +59,7 @@ def prometheus_message(
if ip is None:
try:
external_ip = net.get_external_ip()
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [green]Found external ip: {external_ip}[/green]"
)
cybertensor.logging.success(
@@ -77,7 +79,7 @@ def prometheus_message(
"ip_type": net.ip_version(external_ip),
}
- with cybertensor.__console__.status(":satellite: Checking Prometheus..."):
+ with console.status(":satellite: Checking Prometheus..."):
neuron = cwtensor.get_neuron_for_pubkey_and_subnet(
wallet.hotkey.address, netuid=netuid
)
@@ -89,7 +91,7 @@ def prometheus_message(
}
if neuron_up_to_date:
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [green]Prometheus already Served[/green]\n"
f"[green not bold]- Status: [/green not bold] |"
f"[green not bold] ip: [/green not bold][white not bold]{net.int_to_ip(neuron.prometheus_info.ip)}[/white not bold] |"
@@ -98,7 +100,7 @@ def prometheus_message(
f"[green not bold] version: [/green not bold][white not bold]{neuron.prometheus_info.version}[/white not bold] |"
)
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [white]Prometheus already served.[/white] {external_ip}"
)
return True
@@ -106,7 +108,7 @@ def prometheus_message(
# Add netuid, not in prometheus_info
call_params["netuid"] = netuid
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Serving prometheus on: [white]{cwtensor.network}:{netuid}[/white] ..."
):
success, err = cwtensor._do_serve_prometheus(
@@ -117,13 +119,13 @@ def prometheus_message(
if wait_for_finalization:
if success is True:
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [green]Served prometheus[/green]\n"
f" [bold white]{json.dumps(call_params, indent=4, sort_keys=True)}[/bold white]"
)
return True
else:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [green]Failed to serve prometheus[/green] error: {err}"
)
return False
diff --git a/cybertensor/messages/registration.py b/cybertensor/messages/registration.py
index 76dba06..e8d31d1 100644
--- a/cybertensor/messages/registration.py
+++ b/cybertensor/messages/registration.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -24,13 +24,15 @@
from rich.prompt import Confirm
import cybertensor
-from cybertensor import Balance
+from cybertensor import __console__ as console
+from cybertensor.utils.balance import Balance
from cybertensor.utils.registration import POWSolution, create_pow
+from cybertensor.wallet import Wallet
def register_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuid: int,
wait_for_finalization: bool = True,
prompt: bool = False,
@@ -45,7 +47,7 @@ def register_message(
) -> bool:
r"""Registers the wallet to chain.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
netuid (int):
The netuid of the subnet to register on.
@@ -74,12 +76,12 @@ def register_message(
If we did not wait for finalization / inclusion, the response is true.
"""
if not cwtensor.subnet_exists(netuid):
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{netuid}[/bold white] does not exist."
)
return False
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Checking Account on [bold]subnet:{netuid}[/bold]..."
):
neuron = cwtensor.get_neuron_for_pubkey_and_subnet(
@@ -103,14 +105,14 @@ def register_message(
# Attempt rolling registration.
attempts = 1
while True:
- cybertensor.__console__.print(
+ console.print(
f":satellite: Registering...({attempts}/{max_allowed_attempts})"
)
# Solve latest POW.
if cuda:
if not torch.cuda.is_available():
if prompt:
- cybertensor.__console__.error("CUDA is not available.")
+ console.error("CUDA is not available.")
return False
pow_result: Optional[POWSolution] = create_pow(
cwtensor,
@@ -143,14 +145,14 @@ def register_message(
netuid=netuid, hotkey=wallet.hotkey.address
)
if is_registered:
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [green]Already registered on netuid:{netuid}[/green]"
)
return True
# pow successful, proceed to submit pow to chain for registration
else:
- with cybertensor.__console__.status(":satellite: Submitting POW..."):
+ with console.status(":satellite: Submitting POW..."):
# check if pow result is still valid
while not pow_result.is_stale(cwtensor=cwtensor):
result: Tuple[bool, Optional[str]] = cwtensor._do_pow_register(
@@ -164,61 +166,61 @@ def register_message(
if success != True or success is False:
if "key is already registered" in err_msg:
# Error meant that the key is already registered.
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [green]Already Registered on [bold]subnet:{netuid}[/bold][/green]"
)
return True
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error:{err_msg}"
)
time.sleep(0.5)
# Successful registration, final check for neuron and pubkey
else:
- cybertensor.__console__.print(":satellite: Checking Balance...")
+ console.print(":satellite: Checking Balance...")
is_registered = cwtensor.is_hotkey_registered(
netuid=netuid, hotkey=wallet.hotkey.address
)
if is_registered:
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Registered[/green]"
)
return True
else:
# neuron not found, try again
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
)
continue
else:
# Exited loop because pow is no longer valid.
- cybertensor.__console__.print("[red]POW is stale.[/red]")
+ console.print("[red]POW is stale.[/red]")
# Try again.
continue
if attempts < max_allowed_attempts:
# Failed registration, retry pow
attempts += 1
- cybertensor.__console__.print(
+ console.print(
f":satellite: Failed registration, retrying pow ...({attempts}/{max_allowed_attempts})"
)
else:
# Failed to register after max attempts.
- cybertensor.__console__.print("[red]No more attempts.[/red]")
+ console.print("[red]No more attempts.[/red]")
return False
def burned_register_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuid: int,
wait_for_finalization: bool = True,
prompt: bool = False,
) -> bool:
r"""Registers the wallet to chain by recycling GBOOT.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
netuid (int):
The netuid of the subnet to register on.
@@ -233,13 +235,13 @@ def burned_register_message(
If we did not wait for finalization / inclusion, the response is true.
"""
if not cwtensor.subnet_exists(netuid):
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{netuid}[/bold white] does not exist."
)
return False
wallet.coldkey # unlock coldkey
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Checking Account on [bold]subnet:{netuid}[/bold]..."
):
neuron = cwtensor.get_neuron_for_pubkey_and_subnet(
@@ -250,7 +252,7 @@ def burned_register_message(
burn_amount = Balance(cwtensor.burn(netuid=netuid))
if not neuron.is_null:
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [green]Already Registered[/green]:\n"
f"uid: [bold white]{neuron.uid}[/bold white]\n"
f"netuid: [bold white]{neuron.netuid}[/bold white]\n"
@@ -264,7 +266,7 @@ def burned_register_message(
if not Confirm.ask(f"Recycle {burn_amount} to register on subnet:{netuid}?"):
return False
- with cybertensor.__console__.status(":satellite: Recycling BOOT for Registration..."):
+ with console.status(":satellite: Recycling BOOT for Registration..."):
success, err_msg = cwtensor._do_burned_register(
netuid=netuid,
burn=burn_amount.__int__(),
@@ -273,19 +275,19 @@ def burned_register_message(
)
if success is not True:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error:{err_msg}"
)
time.sleep(0.5)
# Successful registration, final check for neuron and pubkey
else:
- cybertensor.__console__.print(":satellite: Checking Balance...")
+ console.print(":satellite: Checking Balance...")
new_balance = cwtensor.get_balance(
wallet.coldkeypub.address
)
- cybertensor.__console__.print(
+ console.print(
f"Balance:\n"
f" [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]"
)
@@ -293,13 +295,13 @@ def burned_register_message(
netuid=netuid, hotkey=wallet.hotkey.address
)
if is_registered:
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Registered[/green]"
)
return True
else:
# neuron not found, try again
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
)
diff --git a/cybertensor/messages/root.py b/cybertensor/messages/root.py
index b55f440..9a96eb0 100644
--- a/cybertensor/messages/root.py
+++ b/cybertensor/messages/root.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -25,20 +25,22 @@
from rich.prompt import Confirm
import cybertensor
-import cybertensor.utils.weight_utils as weight_utils
+from cybertensor import __console__ as console
+from cybertensor.utils.weight_utils import normalize_max_weight, convert_weights_and_uids_for_emit
+from cybertensor.wallet import Wallet
logger = logger.opt(colors=True)
def root_register_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
wait_for_finalization: bool = True,
prompt: bool = False,
) -> bool:
r"""Registers the wallet to root network.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
wait_for_finalization (bool):
If set, waits for the extrinsic to be finalized on the chain before returning true,
@@ -57,7 +59,7 @@ def root_register_message(
netuid=0, hotkey=wallet.hotkey.address
)
if is_registered:
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Already registered on root network.[/green]"
)
return True
@@ -67,38 +69,35 @@ def root_register_message(
if not Confirm.ask("Register to root network?"):
return False
- with cybertensor.__console__.status(":satellite: Registering to root network..."):
- success, err_msg = cwtensor._do_root_register(
+ with console.status(":satellite: Registering to root network..."):
+ success = cwtensor._do_root_register(
wallet=wallet,
wait_for_finalization=wait_for_finalization,
)
-
- if success != True or success is False:
- cybertensor.__console__.print(
- f":cross_mark: [red]Failed[/red]: error:{err_msg}"
- )
- time.sleep(0.5)
+ time.sleep(0.5)
# Successful registration, final check for neuron and pubkey
- else:
+ if success is True:
is_registered = cwtensor.is_hotkey_registered(
netuid=0, hotkey=wallet.hotkey.address
)
if is_registered:
- cybertensor.__console__.print(
- ":white_heavy_check_mark: [green]Registered[/green]"
+ console.print(
+ ":white_heavy_check_mark: [green]Registered in root[/green]"
)
return True
else:
# neuron not found, try again
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
)
+ return False
+
def set_root_weights_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuids: Union[torch.LongTensor, list],
weights: Union[torch.FloatTensor, list],
version_key: int = 0,
@@ -107,7 +106,7 @@ def set_root_weights_message(
) -> bool:
r"""Sets the given weights and values on chain for wallet hotkey account.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
netuids (List[int]):
netuid of the subnet to set weights for.
@@ -146,12 +145,8 @@ def set_root_weights_message(
)
# Normalize the weights to max value.
- formatted_weights = cybertensor.utils.weight_utils.normalize_max_weight(
- x=weights, limit=max_weight_limit
- )
- cybertensor.__console__.print(
- f"\nNormalized weights: \n\t{weights} -> {formatted_weights}\n"
- )
+ formatted_weights = normalize_max_weight(x=weights, limit=max_weight_limit)
+ console.print(f"\nNormalized weights: \n\t{weights} -> {formatted_weights}\n")
# Ask before moving on.
if prompt:
@@ -162,52 +157,17 @@ def set_root_weights_message(
):
return False
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Setting root weights on [white]{cwtensor.network}[/white] ..."
):
- try:
- weight_uids, weight_vals = weight_utils.convert_weights_and_uids_for_emit(
- netuids, weights
- )
- success, error_message = cwtensor._do_set_weights(
- wallet=wallet,
- netuid=0,
- uids=weight_uids,
- vals=weight_vals,
- version_key=version_key,
- wait_for_finalization=wait_for_finalization,
- )
-
- cybertensor.__console__.print(success, error_message)
-
- if not wait_for_finalization:
- return True
-
- if success is True:
- cybertensor.__console__.print(
- ":white_heavy_check_mark: [green]Finalized[/green]"
- )
- cybertensor.logging.success(
- prefix="Set weights",
- sufix="Finalized: " + str(success),
- )
- return True
- else:
- cybertensor.__console__.print(
- f":cross_mark: [red]Failed[/red]: error:{error_message}"
- )
- cybertensor.logging.warning(
- prefix="Set weights",
- sufix=f"Failed: {error_message}",
- )
- return False
-
- except Exception as e:
- # TODO( devs ): lets remove all of the cybertensor.__console__ calls and replace with loguru.
- cybertensor.__console__.print(
- f":cross_mark: [red]Failed[/red]: error:{e}"
- )
- cybertensor.logging.warning(
- prefix="Set weights", sufix=f"Failed: {e}"
- )
- return False
+ weight_uids, weight_vals = convert_weights_and_uids_for_emit(
+ netuids, weights
+ )
+ return cwtensor._do_set_weights(
+ wallet=wallet,
+ netuid=0,
+ uids=weight_uids,
+ vals=weight_vals,
+ version_key=version_key,
+ wait_for_finalization=wait_for_finalization,
+ )
diff --git a/cybertensor/messages/serving.py b/cybertensor/messages/serving.py
index 492c981..3422578 100644
--- a/cybertensor/messages/serving.py
+++ b/cybertensor/messages/serving.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -21,13 +21,15 @@
from rich.prompt import Confirm
import cybertensor
-import cybertensor.utils.networking as net
+from cybertensor import __console__ as console
from cybertensor.types import AxonServeCallParams
+from cybertensor.utils import networking as net
+from cybertensor.wallet import Wallet
def serve_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
ip: str,
port: int,
protocol: int,
@@ -37,9 +39,9 @@ def serve_message(
wait_for_finalization=True,
prompt: bool = False,
) -> bool:
- r"""Subscribes an cybertensor endpoint to the substensor chain.
+ r"""Subscribes a cybertensor endpoint to the substensor chain.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
ip (str):
endpoint host port i.e. 192.122.31.4
@@ -167,7 +169,7 @@ def serve_axon_message(
if axon.external_ip is None:
try:
external_ip = net.get_external_ip()
- cybertensor.__console__.print(
+ console.print(
f":white_heavy_check_mark: [green]Found external ip: {external_ip}[/green]"
)
cybertensor.logging.success(
diff --git a/cybertensor/messages/set_weights.py b/cybertensor/messages/set_weights.py
index e5d8105..3970769 100644
--- a/cybertensor/messages/set_weights.py
+++ b/cybertensor/messages/set_weights.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -24,14 +24,16 @@
from rich.prompt import Confirm
import cybertensor
-import cybertensor.utils.weight_utils as weight_utils
+from cybertensor import __console__ as console
+from cybertensor.utils import weight_utils
+from cybertensor.wallet import Wallet
logger = logger.opt(colors=True)
def set_weights_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuid: int,
uids: Union[torch.LongTensor, list],
weights: Union[torch.FloatTensor, list],
@@ -41,7 +43,7 @@ def set_weights_message(
) -> bool:
r"""Sets the given weights and values on chain for wallet hotkey account.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
netuid (int):
netuid of the subnet to set weights for.
@@ -81,11 +83,10 @@ def set_weights_message(
):
return False
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Setting weights on [white]{cwtensor.network}[/white] ..."
):
- try:
- success, error_message = cwtensor._do_set_weights(
+ return cwtensor._do_set_weights(
wallet=wallet,
netuid=netuid,
uids=weight_uids,
@@ -93,33 +94,3 @@ def set_weights_message(
version_key=version_key,
wait_for_finalization=wait_for_finalization,
)
-
- if not wait_for_finalization:
- return True
-
- if success is True:
- cybertensor.__console__.print(
- ":white_heavy_check_mark: [green]Finalized[/green]"
- )
- cybertensor.logging.success(
- prefix="Set weights",
- sufix=f"Finalized: {success}",
- )
- return True
- else:
- cybertensor.__console__.print(
- f":cross_mark: [red]Failed[/red]: error:{error_message}",
- )
- cybertensor.logging.warning(
- prefix="Set weights",
- sufix=f"Failed: {error_message}",
- )
- return False
-
- except Exception as e:
- # TODO( devs ): lets remove all of the cybertensor.__console__ calls and replace with loguru.
- cybertensor.__console__.print(f":cross_mark: [red]Failed[/red]: error:{e}")
- cybertensor.logging.warning(
- prefix="Set weights", sufix=f"Failed: {e}"
- )
- return False
diff --git a/cybertensor/messages/staking.py b/cybertensor/messages/staking.py
index 1f57673..962368c 100644
--- a/cybertensor/messages/staking.py
+++ b/cybertensor/messages/staking.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -23,12 +23,14 @@
from rich.prompt import Confirm
import cybertensor
+from cybertensor import __console__ as console
from cybertensor.utils.balance import Balance
+from cybertensor.wallet import Wallet
def add_stake_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkey: Optional[str] = None,
amount: Union[Balance, float] = None,
wait_for_finalization: bool = True,
@@ -36,7 +38,7 @@ def add_stake_message(
) -> bool:
r"""Adds the specified amount of stake to passed hotkey uid.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
hotkey (Optional[str]):
address of the hotkey account to stake to
@@ -69,7 +71,7 @@ def add_stake_message(
# Flag to indicate if we are using the wallet's own hotkey.
own_hotkey: bool
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Syncing with chain: [white]{cwtensor.network}[/white] ..."
):
old_balance = cwtensor.get_balance(wallet.coldkeypub.address)
@@ -91,24 +93,24 @@ def add_stake_message(
coldkey=wallet.coldkeypub.address, hotkey=hotkey
)
- # Convert to cybertensor.Balance
+ # Convert to Balance
if amount is None:
# Stake it all.
- staking_balance = cybertensor.Balance.from_gboot(old_balance.gboot)
- elif not isinstance(amount, cybertensor.Balance):
- staking_balance = cybertensor.Balance.from_gboot(amount)
+ staking_balance = Balance.from_gboot(old_balance.gboot)
+ elif not isinstance(amount, Balance):
+ staking_balance = Balance.from_gboot(amount)
else:
staking_balance = amount
# Remove existential balance to keep key alive.
- if staking_balance > cybertensor.Balance.from_boot(1000000):
- staking_balance = staking_balance - cybertensor.Balance.from_boot(1000000)
+ if staking_balance > Balance.from_boot(1000000):
+ staking_balance = staking_balance - Balance.from_boot(1000000)
else:
staking_balance = staking_balance
# Check enough to stake.
if staking_balance > old_balance:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Not enough stake[/red]:[bold white]\n"
f" balance:{old_balance}\n"
f" amount: {staking_balance}\n"
@@ -137,7 +139,7 @@ def add_stake_message(
return False
try:
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Staking to: [bold white]{cwtensor.network}[/bold white] ..."
):
staking_response: bool = __do_add_stake_single(
@@ -153,10 +155,10 @@ def add_stake_message(
if not wait_for_finalization:
return True
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..."
):
new_balance = cwtensor.get_balance(address=wallet.coldkeypub.address)
@@ -167,34 +169,34 @@ def add_stake_message(
block=block,
) # Get current stake
- cybertensor.__console__.print(
+ console.print(
f"Balance:\n"
f" [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]"
)
- cybertensor.__console__.print(
+ console.print(
f"Stake:\n"
f" [blue]{old_stake}[/blue] :arrow_right: [green]{new_stake}[/green]"
)
return True
else:
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Failed[/red]: Error unknown."
)
return False
except cybertensor.errors.NotRegisteredError as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Hotkey: {wallet.hotkey_str} is not registered.[/red]"
)
return False
except cybertensor.errors.StakeError as e:
- cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]")
+ console.print(f":cross_mark: [red]Stake Error: {e}[/red]")
return False
def add_stake_multiple_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkeys: List[str],
amounts: List[Union[Balance, float]] = None,
wait_for_finalization: bool = True,
@@ -202,7 +204,7 @@ def add_stake_multiple_message(
) -> bool:
r"""Adds stake to each hotkey in the list, using each amount, from a common coldkey.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object for the coldkey.
hotkeys (List[str]):
List of hotkeys to stake to.
@@ -234,7 +236,7 @@ def add_stake_multiple_message(
isinstance(amount, (Balance, float)) for amount in amounts
):
raise TypeError(
- "amounts must be a [list of cybertensor.Balance or float] or None"
+ "amounts must be a [list of Balance or float] or None"
)
if amounts is None:
@@ -242,7 +244,7 @@ def add_stake_multiple_message(
else:
# Convert to Balance
amounts = [
- cybertensor.Balance.from_gboot(amount)
+ Balance.from_gboot(amount)
if isinstance(amount, float)
else amount
for amount in amounts
@@ -256,7 +258,7 @@ def add_stake_multiple_message(
wallet.coldkey
old_stakes = []
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Syncing with chain: [white]{cwtensor.network}[/white] ..."
):
old_balance = cwtensor.get_balance(wallet.coldkeypub.address)
@@ -277,7 +279,7 @@ def add_stake_multiple_message(
if total_staking_boot == 0:
# Staking all to the first wallet.
if old_balance.boot > 1000000:
- old_balance -= cybertensor.Balance.from_boot(1000000)
+ old_balance -= Balance.from_boot(1000000)
elif total_staking_boot < 1000000:
# Staking less than 1000 boot to the wallets.
@@ -295,19 +297,19 @@ def add_stake_multiple_message(
zip(hotkeys, amounts, old_stakes)
):
staking_all = False
- # Convert to cybertensor.Balance
+ # Convert to Balance
if amount is None:
# Stake it all.
- staking_balance = cybertensor.Balance.from_gboot(old_balance.gboot)
+ staking_balance = Balance.from_gboot(old_balance.gboot)
staking_all = True
else:
# Amounts are cast to balance earlier in the function
- assert isinstance(amount, cybertensor.Balance)
+ assert isinstance(amount, Balance)
staking_balance = amount
# Check enough to stake
if staking_balance > old_balance:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Not enough balance[/red]: [green]{old_balance}[/green] "
f"to stake: [blue]{staking_balance}[/blue] from coldkey: [white]{wallet.name}[/white]"
)
@@ -338,7 +340,7 @@ def add_stake_multiple_message(
# Wait for tx rate limit.
tx_rate_limit_blocks = cwtensor.tx_rate_limit()
if tx_rate_limit_blocks > 0:
- cybertensor.__console__.print(
+ console.print(
f":hourglass: [yellow]Waiting for tx rate limit: [white]{tx_rate_limit_blocks}[/white] "
f"blocks[/yellow]"
)
@@ -353,7 +355,7 @@ def add_stake_multiple_message(
continue
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
@@ -366,7 +368,7 @@ def add_stake_multiple_message(
new_balance = cwtensor.get_balance(
wallet.coldkeypub.address, block=block
)
- cybertensor.__console__.print(
+ console.print(
f"Stake ({hotkey}): [blue]{old_stake}[/blue] :arrow_right: [green]{new_stake}[/green]"
)
old_balance = new_balance
@@ -376,26 +378,26 @@ def add_stake_multiple_message(
break
else:
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Failed[/red]: Error unknown."
)
continue
except cybertensor.errors.NotRegisteredError as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Hotkey: {hotkey} is not registered.[/red]"
)
continue
except cybertensor.errors.StakeError as e:
- cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]")
+ console.print(f":cross_mark: [red]Stake Error: {e}[/red]")
continue
if successful_stakes != 0:
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Checking Balance on: ([white]{cwtensor.network}[/white] ..."
):
new_balance = cwtensor.get_balance(wallet.coldkeypub.address)
- cybertensor.__console__.print(
+ console.print(
f"Balance: [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]"
)
return True
@@ -405,19 +407,19 @@ def add_stake_multiple_message(
def __do_add_stake_single(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkey: str,
- amount: "cybertensor.Balance",
+ amount: "Balance",
wait_for_finalization: bool = True,
) -> bool:
r"""
Executes a stake call to the chain using the wallet and amount specified.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
hotkey (str):
Hotkey to stake to.
- amount (cybertensor.Balance):
+ amount (Balance):
Amount to stake as cybertensor balance object.
wait_for_finalization (bool):
If set, waits for the extrinsic to be finalized on the chain before returning true,
diff --git a/cybertensor/messages/transfer.py b/cybertensor/messages/transfer.py
index 530661f..4f00bb7 100644
--- a/cybertensor/messages/transfer.py
+++ b/cybertensor/messages/transfer.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -24,13 +24,15 @@
from rich.prompt import Confirm
import cybertensor
-from ..utils import is_valid_address
-from ..utils.balance import Balance
+from cybertensor.utils import is_valid_address
+from cybertensor.utils.balance import Balance
+from cybertensor.wallet import Wallet
+from cybertensor import __console__ as console
def transfer_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
dest: Union[Address, str],
amount: Union[Balance, float],
wait_for_inclusion: bool = True,
@@ -40,7 +42,7 @@ def transfer_message(
) -> bool:
r"""Transfers funds from this wallet to the destination public key address
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object to make transfer from.
dest (Union[cosmpy.crypto.address.Address, str]):
Destination public key address of a receiver.
@@ -63,7 +65,7 @@ def transfer_message(
"""
# Validate destination address.
if not is_valid_address(dest):
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Invalid destination address[/red]:[bold white]\n {dest}[/bold white]"
)
return False
@@ -71,28 +73,28 @@ def transfer_message(
# Unlock wallet coldkey.
wallet.coldkey
- # Convert to cybertensor.Balance
- if not isinstance(amount, cybertensor.Balance):
- transfer_balance = cybertensor.Balance.from_gboot(amount)
+ # Convert to Balance
+ if not isinstance(amount, Balance):
+ transfer_balance = Balance.from_gboot(amount)
else:
transfer_balance = amount
# Check balance.
- with cybertensor.__console__.status(":satellite: Checking Balance..."):
+ with console.status(":satellite: Checking Balance..."):
account_balance = cwtensor.get_balance(wallet.coldkey.address)
# check existential deposit.
existential_deposit = cwtensor.get_existential_deposit()
- with cybertensor.__console__.status(":satellite: Transferring..."):
+ with console.status(":satellite: Transferring..."):
fee = cwtensor.get_transfer_fee()
if not keep_alive:
# Check if the transfer should keep_alive the account
- existential_deposit = cybertensor.Balance(0)
+ existential_deposit = Balance(0)
# Check if we have enough balance.
if account_balance < (transfer_balance + fee + existential_deposit):
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Not enough balance[/red]:[bold white]\n"
f" balance: {account_balance}\n"
f" amount: {transfer_balance}\n"
@@ -111,7 +113,7 @@ def transfer_message(
):
return False
- with cybertensor.__console__.status(":satellite: Transferring..."):
+ with console.status(":satellite: Transferring..."):
success, tx_hash, err_msg = cwtensor._do_transfer(
wallet,
Address(dest),
@@ -121,27 +123,27 @@ def transfer_message(
)
if success:
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
- cybertensor.__console__.print(f"[green]Tx Hash: {tx_hash}[/green]")
+ console.print(f"[green]Tx Hash: {tx_hash}[/green]")
explorer_url = cybertensor.utils.get_explorer_url_for_network(
- cwtensor.network, tx_hash, cwtensor.network_explorer
+ network_config=cwtensor.network_config, tx_hash=tx_hash
)
if explorer_url is not None:
- cybertensor.__console__.print(
+ console.print(
f"[green]Explorer Link: {explorer_url}[/green]"
)
else:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Failed[/red]: error:{err_msg}"
)
if success:
- with cybertensor.__console__.status(":satellite: Checking Balance..."):
+ with console.status(":satellite: Checking Balance..."):
new_balance = cwtensor.get_balance(wallet.coldkey.address)
- cybertensor.__console__.print(
+ console.print(
f"Balance:\n"
f" [blue]{account_balance}[/blue] :arrow_right: [green]{new_balance}[/green]"
)
diff --git a/cybertensor/messages/unstaking.py b/cybertensor/messages/unstaking.py
index 24dec48..86939b7 100644
--- a/cybertensor/messages/unstaking.py
+++ b/cybertensor/messages/unstaking.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -23,24 +23,26 @@
from rich.prompt import Confirm
import cybertensor
+from cybertensor import __console__ as console
from cybertensor.utils.balance import Balance
+from cybertensor.wallet import Wallet
def __do_remove_stake_single(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkey: str,
- amount: "cybertensor.Balance",
+ amount: "Balance",
wait_for_finalization: bool = True,
) -> bool:
r"""
Executes an unstake call to the chain using the wallet and amount specified.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
Cybertensor wallet object.
hotkey (str):
Hotkey address to unstake from.
- amount (cybertensor.Balance):
+ amount (Balance):
Amount to unstake as cybertensor balance object.
wait_for_finalization (bool):
If set, waits for the extrinsic to be finalized on the chain before returning true,
@@ -73,7 +75,7 @@ def __do_remove_stake_single(
def unstake_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkey: Optional[str] = None,
amount: Union[Balance, float] = None,
wait_for_finalization: bool = True,
@@ -81,7 +83,7 @@ def unstake_message(
) -> bool:
r"""Removes stake into the wallet coldkey from the specified hotkey uid.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
cybertensor wallet object.
hotkey (Optional[str]):
address of the hotkey to unstake from.
@@ -104,7 +106,7 @@ def unstake_message(
if hotkey is None:
hotkey = wallet.hotkey.address # Default to wallet's own hotkey.
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Syncing with chain: [white]{cwtensor.network}[/white] ..."
):
old_balance = cwtensor.get_balance(wallet.coldkeypub.address)
@@ -112,19 +114,19 @@ def unstake_message(
coldkey=wallet.coldkeypub.address, hotkey=hotkey
)
- # Convert to cybertensor.Balance
+ # Convert to Balance
if amount is None:
# Unstake it all.
unstaking_balance = old_stake
- elif not isinstance(amount, cybertensor.Balance):
- unstaking_balance = cybertensor.Balance.from_gboot(amount)
+ elif not isinstance(amount, Balance):
+ unstaking_balance = Balance.from_gboot(amount)
else:
unstaking_balance = amount
# Check enough to unstake.
stake_on_uid = old_stake
if unstaking_balance > stake_on_uid:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Not enough stake[/red]: [green]{stake_on_uid}[/green] "
f"to unstake: [blue]{unstaking_balance}[/blue] from hotkey: [white]{wallet.hotkey_str}[/white]"
)
@@ -140,7 +142,7 @@ def unstake_message(
return False
try:
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Unstaking from chain: [white]{cwtensor.network}[/white] ..."
):
staking_response: bool = __do_remove_stake_single(
@@ -156,44 +158,44 @@ def unstake_message(
if not wait_for_finalization:
return True
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..."
):
new_balance = cwtensor.get_balance(address=wallet.coldkeypub.address)
new_stake = cwtensor.get_stake_for_coldkey_and_hotkey(
coldkey=wallet.coldkeypub.address, hotkey=hotkey
) # Get stake on hotkey.
- cybertensor.__console__.print(
+ console.print(
f"Balance:\n"
f" [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]"
)
- cybertensor.__console__.print(
+ console.print(
f"Stake:\n"
f" [blue]{old_stake}[/blue] :arrow_right: [green]{new_stake}[/green]"
)
return True
else:
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Failed[/red]: Error unknown."
)
return False
except cybertensor.errors.NotRegisteredError as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Hotkey: {wallet.hotkey_str} is not registered.[/red]"
)
return False
except cybertensor.errors.StakeError as e:
- cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]")
+ console.print(f":cross_mark: [red]Stake Error: {e}[/red]")
return False
def unstake_multiple_message(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
hotkey: List[str],
amounts: List[Union[Balance, float]] = None,
wait_for_finalization: bool = True,
@@ -201,7 +203,7 @@ def unstake_multiple_message(
) -> bool:
r"""Removes stake from each hotkey in the list, using each amount, to a common coldkey.
Args:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
The wallet with the coldkey to unstake to.
hotkey (List[str]):
List of hotkeys to unstake from.
@@ -233,7 +235,7 @@ def unstake_multiple_message(
isinstance(amount, (Balance, float)) for amount in amounts
):
raise TypeError(
- "amounts must be a [list of cybertensor.Balance or float] or None"
+ "amounts must be a [list of Balance or float] or None"
)
if amounts is None:
@@ -241,7 +243,7 @@ def unstake_multiple_message(
else:
# Convert to Balance
amounts = [
- cybertensor.Balance.from_gboot(amount)
+ Balance.from_gboot(amount)
if isinstance(amount, float)
else amount
for amount in amounts
@@ -255,7 +257,7 @@ def unstake_multiple_message(
wallet.coldkey
old_stakes = []
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Syncing with chain: [white]{cwtensor.network}[/white] ..."
):
old_balance = cwtensor.get_balance(wallet.coldkeypub.address)
@@ -268,19 +270,19 @@ def unstake_multiple_message(
successful_unstakes = 0
for idx, (hotkey, amount, old_stake) in enumerate(zip(hotkey, amounts, old_stakes)):
- # Covert to cybertensor.Balance
+ # Covert to Balance
if amount is None:
# Unstake it all.
unstaking_balance = old_stake
- elif not isinstance(amount, cybertensor.Balance):
- unstaking_balance = cybertensor.Balance.from_gboot(amount)
+ elif not isinstance(amount, Balance):
+ unstaking_balance = Balance.from_gboot(amount)
else:
unstaking_balance = amount
# Check enough to unstake.
stake_on_uid = old_stake
if unstaking_balance > stake_on_uid:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]Not enough stake[/red]: [green]{stake_on_uid}[/green] "
f"to unstake: [blue]{unstaking_balance}[/blue] from hotkey: [white]{wallet.hotkey_str}[/white]"
)
@@ -296,7 +298,7 @@ def unstake_multiple_message(
continue
try:
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Unstaking from chain: [white]{cwtensor.network}[/white] ..."
):
staking_response: bool = __do_remove_stake_single(
@@ -314,7 +316,7 @@ def unstake_multiple_message(
# Wait for tx rate limit.
tx_rate_limit_blocks = cwtensor.tx_rate_limit()
if tx_rate_limit_blocks > 0:
- cybertensor.__console__.print(
+ console.print(
f":hourglass: [yellow]Waiting for tx rate limit: "
f"[white]{tx_rate_limit_blocks}[/white] blocks[/yellow]"
)
@@ -324,10 +326,10 @@ def unstake_multiple_message(
successful_unstakes += 1
continue
- cybertensor.__console__.print(
+ console.print(
":white_heavy_check_mark: [green]Finalized[/green]"
)
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Checking Balance on: [white]{cwtensor.network}[/white] ..."
):
block = cwtensor.get_current_block()
@@ -336,31 +338,31 @@ def unstake_multiple_message(
hotkey=hotkey,
block=block,
)
- cybertensor.__console__.print(
+ console.print(
f"Stake ({hotkey}): [blue]{stake_on_uid}[/blue] :arrow_right: [green]{new_stake}[/green]"
)
successful_unstakes += 1
else:
- cybertensor.__console__.print(
+ console.print(
":cross_mark: [red]Failed[/red]: Error unknown."
)
continue
except cybertensor.errors.NotRegisteredError as e:
- cybertensor.__console__.print(
+ console.print(
f":cross_mark: [red]{hotkey} is not registered.[/red]"
)
continue
except cybertensor.errors.StakeError as e:
- cybertensor.__console__.print(f":cross_mark: [red]Stake Error: {e}[/red]")
+ console.print(f":cross_mark: [red]Stake Error: {e}[/red]")
continue
if successful_unstakes != 0:
- with cybertensor.__console__.status(
+ with console.status(
f":satellite: Checking Balance on: ([white]{cwtensor.network}[/white] ..."
):
new_balance = cwtensor.get_balance(wallet.coldkeypub.address)
- cybertensor.__console__.print(
+ console.print(
f"Balance: [blue]{old_balance}[/blue] :arrow_right: [green]{new_balance}[/green]"
)
return True
diff --git a/cybertensor/metagraph.py b/cybertensor/metagraph.py
index df8d351..7368264 100644
--- a/cybertensor/metagraph.py
+++ b/cybertensor/metagraph.py
@@ -2,7 +2,7 @@
# Copyright © 2021 Yuma Rao
# Copyright © 2023 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
diff --git a/cybertensor/stream.py b/cybertensor/stream.py
index 0ddd795..6367d9f 100644
--- a/cybertensor/stream.py
+++ b/cybertensor/stream.py
@@ -6,7 +6,7 @@
from starlette.responses import StreamingResponse as _StreamingResponse
from starlette.types import Send, Receive, Scope
-import cybertensor
+from cybertensor.synapse import Synapse
class BTStreamingResponseModel(BaseModel):
@@ -30,7 +30,7 @@ class BTStreamingResponseModel(BaseModel):
token_streamer: Callable[[Send], Awaitable[None]]
-class StreamingSynapse(cybertensor.Synapse, ABC):
+class StreamingSynapse(Synapse, ABC):
"""
The StreamingSynapse class is designed to be subclassed for handling streaming responses in the Cybertensor network.
It provides abstract methods that must be implemented by the subclass to deserialize, process streaming responses,
diff --git a/cybertensor/synapse.py b/cybertensor/synapse.py
index 137e086..ec8d244 100644
--- a/cybertensor/synapse.py
+++ b/cybertensor/synapse.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
diff --git a/cybertensor/threadpool.py b/cybertensor/threadpool.py
index 1b2694c..17842b8 100644
--- a/cybertensor/threadpool.py
+++ b/cybertensor/threadpool.py
@@ -19,7 +19,8 @@
from loguru import logger
-import cybertensor
+from cybertensor import __blocktime__
+from cybertensor.config import Config
# Workers are created as daemon threads. This is done to allow the interpreter
# to exit when there are still idle threads in a ThreadPoolExecutor's thread
@@ -51,7 +52,7 @@ def run(self):
"""Run the given work item"""
# Checks if future is canceled or if work item is stale
if (not self.future.set_running_or_notify_cancel()) or (
- time.time() - self.start_time > cybertensor.__blocktime__
+ time.time() - self.start_time > __blocktime__
):
return
@@ -193,13 +194,13 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None):
pass
@classmethod
- def config(cls) -> "cybertensor.config":
+ def config(cls) -> "Config":
"""Get config from the argument parser
- Return: cybertensor.config object
+ Return: Config object
"""
parser = argparse.ArgumentParser()
PriorityThreadPoolExecutor.add_args(parser)
- return cybertensor.config(parser, args=[])
+ return Config(parser, args=[])
@property
def is_empty(self):
diff --git a/cybertensor/types.py b/cybertensor/types.py
index 6c29423..1e4341a 100644
--- a/cybertensor/types.py
+++ b/cybertensor/types.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2023 Opentensor Technologies Inc
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
diff --git a/cybertensor/utils/__init__.py b/cybertensor/utils/__init__.py
index 0a466cb..284fc6c 100644
--- a/cybertensor/utils/__init__.py
+++ b/cybertensor/utils/__init__.py
@@ -1,7 +1,7 @@
# The MIT License (MIT)
# Copyright © 2022 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -21,8 +21,14 @@
import requests
-from .formatting import get_human_readable, millify
-from .wallet_utils import *
+import cybertensor
+from cybertensor import NetworkConfigCwTensor
+from cybertensor.utils.formatting import get_human_readable, millify
+from cybertensor.utils.wallet_utils import (
+ is_valid_cybertensor_address_or_public_key,
+ is_valid_address,
+ coin_from_str,
+)
GIGA = 1e9
U16_MAX = 65535
@@ -88,15 +94,14 @@ def get_explorer_root_url_by_network_from_map(
def get_explorer_url_for_network(
- network: str, tx_hash: str, network_map: Dict[str, str]
+ network_config: "NetworkConfigCwTensor", tx_hash: str
) -> Optional[str]:
r"""
- Returns the explorer url for the given block hash and network.
+ Returns the explorer url for the given tx hash and network config.
Args:
- network(str): The network to get the explorer url for.
+ network_config("NetworkConfigCwTensor"): The network config to get the explorer url for.
tx_hash(str): The transaction hash to get the explorer url for.
- network_map(Dict[str, str]): The network map to get the explorer url from.
Returns:
The explorer url for the given block hash and network.
@@ -104,10 +109,7 @@ def get_explorer_url_for_network(
"""
explorer_url: Optional[str] = None
- # Will be None if the network is not known. i.e. not in network_map
- explorer_root_url: Optional[str] = get_explorer_root_url_by_network_from_map(
- network, network_map
- )
+ explorer_root_url = network_config.network_explorer
if explorer_root_url is not None:
# We are on a known network.
diff --git a/cybertensor/utils/_register_cuda.py b/cybertensor/utils/_register_cuda.py
index 52313e9..237f060 100644
--- a/cybertensor/utils/_register_cuda.py
+++ b/cybertensor/utils/_register_cuda.py
@@ -1,14 +1,13 @@
import binascii
import hashlib
+import io
import math
+from contextlib import redirect_stdout
from typing import Tuple
import numpy as np
from Crypto.Hash import keccak
-from contextlib import redirect_stdout
-import io
-
def solve_cuda(
nonce_start: np.int64,
@@ -51,7 +50,7 @@ def solve_cuda(
upper_bytes = upper.to_bytes(32, byteorder="little", signed=False)
- def _hex_bytes_to_u8_list(hex_bytes: bytes):
+ def _hex_bytes_to_u8_list(hex_bytes: bytes) -> list[int]:
hex_chunks = [
int(hex_bytes[i : i + 2], 16) for i in range(0, len(hex_bytes), 2)
]
@@ -65,7 +64,7 @@ def _create_seal_hash(block_and_hotkey_hash_hex: bytes, nonce: int) -> bytes:
seal = kec.update(seal_sh256).digest()
return seal
- def _seal_meets_difficulty(seal: bytes, difficulty: int):
+ def _seal_meets_difficulty(seal: bytes, difficulty: int) -> bool:
seal_number = int.from_bytes(seal, "big")
product = seal_number * difficulty
limit = int(math.pow(2, 256)) - 1
@@ -96,7 +95,7 @@ def _seal_meets_difficulty(seal: bytes, difficulty: int):
return solution, seal
-def reset_cuda():
+def reset_cuda() -> None:
"""
Resets the CUDA environment.
"""
diff --git a/cybertensor/utils/balance.py b/cybertensor/utils/balance.py
index d14208d..0625209 100644
--- a/cybertensor/utils/balance.py
+++ b/cybertensor/utils/balance.py
@@ -2,7 +2,7 @@
# Copyright © 2021-2022 Yuma Rao
# Copyright © 2022 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -22,7 +22,7 @@
from cosmpy.aerial.client import Coin
-import cybertensor
+from cybertensor import __giga_boot_symbol__, __boot_symbol__
class Balance:
@@ -38,8 +38,8 @@ class Balance:
gboot: A float property that gives the balance in gboot units.
"""
- unit: str = cybertensor.__giga_boot_symbol__ # This is the gboot unit
- boot_unit: str = cybertensor.__boot_symbol__ # This is the boot unit
+ unit: str = __giga_boot_symbol__ # This is the gboot unit
+ boot_unit: str = __boot_symbol__ # This is the boot unit
boot: int
gboot: float
diff --git a/cybertensor/utils/networking.py b/cybertensor/utils/networking.py
index 96f0a05..b22ac02 100644
--- a/cybertensor/utils/networking.py
+++ b/cybertensor/utils/networking.py
@@ -2,7 +2,7 @@
# Copyright © 2021-2022 Yuma Rao
# Copyright © 2022-2023 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
diff --git a/cybertensor/utils/registration.py b/cybertensor/utils/registration.py
index 73f1d76..3fb4d52 100644
--- a/cybertensor/utils/registration.py
+++ b/cybertensor/utils/registration.py
@@ -17,8 +17,10 @@
from rich import status as rich_status
import cybertensor
-from ._register_cuda import solve_cuda
-from .formatting import get_human_readable, millify
+from cybertensor import __console__ as console
+from cybertensor.utils._register_cuda import solve_cuda
+from cybertensor.utils.formatting import get_human_readable, millify
+from cybertensor.wallet import Wallet
class CUDAException(Exception):
@@ -28,7 +30,7 @@ class CUDAException(Exception):
def _hex_bytes_to_u8_list(hex_bytes: bytes):
- hex_chunks = [int(hex_bytes[i : i + 2], 16) for i in range(0, len(hex_bytes), 2)]
+ hex_chunks = [int(hex_bytes[i: i + 2], 16) for i in range(0, len(hex_bytes), 2)]
return hex_chunks
@@ -452,8 +454,8 @@ def update(self, stats: RegistrationStatistics, verbose: bool = False) -> None:
def _solve_for_difficulty_fast(
- cwtensor,
- wallet: "cybertensor.wallet",
+ cwtensor: "cybertensor.cwtensor",
+ wallet: "Wallet",
netuid: int,
output_in_place: bool = True,
num_processes: Optional[int] = None,
@@ -465,9 +467,9 @@ def _solve_for_difficulty_fast(
"""
Solves the POW for registration using multiprocessing.
Args:
- cwtensor
+ cwtensor: cybertensor.cwtensor
cwtensor to connect to for block information and to submit.
- wallet:
+ wallet: Wallet
wallet to use for registration.
netuid: int
The netuid of the subnet to register to.
@@ -578,7 +580,6 @@ def _solve_for_difficulty_fast(
start_time_perpetual = time.time()
- console = cybertensor.__console__
logger = RegistrationStatisticsLogger(console, output_in_place)
logger.start()
@@ -799,7 +800,7 @@ def _check_for_newest_block_and_update(
def _solve_for_difficulty_fast_cuda(
cwtensor: "cybertensor.cwtensor",
- wallet: "cybertensor.wallet",
+ wallet: "Wallet",
netuid: int,
output_in_place: bool = True,
update_interval: int = 50_000,
@@ -814,7 +815,7 @@ def _solve_for_difficulty_fast_cuda(
Args:
cwtensor: cybertensor.cwtensor
The cwtensor node to grab blocks
- wallet: cybertensor.wallet
+ wallet: Wallet
The wallet to register
netuid: int
The netuid of the subnet to register to.
@@ -926,7 +927,6 @@ def _solve_for_difficulty_fast_cuda(
start_time_perpetual = time.time()
- console = cybertensor.__console__
logger = RegistrationStatisticsLogger(console, output_in_place)
logger.start()
@@ -1023,8 +1023,8 @@ def _terminate_workers_and_wait_for_exit(
def create_pow(
- cwtensor,
- wallet,
+ cwtensor: "cybertensor.cwtensor",
+ wallet: Wallet,
netuid: int,
output_in_place: bool = True,
cuda: bool = False,
@@ -1037,9 +1037,9 @@ def create_pow(
"""
Creates a proof of work for the given cwtensor and wallet.
Args:
- cwtensor (:obj:`cybertensor.cwtensor.cwtensor`, `required`):
+ cwtensor (:obj:`cybertensor.cwtensor`, `required`):
The cwtensor to create a proof of work for.
- wallet (:obj:`cybertensor.wallet.wallet`, `required`):
+ wallet (:obj:`Wallet.wallet`, `required`):
The wallet to create a proof of work for.
netuid (:obj:`int`, `required`):
The netuid for the subnet to create a proof of work for.
diff --git a/cybertensor/utils/stats.py b/cybertensor/utils/stats.py
index f114af2..9a89758 100644
--- a/cybertensor/utils/stats.py
+++ b/cybertensor/utils/stats.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -20,7 +20,7 @@
class timed_rolling_avg:
- """A exponential moving average that updates values based on time since last update."""
+ """An exponential moving average that updates values based on time since last update."""
def __init__(self, initial_value, alpha):
self.value = initial_value
@@ -37,7 +37,7 @@ def update(self, new_value):
class AmountPerSecondRollingAverage:
- """A exponential moving average that counts quantity per second."""
+ """An exponential moving average that counts quantity per second."""
def __init__(self, initial_value=0, alpha=0.1):
self.value = initial_value
@@ -60,7 +60,7 @@ def get(self) -> float:
class EventsPerSecondRollingAverage:
- """A exponential moving average that counts the number of events per second."""
+ """An exponential moving average that counts the number of events per second."""
def __init__(self, initial_value, alpha):
self.value = initial_value
diff --git a/cybertensor/utils/wallet_utils.py b/cybertensor/utils/wallet_utils.py
index 64e4e8d..25da987 100644
--- a/cybertensor/utils/wallet_utils.py
+++ b/cybertensor/utils/wallet_utils.py
@@ -2,7 +2,7 @@
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -24,10 +24,12 @@
from cosmpy.aerial.client import Coin
from cosmpy.crypto.address import Address
-import cybertensor
+from cybertensor import __chain_address_prefix__
-def is_valid_cybertensor_address_or_public_key(address: Union[str, bytes, Address]) -> bool:
+def is_valid_cybertensor_address_or_public_key(
+ address: Union[str, bytes, Address]
+) -> bool:
"""
Checks if the given address is a valid destination address.
@@ -37,9 +39,10 @@ def is_valid_cybertensor_address_or_public_key(address: Union[str, bytes, Addres
Returns:
True if the address is a valid destination address, False otherwise.
"""
-
- # TODO
- return True
+ if address is not None:
+ return is_valid_address(address)
+ # TODO add public key validation
+ return False
def is_valid_address(address: Union[str, Address]) -> bool:
@@ -54,7 +57,7 @@ def is_valid_address(address: Union[str, Address]) -> bool:
"""
try:
Address(address)
- if address.startswith(cybertensor.__chain_address_prefix__):
+ if address.startswith(__chain_address_prefix__):
return True
except RuntimeError:
pass
diff --git a/cybertensor/utils/weight_utils.py b/cybertensor/utils/weight_utils.py
index 9a42b66..1dd4bb7 100644
--- a/cybertensor/utils/weight_utils.py
+++ b/cybertensor/utils/weight_utils.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -230,7 +230,7 @@ def process_weights_for_netuid(
if not isinstance(weights, torch.FloatTensor):
weights = weights.type(torch.float32)
- # Network configuration parameters from an cwtensor.
+ # Network configuration parameters from a cwtensor.
# These parameters determine the range of acceptable weights for each neuron.
quantile = exclude_quantile / U16_MAX
min_allowed_weights = cwtensor.min_allowed_weights(netuid=netuid)
@@ -259,7 +259,7 @@ def process_weights_for_netuid(
) # creating minimum even non-zero weights
weights[non_zero_weight_idx] += non_zero_weights
cybertensor.logging.debug("final_weights", weights)
- normalized_weights = cybertensor.utils.weight_utils.normalize_max_weight(
+ normalized_weights = normalize_max_weight(
x=weights, limit=max_weight_limit
)
return torch.tensor(list(range(len(normalized_weights)))), normalized_weights
@@ -283,7 +283,7 @@ def process_weights_for_netuid(
cybertensor.logging.debug("non_zero_weights", non_zero_weights)
# Normalize weights and return.
- normalized_weights = cybertensor.utils.weight_utils.normalize_max_weight(
+ normalized_weights = normalize_max_weight(
x=non_zero_weights, limit=max_weight_limit
)
cybertensor.logging.debug("final_weights", normalized_weights)
diff --git a/cybertensor/wallet.py b/cybertensor/wallet.py
index abab5d4..97a00da 100644
--- a/cybertensor/wallet.py
+++ b/cybertensor/wallet.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
@@ -24,6 +24,7 @@
from termcolor import colored
import cybertensor
+from cybertensor.config import Config
from cybertensor.keypair import Keypair
from cybertensor.utils import is_valid_cybertensor_address_or_public_key
@@ -55,7 +56,7 @@ def display_mnemonic_msg(keypair: Keypair, key_type: str):
)
-class wallet:
+class Wallet:
"""
Cybertensor wallet maintenance class. Each wallet contains a coldkey and a hotkey.
The coldkey is the user's primary key for holding stake in their wallet
@@ -65,16 +66,16 @@ class wallet:
"""
@classmethod
- def config(cls) -> "cybertensor.config":
+ def config(cls) -> "Config":
"""
Get config from the argument parser.
Returns:
- cybertensor.config: Config object.
+ Config: Config object.
"""
parser = argparse.ArgumentParser()
cls.add_args(parser)
- return cybertensor.config(parser, args=[])
+ return Config(parser, args=[])
@classmethod
def help(cls):
@@ -127,7 +128,7 @@ def __init__(
name: str = None,
hotkey: str = None,
path: str = None,
- config: "cybertensor.config" = None,
+ config: "Config" = None,
):
r"""
Initialize the cybertensor wallet object containing a hot and coldkey.
@@ -136,11 +137,11 @@ def __init__(
name (str, optional): The name of the wallet to unlock for running cybertensor. Defaults to 'default'.
hotkey (str, optional): The name of hotkey used to running the miner. Defaults to 'default'.
path (str, optional): The path to your cybertensor wallets. Defaults to '~/.cybertensor/wallets/'.
- config (cybertensor.config, optional): cybertensor.wallet.config(). Defaults to None.
+ config (Config, optional): Wallet.config(). Defaults to None.
"""
# Fill config from passed args using command line defaults.
if config is None:
- config = wallet.config()
+ config = Wallet.config()
self.config = copy.deepcopy(config)
self.config.wallet.name = name or self.config.wallet.get(
"name", cybertensor.defaults.wallet.name
@@ -180,7 +181,7 @@ def __repr__(self):
def create_if_non_existent(
self, coldkey_use_password: bool = True, hotkey_use_password: bool = False
- ) -> "wallet":
+ ) -> "Wallet":
"""
Checks for existing coldkeypub and hotkeys and creates them if non-existent.
@@ -195,7 +196,7 @@ def create_if_non_existent(
def create(
self, coldkey_use_password: bool = True, hotkey_use_password: bool = False
- ) -> "wallet":
+ ) -> "Wallet":
"""
Checks for existing coldkeypub and hotkeys and creates them if non-existent.
@@ -218,7 +219,7 @@ def create(
def recreate(
self, coldkey_use_password: bool = True, hotkey_use_password: bool = False
- ) -> "wallet":
+ ) -> "Wallet":
"""
Checks for existing coldkeypub and hotkeys and creates them if non-existent.
@@ -420,7 +421,7 @@ def new_coldkey(
use_password: bool = True,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
"""Creates a new coldkey, optionally encrypts it with the user's inputed password and saves to disk.
Args:
n_words: (int, optional):
@@ -430,7 +431,7 @@ def new_coldkey(
overwrite (bool, optional):
Will this operation overwrite the coldkey under the same path //coldkey
Returns:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
this object with newly created coldkey.
"""
self.create_new_coldkey(n_words, use_password, overwrite, suppress)
@@ -441,7 +442,7 @@ def create_new_coldkey(
use_password: bool = True,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
"""Creates a new coldkey, optionally encrypts it with the user's inputed password and saves to disk.
Args:
n_words: (int, optional):
@@ -451,7 +452,7 @@ def create_new_coldkey(
overwrite (bool, optional):
Will this operation overwrite the coldkey under the same path //coldkey
Returns:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
this object with newly created coldkey.
"""
mnemonic = Keypair.generate_mnemonic(n_words)
@@ -468,7 +469,7 @@ def new_hotkey(
use_password: bool = False,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
"""Creates a new hotkey, optionally encrypts it with the user's inputed password and saves to disk.
Args:
n_words: (int, optional):
@@ -478,7 +479,7 @@ def new_hotkey(
overwrite (bool, optional):
Will this operation overwrite the hotkey under the same path //hotkeys/
Returns:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
this object with newly created hotkey.
"""
self.create_new_hotkey(n_words, use_password, overwrite, suppress)
@@ -489,7 +490,7 @@ def create_new_hotkey(
use_password: bool = False,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
"""Creates a new hotkey, optionally encrypts it with the user's inputed password and saves to disk.
Args:
n_words: (int, optional):
@@ -499,7 +500,7 @@ def create_new_hotkey(
overwrite (bool, optional):
Will this operation overwrite the hotkey under the same path //hotkeys/
Returns:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
this object with newly created hotkey.
"""
mnemonic = Keypair.generate_mnemonic(n_words)
@@ -515,7 +516,7 @@ def regenerate_coldkeypub(
public_key: Optional[Union[str, bytes]] = None,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
"""Regenerates the coldkeypub from passed address or public_key and saves the file
Requires either address or public_key to be passed.
Args:
@@ -526,7 +527,7 @@ def regenerate_coldkeypub(
overwrite (bool, optional) (default: False):
Will this operation overwrite the coldkeypub (if exists) under the same path //coldkeypub
Returns:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
newly re-generated Wallet with coldkeypub.
"""
@@ -569,7 +570,7 @@ def regenerate_coldkey(
use_password: bool = True,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
...
@overload
@@ -579,7 +580,7 @@ def regenerate_coldkey(
use_password: bool = True,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
...
@overload
@@ -589,7 +590,7 @@ def regenerate_coldkey(
use_password: bool = True,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
...
def regenerate_coldkey(
@@ -598,7 +599,7 @@ def regenerate_coldkey(
overwrite: bool = False,
suppress: bool = False,
**kwargs,
- ) -> "wallet":
+ ) -> "Wallet":
"""Regenerates the coldkey from passed mnemonic, seed, or json encrypts it with the user's password and saves the file
Args:
mnemonic: (Union[list, str], optional):
@@ -612,7 +613,7 @@ def regenerate_coldkey(
overwrite (bool, optional):
Will this operation overwrite the coldkey under the same path //coldkey
Returns:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
this object with newly created coldkey.
Note: uses priority order: mnemonic > seed > json
@@ -660,7 +661,7 @@ def regenerate_hotkey(
use_password: bool = True,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
...
@overload
@@ -670,7 +671,7 @@ def regenerate_hotkey(
use_password: bool = True,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
...
@overload
@@ -680,7 +681,7 @@ def regenerate_hotkey(
use_password: bool = True,
overwrite: bool = False,
suppress: bool = False,
- ) -> "wallet":
+ ) -> "Wallet":
...
def regenerate_hotkey(
@@ -689,7 +690,7 @@ def regenerate_hotkey(
overwrite: bool = False,
suppress: bool = False,
**kwargs,
- ) -> "wallet":
+ ) -> "Wallet":
"""Regenerates the hotkey from passed mnemonic, encrypts it with the user's password and save the file
Args:
mnemonic: (Union[list, str], optional):
@@ -703,7 +704,7 @@ def regenerate_hotkey(
overwrite (bool, optional):
Will this operation overwrite the hotkey under the same path //hotkeys/
Returns:
- wallet (cybertensor.wallet):
+ wallet (Wallet):
this object with newly created hotkey.
"""
if len(kwargs) == 0:
diff --git a/load_test_main.py b/load_test_main.py
new file mode 100644
index 0000000..b6114d0
--- /dev/null
+++ b/load_test_main.py
@@ -0,0 +1,318 @@
+# Copyright © 2024 cyber~Congress
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
+# the Software.
+
+# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+
+# Example usage:
+# >>> python load_test_main.py --wallets=15 --skip-wallets=10 --send-to-contract=y --send-to-wallets=y \
+# --register-subnet=n --root-register=y --subnet-register=y --subnet-nominate=n --self-stake=y --self-unstake=n \
+# --set-root-weight=y --set-subnets-weight=y```
+
+import warnings
+from argparse import ArgumentParser
+from random import sample, randint
+from time import sleep
+from typing import Union, TypedDict, Optional
+
+warnings.filterwarnings("ignore", category=DeprecationWarning)
+
+import pandas as pd
+from cosmpy.aerial.tx_helpers import SubmittedTx
+from cosmpy.aerial.wallet import LocalWallet
+from cosmpy.crypto.address import Address
+from torch.multiprocessing import Pool
+from tqdm import tqdm
+
+from cybertensor import __local_network__ as network
+from cybertensor import cwtensor, Wallet
+
+
+class Account(TypedDict):
+ wallet: Wallet
+ wallet_address: str
+ wallet_hotkey_address: str
+ start_amount: int
+
+
+BASE_WALLET_SEED = "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius"
+
+parser = ArgumentParser()
+parser.add_argument("--wallets", default=10, type=int, help="Number of wallets")
+parser.add_argument("--skip-wallets", default=0, type=int, help="Skip wallets")
+parser.add_argument(
+ "--send-to-contract", default="false", type=str, help="Send tokens to the contract"
+)
+parser.add_argument(
+ "--activate-contract",
+ default="false",
+ type=str,
+ help="Activate dmn thought for the contract",
+)
+parser.add_argument(
+ "--send-to-wallets", default="true", type=str, help="Send tokens to wallets"
+)
+parser.add_argument("--threads", default=5, type=int, help="Number of threads")
+parser.add_argument(
+ "--register-subnet", default="false", type=str, help="Register new subnetworks"
+)
+parser.add_argument(
+ "--root-register", default="true", type=str, help="Register wallets in root"
+)
+parser.add_argument(
+ "--subnet-register",
+ default="true",
+ type=str,
+ help="Register wallets in subnetworks",
+)
+parser.add_argument(
+ "--subnet-nominate",
+ default="false",
+ type=str,
+ help="Nominate wallets in subnetworks",
+)
+parser.add_argument("--self-stake", default="true", type=str, help="Self stake")
+parser.add_argument("--self-unstake", default="false", type=str, help="Self unstake")
+parser.add_argument(
+ "--set-root-weight", default="true", type=str, help="Set roots' weights"
+)
+parser.add_argument(
+ "--set-subnets-weight", default="false", type=str, help="Set subnets' weights"
+)
+args = parser.parse_args()
+
+
+NUMBER_OF_WALLETS = int(args.wallets)
+SKIP_WALLETS = int(args.skip_wallets)
+SEND_TOKEN_TO_CONTRACT = args.send_to_contract.lower() in ["true", "1", "t", "y", "yes"]
+ACTIVATE_CONTRACT = args.activate_contract.lower() in ["true", "1", "t", "y", "yes"]
+SEND_TOKEN_TO_WALLETS = args.send_to_wallets.lower() in ["true", "1", "t", "y", "yes"]
+NUMBER_OF_THREADS = int(args.threads)
+REGISTER_SUBNET = args.register_subnet.lower() in ["true", "1", "t", "y", "yes"]
+REGISTER_IN_ROOT = args.root_register.lower() in ["true", "1", "t", "y", "yes"]
+REGISTER_IN_SUBNET = args.subnet_register.lower() in ["true", "1", "t", "y", "yes"]
+NOMINATE_IN_SUBNET = args.subnet_nominate.lower() in ["true", "1", "t", "y", "yes"]
+SELF_STAKE = args.self_stake.lower() in ["true", "1", "t", "y", "yes"]
+SELF_UNSTAKE = args.self_unstake.lower() in ["true", "1", "t", "y", "yes"]
+SET_ROOT_WEIGHT = args.set_root_weight.lower() in ["true", "1", "t", "y", "yes"]
+SET_SUBNETS_WEIGHT = args.set_subnets_weight.lower() in ["true", "1", "t", "y", "yes"]
+
+
+def send_coins(
+ to_address: Union[str, Address], amount: int, denom: str = "boot"
+) -> Optional[SubmittedTx]:
+ try:
+ _tx_broadcasted = tensor.client.send_tokens(
+ destination=Address(to_address),
+ amount=amount,
+ denom=denom,
+ sender=base_wallet,
+ ).wait_to_complete()
+ return _tx_broadcasted
+ except Exception as _e:
+ print(f"Exception: {_e}")
+ return None
+
+
+def send_token_to_contract() -> None:
+ if SEND_TOKEN_TO_CONTRACT:
+ send_coins(to_address=tensor.contract_address, amount=10_000_000_000)
+ sleep(5)
+
+
+def activate_contract() -> None:
+ if ACTIVATE_CONTRACT:
+ _tx = tensor.contract.execute(
+ args={"activate": {}}, sender=base_wallet
+ ).wait_to_complete()
+ print(_tx)
+
+
+def get_accounts(
+ number_of_wallets: int = NUMBER_OF_WALLETS, skip_wallets: int = SKIP_WALLETS
+) -> list[Account]:
+ _accounts: list[Account] = []
+ for _i in range(skip_wallets, number_of_wallets):
+ _wallet_name = f"wallet{_i}"
+ _wallet = Wallet(name=_wallet_name, hotkey=_wallet_name, path="temp")
+ _wallet.create_if_non_existent(
+ coldkey_use_password=False, hotkey_use_password=False
+ )
+ _wallet_address = _wallet.get_coldkey().address
+ _wallet_hotkey_address = _wallet.get_hotkey().address
+ print(f"{_wallet_name} address uploaded: {_wallet_address}")
+ _amount = 20_000_000_000
+ if SEND_TOKEN_TO_WALLETS:
+ send_coins(to_address=_wallet_address, amount=_amount)
+ send_coins(to_address=_wallet_hotkey_address, amount=1_000_000)
+ _accounts.append(
+ Account(
+ wallet=_wallet,
+ wallet_address=_wallet_address,
+ wallet_hotkey_address=_wallet_hotkey_address,
+ start_amount=_amount,
+ )
+ )
+ return _accounts
+
+
+def workflow(
+ account: Account,
+ netuids: Optional[list[int]] = None,
+ register_subnetwork: bool = REGISTER_SUBNET,
+ root_register: bool = REGISTER_IN_ROOT,
+ subnet_register: bool = REGISTER_IN_SUBNET,
+ subnet_nominate: bool = NOMINATE_IN_SUBNET,
+ self_stake: bool = SELF_STAKE,
+ self_stake_amount: float = 1,
+ self_unstake: bool = SELF_UNSTAKE,
+ self_unstake_amount: float = 0.1,
+ root_set_weight: bool = SET_ROOT_WEIGHT,
+ root_weights: Optional[list[float]] = None,
+ subnets_set_weight: bool = SET_SUBNETS_WEIGHT,
+ subnets_weights: Optional[dict[int, list[list[int], list[float]]]] = None,
+) -> None:
+ sleep(randint(0, 40))
+ try:
+ _tensor = cwtensor(network="local")
+ if register_subnetwork:
+ _tensor.register_subnetwork(wallet=account["wallet"])
+ if root_register:
+ _tensor.root_register(wallet=account["wallet"])
+ if netuids is None:
+ netuids = _tensor.get_all_subnet_netuids()
+ _subnetuids = [_netuid for _netuid in netuids if _netuid != 0]
+ if subnet_register:
+ for _netuid in netuids:
+ _tensor.burned_register(wallet=account["wallet"], netuid=_netuid)
+ if subnet_nominate:
+ _tensor.nominate(wallet=account["wallet"])
+ # you can stake only to root validators
+ if self_stake:
+ _tensor.add_stake(
+ wallet=account["wallet"],
+ hotkey=account["wallet_hotkey_address"],
+ amount=self_stake_amount,
+ )
+ if self_unstake:
+ _tensor.unstake(
+ wallet=account["wallet"],
+ hotkey=account["wallet_hotkey_address"],
+ amount=self_unstake_amount,
+ )
+ if root_set_weight:
+ if root_weights is None:
+ root_weights = sample(range(1, 1 + len(_subnetuids)), len(_subnetuids))
+ print(f"netuids: {_subnetuids}\troot_weights: {root_weights}")
+ _tensor.root_set_weights(
+ wallet=account["wallet"],
+ netuids=_subnetuids,
+ weights=root_weights,
+ wait_for_finalization=True,
+ )
+ if subnets_set_weight:
+ if subnets_weights is None:
+ subnets_weights = {
+ _netuid: [
+ [
+ _neuron.uid
+ for _neuron in _tensor.metagraph(netuid=_netuid).neurons
+ ],
+ sample(
+ range(
+ 1, 1 + len(_tensor.metagraph(netuid=_netuid).neurons)
+ ),
+ len(_tensor.metagraph(netuid=_netuid).neurons),
+ ),
+ ]
+ for _netuid in _subnetuids
+ }
+ for _netuid in subnets_weights.keys():
+ sleep(10)
+ _tensor.set_weights(
+ wallet=account["wallet"],
+ netuid=_netuid,
+ uids=subnets_weights[_netuid][0],
+ weights=subnets_weights[_netuid][1],
+ )
+ except Exception as _e:
+ print(f"ERROR {_e}")
+
+
+def display_state() -> None:
+ _tensor = cwtensor(network="local")
+ _netuids = _tensor.get_all_subnet_netuids()
+ print(f"\ncontract address: {_tensor.contract_address}")
+ print(f"contract balance: {_tensor.get_balance(_tensor.contract_address)}")
+ print(f"existing subnets: {_netuids}\n")
+ print(f"delegates: {_tensor.get_delegates()}\n")
+ print(f"root weights {_tensor.weights(netuid=0)}\n")
+ for _netuid in _netuids[1:]:
+ print(f"subnet {_netuid} weights {_tensor.weights(netuid=_netuid)}")
+
+ _registration_data = [
+ [f'{"subnet" + str(_netuid) if _netuid != 0 else "root"}']
+ + [
+ tensor.is_hotkey_registered_on_subnet(
+ hotkey=_account["wallet_hotkey_address"], netuid=_netuid
+ )
+ for _account in accounts
+ ]
+ for _netuid in _netuids
+ ]
+ _registration_columns = ["Subnet"] + [
+ _account["wallet"].name for _account in accounts
+ ]
+ print("\nwallet registration:")
+ print(pd.DataFrame(data=_registration_data, columns=_registration_columns))
+
+
+if __name__ == "__main__":
+ tensor = cwtensor(network="local")
+ base_wallet = LocalWallet.from_mnemonic(
+ mnemonic=BASE_WALLET_SEED, prefix=network.address_prefix
+ )
+ base_wallet_address = str(base_wallet)
+ print(
+ f"base address: {base_wallet_address}\n"
+ f"base address balance: {tensor.get_balance(address=base_wallet_address)}\n"
+ f"send token to the contract: {SEND_TOKEN_TO_CONTRACT}\n"
+ f"activate contract: {ACTIVATE_CONTRACT}\n"
+ f"number of wallets: {NUMBER_OF_WALLETS}\n"
+ f"number of skipped wallets: {SKIP_WALLETS}\n"
+ f"send token to the wallets: {SEND_TOKEN_TO_WALLETS}\n"
+ f"number of threads: {NUMBER_OF_THREADS}\n"
+ f"register new subnets: {REGISTER_SUBNET}\n"
+ f"register in root: {REGISTER_IN_ROOT}\n"
+ f"register in subnets: {REGISTER_IN_SUBNET}\n"
+ f"nominate in subnets: {NOMINATE_IN_SUBNET}\n"
+ f"self stake: {SELF_STAKE}\n"
+ f"self unstake: {SELF_UNSTAKE}\n"
+ f"set root weights: {SET_ROOT_WEIGHT}\n"
+ f"set subnets weights: {SET_SUBNETS_WEIGHT}\n"
+ )
+
+ send_token_to_contract()
+ activate_contract()
+ accounts = get_accounts()
+ display_state()
+
+ tasks = accounts
+ print(f"\nnumber of tasks: {len(tasks):>,}")
+ print(f"number of threads: {NUMBER_OF_THREADS:>,}")
+
+ with Pool(processes=NUMBER_OF_THREADS) as pool:
+ res_participation = list(tqdm(pool.imap(workflow, tasks), total=len(tasks)))
+
+ display_state()
diff --git a/requirements/prod.txt b/requirements/prod.txt
index cdea4dc..022c105 100644
--- a/requirements/prod.txt
+++ b/requirements/prod.txt
@@ -5,7 +5,7 @@ backoff
black==23.7.0
cryptography==41.0.3
ddt==1.6.0
-grpcio==1.60.0
+grpcio
fuzzywuzzy>=0.18.0
fastapi==0.99.1
loguru==0.7.0
@@ -26,6 +26,7 @@ pytest
retry
requests
rich
+setuptools<=65.6.3
termcolor
torch>=1.13.1
tqdm
diff --git a/setup.py b/setup.py
index 4e4227f..f799ca3 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
-# Copyright © 2023 cyber~Congress
+# Copyright © 2024 cyber~Congress
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation