aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2020-01-15 13:40:14 -0800
committerBen Woosley <ben.woosley@gmail.com>2020-06-19 12:14:07 -0700
commit2c54217f913967703b404747133be67cf2f4feac (patch)
tree5e0e846cd14a58414943f5f8a91ff055bbd0ee63 /src/script
parenta9e451f144480d7b170e49087df162989d31cd20 (diff)
downloadbitcoin-2c54217f913967703b404747133be67cf2f4feac.tar.xz
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
Diffstat (limited to 'src/script')
-rw-r--r--src/script/signingprovider.cpp2
-rw-r--r--src/script/standard.cpp5
-rw-r--r--src/script/standard.h1
3 files changed, 7 insertions, 1 deletions
diff --git a/src/script/signingprovider.cpp b/src/script/signingprovider.cpp
index 01757e2f65..a4eb0a8399 100644
--- a/src/script/signingprovider.cpp
+++ b/src/script/signingprovider.cpp
@@ -180,7 +180,7 @@ CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination&
// Only supports destinations which map to single public keys, i.e. P2PKH,
// P2WPKH, and P2SH-P2WPKH.
if (auto id = boost::get<PKHash>(&dest)) {
- return CKeyID(*id);
+ return ToKeyID(*id);
}
if (auto witness_id = boost::get<WitnessV0KeyHash>(&dest)) {
return CKeyID(*witness_id);
diff --git a/src/script/standard.cpp b/src/script/standard.cpp
index 3e0a9e2304..4b408d82e3 100644
--- a/src/script/standard.cpp
+++ b/src/script/standard.cpp
@@ -23,6 +23,11 @@ ScriptHash::ScriptHash(const CScript& in) : uint160(Hash160(in.begin(), in.end()
PKHash::PKHash(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)
{
CSHA256().Write(in.data(), in.size()).Finalize(begin());
diff --git a/src/script/standard.h b/src/script/standard.h
index 382d8d002b..1c630744be 100644
--- a/src/script/standard.h
+++ b/src/script/standard.h
@@ -79,6 +79,7 @@ struct PKHash : public uint160
explicit PKHash(const uint160& hash) : uint160(hash) {}
explicit PKHash(const CPubKey& pubkey);
};
+CKeyID ToKeyID(const PKHash& key_hash);
struct WitnessV0KeyHash;
struct ScriptHash : public uint160