Skip to content
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

wallet: remove unused variable spk_man in import* RPCs #17377

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Nov 5, 2019

Each of the following RPC functions

  • importprivkey
  • importaddress
  • importpubkey
  • importwallet
  • importmulti

define a variable reference LegacyScriptPubKeyMan& spk_man which is not used, leading to compiler warnings in the current master branch (bdda137):

  CXX      wallet/libbitcoin_wallet_a-rpcdump.o
wallet/rpcdump.cpp:137:28: warning: unused variable 'spk_man' [-Wunused-variable]
    LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
                           ^
wallet/rpcdump.cpp:265:28: warning: unused variable 'spk_man' [-Wunused-variable]
    LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*pwallet);
                           ^
wallet/rpcdump.cpp:468:28: warning: unused variable 'spk_man' [-Wunused-variable]
    LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
                           ^
wallet/rpcdump.cpp:552:28: warning: unused variable 'spk_man' [-Wunused-variable]
    LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
                           ^
wallet/rpcdump.cpp:1349:28: warning: unused variable 'spk_man' [-Wunused-variable]
    LegacyScriptPubKeyMan& spk_man = GetLegacyScriptPubKeyMan(*wallet);
                           ^
5 warnings generated.

The call to GetLegacyScriptPubKeyMan() still serves the purpose to throw an error if the wallet doesn't have a LegacyScriptPubKeyMan instance (indicating that the command is not supported, as pointed out by the error message):

static LegacyScriptPubKeyMan& GetLegacyScriptPubKeyMan(CWallet& wallet)
{
LegacyScriptPubKeyMan* spk_man = wallet.GetLegacyScriptPubKeyMan();
if (!spk_man) {
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
}
return *spk_man;
}

This commit casts the functions return value to void to point out that the value is thrown away, and adds a comment on why the function call is needed as well. introduces a new function RequireLegacyScriptPubKeyMan() which in turn calls GetLegacyScriptPubKeyMan() but discards its return value.

@fanquake fanquake added the Wallet label Nov 5, 2019
@practicalswift
Copy link
Contributor

@theStack Some context is found in #17338 :)

@jonatack
Copy link
Contributor

jonatack commented Nov 5, 2019

See #17300 (comment).

@jonatack
Copy link
Contributor

jonatack commented Nov 5, 2019

@practicalswift Snap! :)

@theStack
Copy link
Contributor Author

theStack commented Nov 5, 2019

@practicalswift @jonatack Oops, I overlooked that. Mental note to myself: also search through merged/closed PRs about a change that is likely to having been discussed already, not only currently open ones. Thanks for pointing out!

@Sjors
Copy link
Member

Sjors commented Nov 5, 2019

From the earlier comment:

Some of the unused spk_man variables in the warnings are used later in 07e0c23 from #17261 for locking cs_keystore

You could add a function void RequireLegacyScriptPubKeyMan() that only serves to check the presence. That in turn can call GetLegacyScriptPubKeyMan(). Later commits can then switch RequireLegacyScriptPubKeyMan() to GetLegacyScriptPubKeyMan() if they need the return value.

cc @achow101 @ryanofsky

Each of the following RPC functions define a variable reference
"LegacyScriptPubKeyMan& spk_man" which is not used, leading to compiler
warnings:
- importprivkey
- importaddress
- importpubkey
- importwallet
- importmulti

The call to GetLegacyScriptPubKeyMan() still serves the purpose to throw an
error if the wallet doesn't have a LegacyScriptPubKeyMan instance. This commit
introduces a new function RequireLegacyScriptPubKeyMan() which in turn calls
GetLegacyScriptPubKeyMan() but discards its return value.
@theStack theStack force-pushed the 20191105-refactor-remove_unused_variable_spkman branch from c57de2e to 606422b Compare November 5, 2019 14:14
@theStack
Copy link
Contributor Author

theStack commented Nov 5, 2019

@Sjors: Good idea, I updated the commit and the PR description accordingly.

If someone else wants to work on this who has more background knowledge about future use etc., probably on the course of a larger cleanup PR (@ryanofsky, @achow101 ?), feel free to close it though -- I wouldn't have opened it in the first place if I knew about #17338 and #17300 (comment).

@Sjors
Copy link
Member

Sjors commented Nov 5, 2019

ACK 606422b (works, but prefer ryanofsky's solution) ./configure -Werror=unused-variable is happy again. @MarcoFalke didn't we have a Travis instance with that config at some point?

@ryanofsky
Copy link
Contributor

Sorry for causing these warnings. Feel free to pull in changes from b07b07c in #17381 to avoid conflicts with that PR. I think the changes in that commit are a little better than current changes here (606422b), because they extend the getter function to cover rpcwallet as well as rpcdump, and use Ensure naming consistent with EnsureWalletIsAvailable and EnsureWalletIsUnlocked. They implement what I previously suggested to jonatack in #17338 (comment)

@ryanofsky ryanofsky removed this from PRs in Descriptor wallets Nov 5, 2019
@Sjors
Copy link
Member

Sjors commented Nov 5, 2019

Agree @ryanofsky's version is more thorough, so let's go with that.

@fanquake
Copy link
Member

fanquake commented Nov 5, 2019

Closing in favour of #17381.

@laanwj
Copy link
Member

laanwj commented Nov 6, 2019

Whoops. We should probably merge something to get rid of these warnings to avoid people wasting their time creating PR after PR fixing them.

@theStack theStack deleted the 20191105-refactor-remove_unused_variable_spkman branch December 1, 2020 10:06
@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.

None yet

7 participants