Skip to content

Commit 2c54217

Browse files
committed
Use explicit conversion from PKHash -> CKeyID
These types are equivalent, in data etc, so they need only their data cast across. Note a function is used rather than a casting operator as CKeyID is defined at a lower level than script/standard
1 parent a9e451f commit 2c54217

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
456456
{
457457
CPubKey pubkey;
458458
PKHash *pkhash = boost::get<PKHash>(&address);
459-
if (pkhash && model->wallet().getPubKey(out.txout.scriptPubKey, CKeyID(*pkhash), pubkey))
459+
if (pkhash && model->wallet().getPubKey(out.txout.scriptPubKey, ToKeyID(*pkhash), pubkey))
460460
{
461461
nBytesInputs += (pubkey.IsCompressed() ? 148 : 180);
462462
}

src/script/signingprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination&
180180
// Only supports destinations which map to single public keys, i.e. P2PKH,
181181
// P2WPKH, and P2SH-P2WPKH.
182182
if (auto id = boost::get<PKHash>(&dest)) {
183-
return CKeyID(*id);
183+
return ToKeyID(*id);
184184
}
185185
if (auto witness_id = boost::get<WitnessV0KeyHash>(&dest)) {
186186
return CKeyID(*witness_id);

src/script/standard.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ ScriptHash::ScriptHash(const CScript& in) : uint160(Hash160(in.begin(), in.end()
2323
PKHash::PKHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
2424
WitnessV0KeyHash::WitnessV0KeyHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
2525

26+
CKeyID ToKeyID(const PKHash& key_hash)
27+
{
28+
return CKeyID{static_cast<uint160>(key_hash)};
29+
}
30+
2631
WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)
2732
{
2833
CSHA256().Write(in.data(), in.size()).Finalize(begin());

src/script/standard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct PKHash : public uint160
7979
explicit PKHash(const uint160& hash) : uint160(hash) {}
8080
explicit PKHash(const CPubKey& pubkey);
8181
};
82+
CKeyID ToKeyID(const PKHash& key_hash);
8283

8384
struct WitnessV0KeyHash;
8485
struct ScriptHash : public uint160

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,7 @@ class DescribeWalletAddressVisitor : public boost::static_visitor<UniValue>
35173517

35183518
UniValue operator()(const PKHash& pkhash) const
35193519
{
3520-
CKeyID keyID(pkhash);
3520+
CKeyID keyID{ToKeyID(pkhash)};
35213521
UniValue obj(UniValue::VOBJ);
35223522
CPubKey vchPubKey;
35233523
if (provider && provider->GetPubKey(keyID, vchPubKey)) {

src/wallet/scriptpubkeyman.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,8 @@ bool LegacyScriptPubKeyMan::SignTransaction(CMutableTransaction& tx, const std::
573573

574574
SigningResult LegacyScriptPubKeyMan::SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const
575575
{
576-
CKeyID key_id(pkhash);
577576
CKey key;
578-
if (!GetKey(key_id, key)) {
577+
if (!GetKey(ToKeyID(pkhash), key)) {
579578
return SigningResult::PRIVATE_KEY_NOT_AVAILABLE;
580579
}
581580

@@ -2052,9 +2051,8 @@ SigningResult DescriptorScriptPubKeyMan::SignMessage(const std::string& message,
20522051
return SigningResult::PRIVATE_KEY_NOT_AVAILABLE;
20532052
}
20542053

2055-
CKeyID key_id(pkhash);
20562054
CKey key;
2057-
if (!keys->GetKey(key_id, key)) {
2055+
if (!keys->GetKey(ToKeyID(pkhash), key)) {
20582056
return SigningResult::PRIVATE_KEY_NOT_AVAILABLE;
20592057
}
20602058

0 commit comments

Comments
 (0)