Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 078d193

Browse files
committed
init
1 parent 8508167 commit 078d193

File tree

19 files changed

+2108
-0
lines changed

19 files changed

+2108
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Run command '...'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Environment:**
27+
- OS and Distro: [e.g. Linux Ubuntu, Linux Fedora, etc.]
28+
- BittensorWallet Version [e.g. 0.0.1]
29+
30+
**Additional context**
31+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
### Requirements for Contributing a Bug Fix
2+
3+
* Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
4+
* The pull request must only fix an existing bug. To contribute other changes, you must use a different template. You can see all templates at <https://github.com/opentensor/bittensor-wallet/tree/main/.github/PULL_REQUEST_TEMPLATE>.
5+
* The pull request must update the test suite to demonstrate the changed functionality.
6+
* After you create the pull request, all status checks must pass before a maintainer reviews your contribution. This means that all the tests must pass your pull request before a maintainer is tagged to review.
7+
8+
### Identify the Bug
9+
10+
<!--
11+
12+
Link to the issue describing the bug that you're fixing.
13+
14+
If there is not yet an issue for your bug, please open a new issue and then link to that issue in your pull request.
15+
Note: In some cases, one person's "bug" is another person's "feature." If the pull request does not address an existing issue with the "bug" label, the maintainers have the final say on whether the current behavior is a bug.
16+
17+
-->
18+
19+
### Description of the Change
20+
21+
<!--
22+
23+
We must be able to understand the design of your change from this description. If we can't get a good idea of what the code will be doing from the description here, the pull request may be closed at the maintainers' discretion. Keep in mind that the maintainer reviewing this PR may not be familiar with or have worked with the code here recently, so please walk us through the concepts.
24+
25+
-->
26+
27+
28+
### Possible Drawbacks
29+
30+
<!-- What are the possible side-effects or negative impacts of the code change? -->
31+
32+
### Verification Process
33+
34+
<!--
35+
36+
What process did you follow to verify that the change has not introduced any regressions? Describe the actions you performed (including buttons you clicked, text you typed, commands you ran, etc.), and describe the results you observed.
37+
38+
-->
39+
40+
### Release Notes
41+
42+
<!--
43+
44+
Please describe the changes in a single line that explains this improvement in
45+
terms that a user can understand. This text will be used in Atom's release notes.
46+
47+
If this change is not user-facing or notable enough to be included in release notes
48+
you may use the strings "Not applicable" or "N/A" here.
49+
50+
Examples:
51+
52+
- The GitHub package now allows you to add co-authors to commits.
53+
- Fixed an issue where multiple cursors did not work in a file with a single line.
54+
- Increased the performance of searching and replacing across a whole project.
55+
56+
-->
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
### Requirements for Adding, Changing, or Removing a Feature
2+
3+
* Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
4+
* The pull request must contribute a change that has been endorsed by the maintainer team. See details in the template below.
5+
* The pull request must update the test suite to exercise the updated functionality.
6+
* After you create the pull request, all status checks must pass before a maintainer reviews your contribution. This means that all the tests must pass your pull request before a maintainer is tagged to review.
7+
8+
### Issue Endorsed by Bittensor's Maintainers
9+
10+
<!--
11+
12+
Link to the issue that your change relates to.
13+
14+
To contribute an enhancement that isn't covered by one of the items above, please follow our guide for suggesting an enhancement: https://github.com/opentensor/bittensor-wallet/blob/main/CONTRIBUTING.md#suggesting-enhancements
15+
16+
To contribute other changes, you must use a different template. You can see all templates at https://github.com/opentensor/bittensor-wallet/tree/main/.github/PULL_REQUEST_TEMPLATE.
17+
18+
-->
19+
20+
### Description of the Change
21+
22+
<!--
23+
24+
We must be able to understand the design of your change from this description. If we can't get a good idea of what the code will be doing from the description here, the pull request may be closed at the maintainers' discretion. Keep in mind that the maintainer reviewing this PR may not be familiar with or have worked with the code here recently, so please walk us through the concepts.
25+
26+
-->
27+
28+
### Alternate Designs
29+
30+
<!-- Explain what other alternates were considered and why the proposed version was selected -->
31+
32+
### Possible Drawbacks
33+
34+
<!-- What are the possible side-effects or negative impacts of the code change? -->
35+
36+
### Verification Process
37+
38+
<!--
39+
40+
What process did you follow to verify that your change has the desired effects?
41+
42+
- How did you verify that all new functionality works as expected?
43+
- How did you verify that all changed functionality works as expected?
44+
- How did you verify that the change has not introduced any regressions?
45+
46+
Describe the actions you performed (including buttons you clicked, text you typed, commands you ran, etc.), and describe the results you observed.
47+
48+
-->
49+
50+
### Release Notes
51+
52+
<!--
53+
54+
Please describe the changes in a single line that explains this improvement in
55+
terms that a user can understand. This text will be used in Atom's release notes.
56+
57+
If this change is not user-facing or notable enough to be included in release notes
58+
you may use the strings "Not applicable" or "N/A" here.
59+
60+
Examples:
61+
62+
- The GitHub package now allows you to add co-authors to commits.
63+
- Fixed an issue where multiple cursors did not work in a file with a single line.
64+
- Increased the performance of searching and replacing across a whole project.
65+
66+
-->
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
### Requirements for Contributing a Performance Improvement
2+
3+
* Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
4+
* The pull request must only affect performance of existing functionality. To contribute other changes, you must use a different template. You can see all templates at <https://github.com/opentensor/bittensor-wallet/tree/main/.github/PULL_REQUEST_TEMPLATE>.
5+
* After you create the pull request, all status checks must pass before a maintainer reviews your contribution. This means that all the tests must pass your pull request before a maintainer is tagged to review.
6+
7+
### Description of the Change
8+
9+
<!--
10+
11+
We must be able to understand the design of your change from this description. If we can't get a good idea of what the code will be doing from the description here, the pull request may be closed at the maintainers' discretion. Keep in mind that the maintainer reviewing this PR may not be familiar with or have worked with the code here recently, so please walk us through the concepts.
12+
13+
-->
14+
15+
### Quantitative Performance Benefits
16+
17+
<!--
18+
19+
Describe the exact performance improvement observed (for example, reduced time to complete an operation, reduced memory use, model metrics improvements, etc.). Describe how you measured this change. Bonus points for including graphs that demonstrate the improvement or attached dumps from the built-in profiling tools. Using Tensorboard to show your improvements would be a great way to do this.
20+
21+
-->
22+
23+
### Possible Drawbacks
24+
25+
<!-- What are the possible side-effects or negative impacts of the code change? -->
26+
27+
### Verification Process
28+
29+
<!--
30+
31+
What process did you follow to verify that the change has not introduced any regressions? Describe the actions you performed (including buttons you clicked, text you typed, commands you ran, etc.), and describe the results you observed.
32+
33+
-->
34+
35+
### Applicable Issues
36+
37+
<!-- Enter any applicable Issues here -->
38+
39+
### Release Notes
40+
41+
<!--
42+
43+
Please describe the changes in a single line that explains this improvement in
44+
terms that a user can understand. This text will be used in Atom's release notes.
45+
46+
If this change is not user-facing or notable enough to be included in release notes
47+
you may use the strings "Not applicable" or "N/A" here.
48+
49+
Examples:
50+
51+
- The GitHub package now allows you to add co-authors to commits.
52+
- Fixed an issue where multiple cursors did not work in a file with a single line.
53+
- Increased the performance of searching and replacing across a whole project.
54+
55+
-->
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Welcome! Please follow the steps below to tell us about your contribution.
2+
3+
1. Copy the correct template for your contribution
4+
- 🐛 Are you fixing a bug? Copy the template from <https://bit.ly/atom-bugfix-pr>
5+
- 📈 Are you improving performance? Copy the template from <https://bit.ly/atom-perf-pr>
6+
- 💻 Are you changing functionality? Copy the template from <https://bit.ly/atom-behavior-pr>
7+
2. Replace this text with the contents of the template
8+
3. Fill in all sections of the template
9+
4. Click "Create pull request"

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist
2+
build
3+
.vscode
4+
*.egg-info
5+
__pycache__

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# BittensorWallet - v0.0.0
2+
3+
BittensorWallet is a library for managing wallet keypairs, keyfiles, etc. for the [Bittensor Python API](https://github.com/opentensor/bittensor).
4+
5+
The purpose of this repo is to separate the concern of keyfile management from the https://github.com/opentensor/bittensor repo, to decrease the attack surface of Bittensor related to local keys and wallet functionality.
6+
7+
# Installation
8+
This package can be installed from [PyPi.org](https://pypi.org/project/bittensor-wallet/):
9+
```bash
10+
pip install bittensor-wallet==0.0.0
11+
```
12+
or via this repo (using [gh-cli](https://cli.github.com/)):
13+
```bash
14+
gh repo clone opentensor/bittensor-wallet
15+
cd bittensor-wallet
16+
pip install -e .
17+
```
18+
19+

bittensor_wallet/__init__.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# The MIT License (MIT)
2+
# Copyright © 2021 Yuma Rao
3+
# Copyright © 2022 Opentensor Foundation
4+
# Copyright © 2023 Opentensor Technologies Inc
5+
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7+
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
8+
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9+
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10+
11+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
12+
# the Software.
13+
14+
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15+
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
# DEALINGS IN THE SOFTWARE.
19+
20+
__version__ = "0.0.0"
21+
__ss58_format__ = 42 # Bittensor ss58 format
22+
23+
import argparse
24+
import copy
25+
import os
26+
from typing import Optional
27+
28+
import bittensor_config
29+
30+
from .wallet_impl import Wallet as Wallet, WalletConfig as WalletConfig
31+
from ._keyfile import Keyfile as Keyfile, KeyFileError as KeyFileError, keyfile as keyfile, serialized_keypair_to_keyfile_data as serialized_keypair_to_keyfile_data
32+
from .keypair_impl import Keypair as Keypair
33+
from . import utils as utils
34+
35+
36+
class wallet:
37+
""" Create and init wallet that stores hot and coldkey
38+
"""
39+
defaults: WalletConfig = WalletConfig.default()
40+
41+
def __new__(
42+
cls,
43+
config: Optional[WalletConfig] = None,
44+
name: str = None,
45+
hotkey: str = None,
46+
path: str = None,
47+
) -> 'wallet_impl.Wallet':
48+
r""" Init bittensor wallet object containing a hot and coldkey.
49+
50+
Args:
51+
config (:obj:`bittensor_config.Config`, `optional`):
52+
bittensor_wallet.wallet.config()
53+
name (required=False, default='default'):
54+
The name of the wallet to unlock for running bittensor
55+
hotkey (required=False, default='default'):
56+
The name of hotkey used to running the miner.
57+
path (required=False, default='~/.bittensor/wallets/'):
58+
The path to your bittensor wallets
59+
"""
60+
if config == None:
61+
config = wallet.config()
62+
config = copy.deepcopy( config )
63+
config.wallet.name = name if name != None else config.wallet.name
64+
config.wallet.hotkey = hotkey if hotkey != None else config.wallet.hotkey
65+
config.wallet.path = path if path != None else config.wallet.path
66+
wallet.check_config( config )
67+
68+
return wallet_impl.Wallet(
69+
name = config.wallet.get('name', cls.defaults.name),
70+
hotkey = config.wallet.get('hotkey', cls.defaults.hotkey),
71+
path = config.wallet.path,
72+
config = config
73+
)
74+
75+
@classmethod
76+
def config(cls) -> 'bittensor_config.Config':
77+
""" Get config from the argument parser
78+
Return: bittensor_config.config object
79+
"""
80+
parser = argparse.ArgumentParser()
81+
wallet.add_args( parser )
82+
return bittensor_config.config( parser )
83+
84+
@classmethod
85+
def help(cls):
86+
""" Print help to stdout
87+
"""
88+
parser = argparse.ArgumentParser()
89+
cls.add_args( parser )
90+
print (cls.__new__.__doc__)
91+
parser.print_help()
92+
93+
@classmethod
94+
def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None ):
95+
""" Accept specific arguments from parser
96+
"""
97+
prefix_str = '' if prefix == None else prefix + '.'
98+
try:
99+
parser.add_argument('--' + prefix_str + 'wallet.name', required=False, default=cls.defaults.name, help='''The name of the wallet to unlock for running bittensor (name mock is reserved for mocking this wallet)''')
100+
parser.add_argument('--' + prefix_str + 'wallet.hotkey', required=False, default=cls.defaults.hotkey, help='''The name of wallet's hotkey.''')
101+
parser.add_argument('--' + prefix_str + 'wallet.path', required=False, default=cls.defaults.path, help='''The path to your bittensor wallets''')
102+
103+
except argparse.ArgumentError as e:
104+
pass
105+
106+
107+
@classmethod
108+
def add_defaults(cls, defaults: bittensor_config.Config, prefix: str = 'wallet' ) -> None:
109+
""" Adds parser defaults to object, optionally using enviroment variables.
110+
"""
111+
default_config = WalletConfig()
112+
default_config.name = os.getenv('BT_WALLET_NAME') if os.getenv('BT_WALLET_NAME') != None else cls.defaults.name
113+
default_config.hotkey = os.getenv('BT_WALLET_HOTKEY') if os.getenv('BT_WALLET_HOTKEY') != None else cls.defaults.hotkey
114+
default_config.path = os.getenv('BT_WALLET_PATH') if os.getenv('BT_WALLET_PATH') != None else cls.defaults.path
115+
116+
setattr( defaults, prefix, default_config )
117+
118+
@classmethod
119+
def check_config(cls, config: 'bittensor_config.Config' ):
120+
""" Check config for wallet name/hotkey/path/hotkeys/sort_by
121+
"""
122+
assert 'wallet' in config
123+
assert isinstance(config.wallet.name, str)
124+
assert isinstance(config.wallet.hotkey, str ) or config.wallet.hotkey == None # Optional
125+
assert isinstance(config.wallet.path, str)

0 commit comments

Comments
 (0)