Skip to content

Commit 0ee914b

Browse files
committed
Merge bitcoin#17584: wallet: replace raw pointer with const reference in AddrToPubKey
1a3a256 wallet: replace raw pointer with const reference in AddrToPubKey (Harris) Pull request description: This PR replaces a redundant reference-to-pointer conversion in **addmultisigaddress** from *wallet/rpcwallet.cpp*. It also makes the API from *rpc/util.h* look more straightforward as **AddrToPubKey** now uses const references like other functions from there. I am not sure why there is a ref-to-ptr conversion in addmultisignatures, so I can only speculate that this is because of "historical reasons". The ref-to-ptr conversion happens here: https://github.com/bitcoin/bitcoin/blob/master/src/wallet/rpcwallet.cpp#L1001 There, the address of LegacyScriptPubKeyMan& is given to AddrToPubKey. Later, in AddrToPubKey, it gets converted back to a reference, because GetKeyForDestination in rpc/util.cpp expects a const ref: https://github.com/bitcoin/bitcoin/blob/master/src/rpc/util.cpp#L140 Regards, ACKs for top commit: achow101: ACK 1a3a256 meshcollider: utACK 1a3a256 promag: Code review ACK 1a3a256. hebasto: ACK 1a3a256, I have not tested the code, but I have reviewed it and it looks OK, I agree it can be merged. Tree-SHA512: 1a2b8ddab5694ef4c65fac69f011e38dd03a634e84a35857e13bd05ad99fe42af22ee0af6230865e3d2c725693512f3336acb055ede19c958424283e7a3856c4
2 parents 2c1c437 + 1a3a256 commit 0ee914b

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/rpc/util.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,18 @@ CPubKey HexToPubKey(const std::string& hex_in)
131131
}
132132

133133
// Retrieves a public key for an address from the given FillableSigningProvider
134-
CPubKey AddrToPubKey(FillableSigningProvider* const keystore, const std::string& addr_in)
134+
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in)
135135
{
136136
CTxDestination dest = DecodeDestination(addr_in);
137137
if (!IsValidDestination(dest)) {
138138
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address: " + addr_in);
139139
}
140-
CKeyID key = GetKeyForDestination(*keystore, dest);
140+
CKeyID key = GetKeyForDestination(keystore, dest);
141141
if (key.IsNull()) {
142142
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("%s does not refer to a key", addr_in));
143143
}
144144
CPubKey vchPubKey;
145-
if (!keystore->GetPubKey(key, vchPubKey)) {
145+
if (!keystore.GetPubKey(key, vchPubKey)) {
146146
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("no full public key for address %s", addr_in));
147147
}
148148
if (!vchPubKey.IsFullyValid()) {

src/rpc/util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extern std::string HelpExampleCli(const std::string& methodname, const std::stri
6969
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
7070

7171
CPubKey HexToPubKey(const std::string& hex_in);
72-
CPubKey AddrToPubKey(FillableSigningProvider* const keystore, const std::string& addr_in);
72+
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in);
7373
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, FillableSigningProvider& keystore, CScript& script_out);
7474

7575
UniValue DescribeAddress(const CTxDestination& dest);

src/wallet/rpcwallet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
998998
if (IsHex(keys_or_addrs[i].get_str()) && (keys_or_addrs[i].get_str().length() == 66 || keys_or_addrs[i].get_str().length() == 130)) {
999999
pubkeys.push_back(HexToPubKey(keys_or_addrs[i].get_str()));
10001000
} else {
1001-
pubkeys.push_back(AddrToPubKey(&spk_man, keys_or_addrs[i].get_str()));
1001+
pubkeys.push_back(AddrToPubKey(spk_man, keys_or_addrs[i].get_str()));
10021002
}
10031003
}
10041004

0 commit comments

Comments
 (0)