-
Notifications
You must be signed in to change notification settings - Fork 38.7k
gui: Show wallet selector on console window if there are wallets loaded #15150
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
Conversation
|
utACK b669ba6 Clarification: in master, if you start with no wallet, then load a wallet, you'll miss the selector between "none" and the "loaded wallet". This seems to be a bugfix. |
|
Tested on Linux Mint 19.1. Detected behavior change: In master having "none" in selector implies an error output of "getwalletinfo": With this PR: The selector value is "none". Then in Console: Note the selector remains "none". But "getwalletinfo" returns data about "test_alpha" wallet. |
|
Thanks @hebasto, will fix. Is this worth of backport? |
|
@hebasto unfortunately that's not an easy fix, all wallet RPC call bitcoin/src/wallet/rpcwallet.cpp Lines 56 to 67 in 7633529
This means that "None" is not really possible unless we define an endpoint for that — "don't default to single wallet". |
|
@promag maybe update the wallet selector when the first wallet has been loaded? |
|
I don't think we should mimic the RPC server behaviour. It was done like that to avoid breaking changes and so I think the GUI should be explicit. I also think it should be possible to have a no-wallet RPC endpoint — one that no wallet is automatically used. That said I think your test case should be fixed in a separate PR. |
Right.
Could this test case be mentioned in this PR description? |
|
@hebasto please see/test last commit. |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
7db2876 to
e7a1ff1
Compare
| } | ||
|
|
||
| bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException) | ||
| bool EnsureWalletIsAvailable(CWallet * const pwallet, const JSONRPCRequest& request) |
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.
bool EnsureWalletIsAvailable(const CWallet* const pwallet, const JSONRPCRequest& request)
| std::string HelpRequiringPassphrase(CWallet *); | ||
| void EnsureWalletIsUnlocked(CWallet *); | ||
| bool EnsureWalletIsAvailable(CWallet *, bool avoidException); | ||
| bool EnsureWalletIsAvailable(CWallet *, const JSONRPCRequest& request); |
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.
bool EnsureWalletIsAvailable(const CWallet* const pwallet, const JSONRPCRequest& request);
Sjors
left a comment
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.
Concept ACK for the dropdown change, but I don't understand the need for RPC "/nowallet". Isn't the absence of a wallet path (so no -rpcwallet=...) enough for the RPC server to understand there's no wallet context?
Suggest renaming PR and commit to: gui: only show wallet selector in console window if any wallets are loaded, which it more clear this is a bug fix.
| ui->WalletSelector->setCurrentIndex(1); | ||
| } | ||
| if (ui->WalletSelector->count() > 2) { | ||
| if (ui->WalletSelector->count() > 1) { |
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.
Can we just directly count the number of wallets?
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 change doesn't make the code worse. I think this can be improved later by refactoring to take advantage of the new WalletController.
| if (wallet_index > 0) { | ||
| wallet_model = ui->WalletSelector->itemData(wallet_index).value<WalletModel*>(); | ||
| } | ||
| WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>(); |
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.
Why it safe to remove if (wallet_index > 0) {?
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's safe because what we want is the current Qt::UserRole data as WalletModel*. If there is none then currentData().value<WalletModel*>() returns nullptr, which is the case for the fist item.
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.
Why was {} syntax for wallet_model initialization dropped? It could prevent an implicit data conversion.
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 mean this should be WalletModel* wallet_model{ui->WalletSelector->currentData().value<WalletModel*>()};?
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.
Yes. It seems more robust.
@Sjors it's just an endpoint where there is no automagic wallet selection. The idea is that you should explicit select the wallet and if you select "(none)" then wallet commands should fail, IMO. |
|
I agree that wallet commands should fail if you select (none). But I don't understand why we need this When using |
|
@Sjors so |
|
Mmm, I kind of like that behavior though. Running a node with one wallet shouldn't require Is there a scenario where this leads to the wrong result? It might be better to hide the "no wallet" option when that is the case. |
| Needs rebase |
|
@Sjors Users might select "(none)" wallet with the intent of protecting their wallet from arbitrary commands they are told to run... Agree |
| } | ||
|
|
||
| bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException) | ||
| bool EnsureWalletIsAvailable(CWallet * const pwallet, const JSONRPCRequest& request) |
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.
Seems like GetWalletForJSONRPCRequest is a better place to do this?
| There hasn't been much activity lately and the patch still needs rebase, so I am closing this for now. Please let me know when you want to continue working on this, so the pull request can be re-opened. |
c279a81 gui: Remove warning "unused variable 'wallet_model'" (João Barbosa) Pull request description: This was part of the abandoned #15150. ACKs for top commit: theStack: utACK c279a81 fanquake: ACK c279a81 - tested wallet loading/unloading in the qt rpc console. Tree-SHA512: 8fbd55c7e213599c7be843b52e960a16cf965b3e01489f426ac3ed9d579d78bb4b2ac230bcccd8abe0397a8b1166ee10e0d685738441a77a5dcb5135c15790fa
…el'" c279a81 gui: Remove warning "unused variable 'wallet_model'" (João Barbosa) Pull request description: This was part of the abandoned bitcoin#15150. ACKs for top commit: theStack: utACK bitcoin@c279a81 fanquake: ACK c279a81 - tested wallet loading/unloading in the qt rpc console. Tree-SHA512: 8fbd55c7e213599c7be843b52e960a16cf965b3e01489f426ac3ed9d579d78bb4b2ac230bcccd8abe0397a8b1166ee10e0d685738441a77a5dcb5135c15790fa
Now with one wallet loaded the selector is visible:

After unloading the wallet the selector is hidden:
