Now with one wallet loaded the selector is visible:
After unloading the wallet the selector is hidden:
Now with one wallet loaded the selector is visible:
After unloading the wallet the selector is hidden:
utACK b669ba6bd86a7808e4692bb0cf692b1c95d8d32d
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”:
0Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path). (code -19)
With this PR:
0bitcoin-qt -nowallet
The selector value is “none”.
Then in Console:
0loadwallet "test_alpha"
Note the selector remains “none”. But “getwalletinfo” returns data about “test_alpha” wallet.
GetWalletForJSONRPCRequest
:
https://github.com/bitcoin/bitcoin/blob/76335298f427de7d7ce58ced177518a7905706cc/src/wallet/rpcwallet.cpp#L56-L67
This means that “None” is not really possible unless we define an endpoint for that — “don’t default to single wallet”.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, 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.
86- if (!HasWallets()) {
87+ if (request.fHelp) return false;
88+ if (!HasWallets() || request.URI == "/nowallet") {
89 throw JSONRPCError(
90- RPC_METHOD_NOT_FOUND, "Method not found (wallet method is disabled because no wallet is loaded)");
91+ RPC_METHOD_NOT_FOUND, "Method not found (wallet method is disabled because no wallet loaded or selected)");
77@@ -73,13 +78,13 @@ std::string HelpRequiringPassphrase(CWallet * const pwallet)
78 : "";
79 }
80
81-bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException)
82+bool EnsureWalletIsAvailable(CWallet * const pwallet, const JSONRPCRequest& request)
0bool EnsureWalletIsAvailable(const CWallet* const pwallet, const JSONRPCRequest& request)
GetWalletForJSONRPCRequest
is a better place to do this?
25@@ -26,7 +26,7 @@ std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& reques
26
27 std::string HelpRequiringPassphrase(CWallet *);
28 void EnsureWalletIsUnlocked(CWallet *);
29-bool EnsureWalletIsAvailable(CWallet *, bool avoidException);
30+bool EnsureWalletIsAvailable(CWallet *, const JSONRPCRequest& request);
0bool EnsureWalletIsAvailable(const CWallet* const pwallet, const JSONRPCRequest& request);
702@@ -703,7 +703,7 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
703 // First wallet added, set to default so long as the window isn't presently visible (and potentially in use)
704 ui->WalletSelector->setCurrentIndex(1);
705 }
706- if (ui->WalletSelector->count() > 2) {
707+ if (ui->WalletSelector->count() > 1) {
WalletController
.
910 #ifdef ENABLE_WALLET
911- const int wallet_index = ui->WalletSelector->currentIndex();
912- if (wallet_index > 0) {
913- wallet_model = ui->WalletSelector->itemData(wallet_index).value<WalletModel*>();
914- }
915+ WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
if (wallet_index > 0) {
?
Qt::UserRole
data as WalletModel*
. If there is none then currentData().value<WalletModel*>()
returns nullptr
, which is the case for the fist item.
{}
syntax for wallet_model
initialization dropped? It could prevent an implicit data conversion.
WalletModel* wallet_model{ui->WalletSelector->currentData().value<WalletModel*>()};
?
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.
but I don’t understand the need for RPC “/nowallet” @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 /nowallet
path, that feels like a hack.
When using bitcoin-cli
wallet commands without specifying the wallet, the RPC throws Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path).
. That seems like a better approach; not sure how to translate that to the console UI.
Mmm, I kind of like that behavior though. Running a node with one wallet shouldn’t require -rpcwallet
as that’s tedious.
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.
@Sjors Users might select “(none)” wallet with the intent of protecting their wallet from arbitrary commands they are told to run…
Agree /nowallet
seems hacky. The original implementation just passed the CWallet pointer… but it got hackily turned into a URI encoding instead. :/