-
Notifications
You must be signed in to change notification settings - Fork 334
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
feat(wallets.py): add wallet history command #1638
feat(wallets.py): add wallet history command #1638
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Looks good overall, left you some comments with a request for updating the while
loop.
bittensor/commands/wallets.py
Outdated
transfers = [] | ||
|
||
# Make the request with the provided query and variables until all transfers are fetched | ||
while True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally weary of unbounded while True
statements in python. This technically should terminate on the desired condition, but may want to explicitly put the exit condition in this line and/or specify some other conditions for exiting. For example, if there is significant txn volume, we may want to limit the output to n
txns.
For example, adding a max_txn_history
that we exit upon reaching:
max_txn_history = 1000 # this should be set in the config.
page_info = {"page_info": {"hasNextPage": True}} # for initial loop entry, will be filled by `transfer_data`
while len(transfers) < max_txn_history and page_info.get("hasNextPage") == True:
...
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it will be a better approach. Will be fixing this in the next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You not need while. Change 10 to 1000 or more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alex0500 removed while and set max_txn to 1000.
Also, in the future, would you mind branching off from Thanks! |
Any new feature should include proper tests for them, including new Thanks! |
…ib-codes-11/bittensor into feature/btcli-wallet-history
Added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updated tests and testing out the query. Looks good!
Two small nits for you and we should be good to merge:
(1) Don't unlock coldkey to get ss58_address
(2) Display values in tao
instead of rao
(and mention this in the column, e.g. Amount (tao)
Suggestion for a nice to have, but is not necessary IMO:
(3) May be nice to add a column for Time
, translating the block number into datetimes. What do you think?
... | Block No | Time
... | 2044685 | Nov 1, 2023 12:21:00
...
bittensor/commands/wallets.py
Outdated
def run(cli): | ||
r"""Check the transfer history of the provided wallet.""" | ||
wallet = bittensor.wallet(config=cli.config) | ||
wallet_address = wallet.coldkey.ss58_address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is somewhat cumbersome to enter the password each time to simply get the coldkey address, which is not exactly private data.
Suggestion:
wallet_address = wallet.get_coldkeypub().ss58_address
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done.
bittensor/commands/wallets.py
Outdated
item["id"], | ||
item["from"], | ||
item["to"], | ||
item["amount"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current amount displayed is in rao
, and displaying in tao
may be more user-friendly. It's a simple divide by 1e9
Suggestion:
int(item["amount"]) / 1e9
May want to do some error handling if the value cannot be converted to an int
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also done. Tested it for the below values,
2
2.9
"2"
"2.989767"
Any invalid integer will throw an error, in that case, I am using it as it as. Any other suggestions on the same?
Where is time of transfers? |
I did complete the first two changes but I was not able to get the correct time using the block number, I tried the below formula to calculate it but was getting a 1-day difference.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'll take it from here
Description :-
This PR adds the following new command to fetch all the transfers associated with the provided "Wallet Name".
Command - btcli wallet history --wallet.name xyz
Screenshot -