Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E Setup + wallet commands #11

Merged
merged 28 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
96c9123
SubtensorInterface async update, `sudo set` command
thewhaleking Aug 14, 2024
46215ee
`subnets hyperparameters`
thewhaleking Aug 14, 2024
1eca517
`subnets list` command
thewhaleking Aug 14, 2024
08e7d05
MyPy
thewhaleking Aug 15, 2024
e40c70f
MyPy
thewhaleking Aug 15, 2024
a413eb1
`subnets lock-cost` command
thewhaleking Aug 16, 2024
79f5bfc
init commit
ibraheem-opentensor Aug 17, 2024
6ecaef7
Fixed input configs for commands
ibraheem-opentensor Aug 19, 2024
47e338a
command fixes + e2e coverage increase
ibraheem-opentensor Aug 20, 2024
db243f5
Fixes localnet sh path
ibraheem-opentensor Aug 20, 2024
e59d2e0
Fix imports
ibraheem-opentensor Aug 20, 2024
2583623
`subnets create` command
thewhaleking Aug 20, 2024
e7060e5
`pow-register` command
thewhaleking Aug 20, 2024
520c4ed
`subnets register` command
thewhaleking Aug 20, 2024
7221d49
language
thewhaleking Aug 20, 2024
03b77a8
Fixed overview.
thewhaleking Aug 20, 2024
8311c61
Minor fixes
ibraheem-opentensor Aug 20, 2024
9c21994
Merge remote-tracking branch 'origin/feat/thewhaleking/subnets-comman…
ibraheem-opentensor Aug 20, 2024
83da956
Finishes e2e wallet + minor fixes
ibraheem-opentensor Aug 21, 2024
a67cd7b
Fixes wallet balance command
thewhaleking Aug 21, 2024
7691287
Merge branch 'main' into tests/e2e-tests-init
ibraheem-opentensor Aug 21, 2024
e7a0d92
Merged interaction tests
ibraheem-opentensor Aug 21, 2024
21855c3
init file
ibraheem-opentensor Aug 21, 2024
0a59b99
Added workflow + indications in tests
ibraheem-opentensor Aug 21, 2024
0d2522b
Fix extra file
ibraheem-opentensor Aug 21, 2024
29bd7ac
Fixes yml config
ibraheem-opentensor Aug 21, 2024
c3db78e
Code improvements
ibraheem-opentensor Aug 22, 2024
81b9e0a
Merge branch 'main' into tests/e2e-tests-init
ibraheem-opentensor Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 214 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
# Byte-compiled / optimized / DLL files
**/__pycache__/
*.py[cod]
*$py.class
*.pyc

# Remove notebooks.
*.ipynb

# weigths and biases
wandb/

*.csv
*.torch
*.pt
*.log

# runs/data/models/logs/~
data/
**/data/

# C extensions
*.so

# IDE
*.idea/

# VSCODE
.vscode/

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
# Generated by Cargo
# will have compiled files and executables
**/target/
# These are backup files generated by rustfmt
**/*.rs.bk

.DS_Store

# The cache for docker container dependency
.cargo

# The cache for chain data in container
.local

# State folder for all neurons.
**/data/*
!data/.gitkeep

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

# PIPY Stuff
bittensor.egg-info
bittensor*.egg
bdist.*

npm-debug.log*
yarn-debug.log*
yarn-error.log*

**/build/*
**/dist/*
**/runs/*
**/env/*
**/data/*
**/.data/*
**/tmp/*

**/.bash_history
**/*.xml
**/*.pstats
**/*.png

# Replicate library
**/.replicate
replicate.yaml
**/run.sh

# Notebooks
*.ipynb
23 changes: 12 additions & 11 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Options:
"""

wallet_name = typer.Option(None, "--wallet-name", "-w", help="Name of wallet")
wallet_name_req = typer.Option(None, "--wallet-name", "-w", help="Name of wallet", prompt=True)
wallet_path = typer.Option(
None, "--wallet-path", "-p", help="Filepath of root of wallets"
)
Expand Down Expand Up @@ -56,7 +57,7 @@ class Options:
None, "--json-password", help="Password to decrypt the json file."
)
use_password = typer.Option(
None,
True,
help="Set true to protect the generated bittensor key with a password.",
is_flag=True,
flag_value=False,
Expand Down Expand Up @@ -655,9 +656,9 @@ def wallet_transfer(
destination address and amount before confirming the transaction to avoid errors or loss of funds.
"""
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey)
self.initialize_chain(network, chain)
subtensor = self.initialize_chain(network, chain)
return self._run_command(
wallets.transfer(wallet, self.not_subtensor, destination, amount)
wallets.transfer(wallet, subtensor, destination, amount)
)

def wallet_swap_hotkey(
Expand Down Expand Up @@ -888,14 +889,14 @@ def wallet_regen_coldkey(

### Example usage:
```
btcli wallet regen_coldkey --mnemonic "word1 word2 ... word12"
btcli wallet regen-coldkey --mnemonic "word1 word2 ... word12"
```

### Note: This command is critical for users who need to regenerate their coldkey, possibly for recovery or
security reasons. It should be used with caution to avoid overwriting existing keys unintentionally.
"""

wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey)
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey, validate=False)
mnemonic, seed, json, json_password = get_creation_data(
mnemonic, seed, json, json_password
)
Expand Down Expand Up @@ -945,7 +946,7 @@ def wallet_regen_coldkey_pub(
corruption or loss. It is a recovery-focused utility that ensures continued access to wallet
functionalities.
"""
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey)
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey, validate=False)
if not ss58_address and not public_key_hex:
prompt_answer = typer.prompt(
"Enter the ss58_address or the public key in hex"
Expand All @@ -961,7 +962,7 @@ def wallet_regen_coldkey_pub(
raise typer.Exit()
return self._run_command(
wallets.regen_coldkey_pub(
wallet, public_key_hex, ss58_address, overwrite_coldkeypub
wallet, ss58_address, public_key_hex, overwrite_coldkeypub
)
)

Expand Down Expand Up @@ -1015,7 +1016,7 @@ def wallet_regen_hotkey(

def wallet_new_hotkey(
self,
wallet_name: Optional[str] = Options.wallet_name,
wallet_name: Optional[str] = Options.wallet_name_req,
wallet_path: Optional[str] = Options.wallet_path,
wallet_hotkey: Optional[str] = Options.wallet_hk_req,
n_words: Optional[int] = None,
Expand Down Expand Up @@ -1077,7 +1078,7 @@ def wallet_new_coldkey(
setting up a new wallet. It's a foundational step in establishing a secure presence on the Bittensor
network.
"""
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey)
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey, validate=False)
n_words = get_n_words(n_words)
return self._run_command(
wallets.new_coldkey(wallet, n_words, use_password, overwrite_coldkey)
Expand Down Expand Up @@ -1112,7 +1113,7 @@ def wallet_check_ck_swap(

def wallet_create_wallet(
self,
wallet_name: Optional[str] = Options.wallet_name,
wallet_name: Optional[str] = Options.wallet_name_req,
wallet_path: Optional[str] = Options.wallet_path,
wallet_hotkey: Optional[str] = Options.wallet_hk_req,
n_words: Optional[int] = None,
Expand Down Expand Up @@ -1199,7 +1200,7 @@ def wallet_balance(
btcli w balance --all
```
"""
subtensor = SubtensorInterface(network, chain)
subtensor=self.initialize_chain(network, chain)
wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey)
return self._run_command(
wallets.wallet_balance(wallet, subtensor, all_balances)
Expand Down
11 changes: 5 additions & 6 deletions src/bittensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,17 @@ async def do_transfer() -> tuple[bool, str, str]:
# Check balance.
with console.status(":satellite: Checking balance and fees..."):
# check existential deposit and fee
account_balance, existential_deposit, fee = await asyncio.gather(
subtensor.get_balance(wallet.coldkey.ss58_address),
subtensor.get_existential_deposit(reuse_block=True),
get_transfer_fee(),
)
account_balance = await subtensor.get_balance(wallet.coldkey.ss58_address)
existential_deposit = await subtensor.get_existential_deposit(reuse_block=True)
fee = await get_transfer_fee()

if not keep_alive:
# Check if the transfer should keep_alive the account
existential_deposit = Balance(0)

# Check if we have enough balance.
if account_balance < (amount + fee + existential_deposit):
# Temp: See if there is a better way.
if list(account_balance.values())[0] < (amount + fee + existential_deposit):
err_console.print(
":cross_mark: [red]Not enough balance[/red]:[bold white]\n"
f" balance: {account_balance}\n"
Expand Down
13 changes: 7 additions & 6 deletions src/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def new_coldkey(
)


def wallet_create(
async def wallet_create(
wallet: Wallet,
n_words: int = 12,
use_password: bool = True,
Expand Down Expand Up @@ -407,10 +407,10 @@ async def wallet_list(wallet_path: str):
wallet_tree = root.add(f"\n[bold white]{wallet.name} ({coldkeypub_str})")
hotkeys = utils.get_hotkey_wallets_for_wallet(wallet, show_nulls=True)
for hkey in hotkeys:
data = f"[bold grey]{hkey.name} (?)"
data = f"[bold grey]{hkey.hotkey_str} (?)"
if hkey:
try:
data = f"[bold grey]{hkey.name} ({hkey.hotkey.ss58_address})"
data = f"[bold grey]{hkey.hotkey_str} ({hkey.hotkey.ss58_address})"
except UnicodeDecodeError:
pass
wallet_tree.add(data)
Expand Down Expand Up @@ -1151,9 +1151,10 @@ async def _filter_stake_info(stake_info: StakeInfo) -> bool:
async def transfer(
wallet: Wallet, subtensor: SubtensorInterface, destination: str, amount: float
):
# To:do - work out prompts to be passed through the cli
"""Transfer token of amount to destination."""
await transfer_extrinsic(
subtensor, wallet, destination, Balance.from_tao(amount), prompt=True
subtensor, wallet, destination, Balance.from_tao(amount), prompt=False
)


Expand All @@ -1165,7 +1166,7 @@ async def inspect(
):
def delegate_row_maker(
delegates_: list[tuple[DelegateInfo, Balance]],
) -> Generator[list[str]]:
) -> Generator[list[str], None, None]:
for d_, staked in delegates_:
if d_.hotkey_ss58 in registered_delegate_info:
delegate_name = registered_delegate_info[d_.hotkey_ss58].name
Expand All @@ -1181,7 +1182,7 @@ def delegate_row_maker(
+ [""] * 4
)

def neuron_row_maker(wallet_, all_netuids_, nsd) -> Generator[list[str]]:
def neuron_row_maker(wallet_, all_netuids_, nsd) -> Generator[list[str], None, None]:
hotkeys = get_hotkey_wallets_for_wallet(wallet_)
for netuid in all_netuids_:
for n in nsd[netuid]:
Expand Down
Empty file added src/tests/__init__.py
Empty file.
Empty file added src/tests/e2e_tests/__init__.py
Empty file.
Loading