0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-13 11:25:02 -05:00

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
This commit is contained in:
Ben Woosley 2020-01-15 13:40:14 -08:00
parent a9e451f144
commit 2c54217f91
No known key found for this signature in database
GPG key ID: 6EE5F3785F78B345
6 changed files with 11 additions and 7 deletions

View file

@ -456,7 +456,7 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
{ {
CPubKey pubkey; CPubKey pubkey;
PKHash *pkhash = boost::get<PKHash>(&address); PKHash *pkhash = boost::get<PKHash>(&address);
if (pkhash && model->wallet().getPubKey(out.txout.scriptPubKey, CKeyID(*pkhash), pubkey)) if (pkhash && model->wallet().getPubKey(out.txout.scriptPubKey, ToKeyID(*pkhash), pubkey))
{ {
nBytesInputs += (pubkey.IsCompressed() ? 148 : 180); nBytesInputs += (pubkey.IsCompressed() ? 148 : 180);
} }

View file

@ -180,7 +180,7 @@ CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination&
// Only supports destinations which map to single public keys, i.e. P2PKH, // Only supports destinations which map to single public keys, i.e. P2PKH,
// P2WPKH, and P2SH-P2WPKH. // P2WPKH, and P2SH-P2WPKH.
if (auto id = boost::get<PKHash>(&dest)) { if (auto id = boost::get<PKHash>(&dest)) {
return CKeyID(*id); return ToKeyID(*id);
} }
if (auto witness_id = boost::get<WitnessV0KeyHash>(&dest)) { if (auto witness_id = boost::get<WitnessV0KeyHash>(&dest)) {
return CKeyID(*witness_id); return CKeyID(*witness_id);

View file

@ -23,6 +23,11 @@ ScriptHash::ScriptHash(const CScript& in) : uint160(Hash160(in.begin(), in.end()
PKHash::PKHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {} PKHash::PKHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
WitnessV0KeyHash::WitnessV0KeyHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {} WitnessV0KeyHash::WitnessV0KeyHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
CKeyID ToKeyID(const PKHash& key_hash)
{
return CKeyID{static_cast<uint160>(key_hash)};
}
WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in) WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)
{ {
CSHA256().Write(in.data(), in.size()).Finalize(begin()); CSHA256().Write(in.data(), in.size()).Finalize(begin());

View file

@ -79,6 +79,7 @@ struct PKHash : public uint160
explicit PKHash(const uint160& hash) : uint160(hash) {} explicit PKHash(const uint160& hash) : uint160(hash) {}
explicit PKHash(const CPubKey& pubkey); explicit PKHash(const CPubKey& pubkey);
}; };
CKeyID ToKeyID(const PKHash& key_hash);
struct WitnessV0KeyHash; struct WitnessV0KeyHash;
struct ScriptHash : public uint160 struct ScriptHash : public uint160

View file

@ -3517,7 +3517,7 @@ public:
UniValue operator()(const PKHash& pkhash) const UniValue operator()(const PKHash& pkhash) const
{ {
CKeyID keyID(pkhash); CKeyID keyID{ToKeyID(pkhash)};
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
CPubKey vchPubKey; CPubKey vchPubKey;
if (provider && provider->GetPubKey(keyID, vchPubKey)) { if (provider && provider->GetPubKey(keyID, vchPubKey)) {

View file

@ -573,9 +573,8 @@ bool LegacyScriptPubKeyMan::SignTransaction(CMutableTransaction& tx, const std::
SigningResult LegacyScriptPubKeyMan::SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const SigningResult LegacyScriptPubKeyMan::SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const
{ {
CKeyID key_id(pkhash);
CKey key; CKey key;
if (!GetKey(key_id, key)) { if (!GetKey(ToKeyID(pkhash), key)) {
return SigningResult::PRIVATE_KEY_NOT_AVAILABLE; return SigningResult::PRIVATE_KEY_NOT_AVAILABLE;
} }
@ -2052,9 +2051,8 @@ SigningResult DescriptorScriptPubKeyMan::SignMessage(const std::string& message,
return SigningResult::PRIVATE_KEY_NOT_AVAILABLE; return SigningResult::PRIVATE_KEY_NOT_AVAILABLE;
} }
CKeyID key_id(pkhash);
CKey key; CKey key;
if (!keys->GetKey(key_id, key)) { if (!keys->GetKey(ToKeyID(pkhash), key)) {
return SigningResult::PRIVATE_KEY_NOT_AVAILABLE; return SigningResult::PRIVATE_KEY_NOT_AVAILABLE;
} }