Skip to content

Conversation

@promag
Copy link
Contributor

@promag promag commented Jan 12, 2019

Now with one wallet loaded the selector is visible:
screenshot 2019-01-12 at 01 38 34

After unloading the wallet the selector is hidden:
screenshot 2019-01-12 at 01 39 06

@fanquake fanquake added the GUI label Jan 12, 2019
@jonasschnelli
Copy link
Contributor

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.

@hebasto
Copy link
Member

hebasto commented Jan 14, 2019

Tested on Linux Mint 19.1. Detected behavior change:

In master having "none" in selector implies an error output of "getwalletinfo":

Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path). (code -19)

With this PR:

bitcoin-qt -nowallet

The selector value is "none".

Then in Console:

loadwallet "test_alpha"

Note the selector remains "none". But "getwalletinfo" returns data about "test_alpha" wallet.

@promag
Copy link
Contributor Author

promag commented Jan 14, 2019

Thanks @hebasto, will fix.

Is this worth of backport?

@promag
Copy link
Contributor Author

promag commented Jan 14, 2019

@hebasto unfortunately that's not an easy fix, all wallet RPC call GetWalletForJSONRPCRequest:

std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
{
std::string wallet_name;
if (GetWalletNameFromJSONRPCRequest(request, wallet_name)) {
std::shared_ptr<CWallet> pwallet = GetWallet(wallet_name);
if (!pwallet) throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
return pwallet;
}
std::vector<std::shared_ptr<CWallet>> wallets = GetWallets();
return wallets.size() == 1 || (request.fHelp && wallets.size() > 0) ? wallets[0] : nullptr;
}

This means that "None" is not really possible unless we define an endpoint for that — "don't default to single wallet".

@hebasto
Copy link
Member

hebasto commented Jan 14, 2019

@promag maybe update the wallet selector when the first wallet has been loaded?

@promag
Copy link
Contributor Author

promag commented Jan 14, 2019

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.

@hebasto
Copy link
Member

hebasto commented Jan 14, 2019

@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?

@promag
Copy link
Contributor Author

promag commented Jan 14, 2019

@hebasto please see/test last commit.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 14, 2019

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.

@promag promag force-pushed the 2019-01-consolewalletselector branch from 7db2876 to e7a1ff1 Compare January 14, 2019 23:52
}

bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException)
bool EnsureWalletIsAvailable(CWallet * const pwallet, const JSONRPCRequest& request)
Copy link
Member

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);
Copy link
Member

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);

Copy link
Member

@Sjors Sjors left a 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) {
Copy link
Member

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?

Copy link
Contributor Author

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*>();
Copy link
Member

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) {?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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*>()};?

Copy link
Member

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.

@promag
Copy link
Contributor Author

promag commented Jan 20, 2019

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.

@Sjors
Copy link
Member

Sjors commented Jan 21, 2019

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.

@promag
Copy link
Contributor Author

promag commented Jan 21, 2019

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

@Sjors
Copy link
Member

Sjors commented Jan 21, 2019

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 2, 2019

Needs rebase

@luke-jr
Copy link
Member

luke-jr commented Apr 17, 2019

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

}

bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException)
bool EnsureWalletIsAvailable(CWallet * const pwallet, const JSONRPCRequest& request)
Copy link
Member

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?

@DrahtBot
Copy link
Contributor

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.

fanquake added a commit that referenced this pull request Jan 17, 2020
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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 17, 2021
…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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants