gui: Show wallet selector on console window if there are wallets loaded #15150

pull promag wants to merge 3 commits into bitcoin:master from promag:2019-01-consolewalletselector changing 5 files +67 −66
  1. promag commented at 1:43 am on January 12, 2019: member

    Now with one wallet loaded the selector is visible:

    After unloading the wallet the selector is hidden:

  2. gui: Remove warning "unused variable 'wallet_model'" b669ba6bd8
  3. gui: Show wallet selector on console window if there are wallets loaded fca4bcdc32
  4. fanquake added the label GUI on Jan 12, 2019
  5. jonasschnelli commented at 6:17 am on January 12, 2019: contributor

    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.

  6. hebasto commented at 2:18 pm on January 14, 2019: member

    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.

  7. promag commented at 2:23 pm on January 14, 2019: member

    Thanks @hebasto, will fix.

    Is this worth of backport?

  8. promag commented at 3:05 pm on January 14, 2019: member
    @hebasto unfortunately that’s not an easy fix, all wallet RPC call 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”.
  9. hebasto commented at 3:08 pm on January 14, 2019: member
    @promag maybe update the wallet selector when the first wallet has been loaded?
  10. promag commented at 3:19 pm on January 14, 2019: member
    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.
  11. hebasto commented at 3:26 pm on January 14, 2019: member

    @promag

    the GUI should be explicit.

    Right.

    That said I think your test case should be fixed in a separate PR.

    Could this test case be mentioned in this PR description?

  12. promag commented at 4:16 pm on January 14, 2019: member
    @hebasto please see/test last commit.
  13. DrahtBot commented at 4:50 pm on January 14, 2019: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #15492 ([rpc] remove deprecated generate method by Sjors)
    • #15157 (rpc: Bumpfee units change, satoshis to BTC by benthecarman)
    • #10615 (RPC: Allow rpcauth configs to specify a 4th parameter naming a specific wallet by luke-jr)

    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.

  14. wip: rpc: Add /nowallet endpoint e7a1ff13ef
  15. in src/wallet/rpcwallet.cpp:87 in 7db2876cdd outdated
    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)");
    


    hebasto commented at 7:04 pm on January 14, 2019:
    Missed “is” causes test failures.

    promag commented at 7:06 pm on January 14, 2019:
    Ops
  16. promag force-pushed on Jan 14, 2019
  17. in src/wallet/rpcwallet.cpp:81 in e7a1ff13ef
    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)
    


    hebasto commented at 6:15 pm on January 15, 2019:
    0bool EnsureWalletIsAvailable(const CWallet* const pwallet, const JSONRPCRequest& request)
    

    luke-jr commented at 6:12 am on April 17, 2019:
    Seems like GetWalletForJSONRPCRequest is a better place to do this?
  18. in src/wallet/rpcwallet.h:29 in e7a1ff13ef
    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);
    


    hebasto commented at 6:28 pm on January 15, 2019:
    0bool EnsureWalletIsAvailable(const CWallet* const pwallet, const JSONRPCRequest& request);
    
  19. hebasto changes_requested
  20. in src/qt/rpcconsole.cpp:706 in fca4bcdc32 outdated
    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) {
    


    Sjors commented at 5:30 pm on January 16, 2019:
    Can we just directly count the number of wallets?

    promag commented at 7:14 pm on January 20, 2019:
    This change doesn’t make the code worse. I think this can be improved later by refactoring to take advantage of the new WalletController.
  21. in src/qt/rpcconsole.cpp:910 in b669ba6bd8 outdated
    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*>();
    


    Sjors commented at 5:32 pm on January 16, 2019:
    Why it safe to remove if (wallet_index > 0) {?

    promag commented at 7:12 pm on January 20, 2019:
    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.

    hebasto commented at 7:17 pm on January 20, 2019:
    Why was {} syntax for wallet_model initialization dropped? It could prevent an implicit data conversion.

    promag commented at 8:39 pm on January 20, 2019:
    You mean this should be WalletModel* wallet_model{ui->WalletSelector->currentData().value<WalletModel*>()};?

    hebasto commented at 9:47 pm on January 20, 2019:
    Yes. It seems more robust.
  22. Sjors commented at 5:35 pm on January 16, 2019: member

    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.

  23. promag commented at 7:15 pm on January 20, 2019: member

    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.

  24. Sjors commented at 6:45 pm on January 21, 2019: member

    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.

  25. promag commented at 6:50 pm on January 21, 2019: member
    @Sjors so /wallet/ explicitly selects the wallet but / automatically selects a wallet if there’s only one loaded, so we need to somehow avoid that without breaking the current behavior.
  26. Sjors commented at 7:24 pm on January 21, 2019: member

    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.

  27. DrahtBot commented at 3:22 pm on March 2, 2019: member
  28. DrahtBot added the label Needs rebase on Mar 2, 2019
  29. luke-jr commented at 6:07 am on April 17, 2019: member

    @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. :/

  30. DrahtBot commented at 2:02 pm on August 16, 2019: member
  31. DrahtBot added the label Up for grabs on Aug 16, 2019
  32. DrahtBot closed this on Aug 16, 2019

  33. laanwj removed the label Needs rebase on Oct 24, 2019
  34. fanquake removed the label Up for grabs on Jan 17, 2020
  35. fanquake referenced this in commit c20fbb7be8 on Jan 17, 2020
  36. PastaPastaPasta referenced this in commit 81f118f3d3 on Sep 17, 2021
  37. thelazier referenced this in commit 092bb8a134 on Sep 25, 2021
  38. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-03 10:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me