aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2020-01-14 23:46:14 -0800
committerBen Woosley <ben.woosley@gmail.com>2020-06-19 12:14:07 -0700
commita9e451f144480d7b170e49087df162989d31cd20 (patch)
treea50496593555392d0c996311f65026dc6582a737
parent3fcc46812334074d2c77a6233e8a961cd0785872 (diff)
Convert CPubKey to WitnessV0KeyHash directly
The round-tripping through PKHash has no effect, and is potentially misleading as such.
-rw-r--r--src/outputtype.cpp2
-rw-r--r--src/script/standard.cpp1
-rw-r--r--src/script/standard.h1
-rw-r--r--src/wallet/test/ismine_tests.cpp6
4 files changed, 6 insertions, 4 deletions
diff --git a/src/outputtype.cpp b/src/outputtype.cpp
index ea7a86d6d6..871474d56e 100644
--- a/src/outputtype.cpp
+++ b/src/outputtype.cpp
@@ -53,7 +53,7 @@ CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
case OutputType::P2SH_SEGWIT:
case OutputType::BECH32: {
if (!key.IsCompressed()) return PKHash(key);
- CTxDestination witdest = WitnessV0KeyHash(PKHash(key));
+ CTxDestination witdest = WitnessV0KeyHash(key);
CScript witprog = GetScriptForDestination(witdest);
if (type == OutputType::P2SH_SEGWIT) {
return ScriptHash(witprog);
diff --git a/src/script/standard.cpp b/src/script/standard.cpp
index b6ee6117d9..3e0a9e2304 100644
--- a/src/script/standard.cpp
+++ b/src/script/standard.cpp
@@ -21,6 +21,7 @@ CScriptID::CScriptID(const CScript& in) : uint160(Hash160(in.begin(), in.end()))
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()) {}
WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)
{
diff --git a/src/script/standard.h b/src/script/standard.h
index 7c74d05be5..382d8d002b 100644
--- a/src/script/standard.h
+++ b/src/script/standard.h
@@ -103,6 +103,7 @@ struct WitnessV0KeyHash : public uint160
{
WitnessV0KeyHash() : uint160() {}
explicit WitnessV0KeyHash(const uint160& hash) : uint160(hash) {}
+ explicit WitnessV0KeyHash(const CPubKey& pubkey);
};
//! CTxDestination subtype to encode any future Witness version
diff --git a/src/wallet/test/ismine_tests.cpp b/src/wallet/test/ismine_tests.cpp
index cdb0522920..e416f16044 100644
--- a/src/wallet/test/ismine_tests.cpp
+++ b/src/wallet/test/ismine_tests.cpp
@@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
keystore.SetupLegacyScriptPubKeyMan();
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
- CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
+ CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0]));
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
@@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
- scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
+ scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0]));
// Keystore implicitly has key and P2SH redeemScript
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
@@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
- scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(uncompressedPubkey)));
+ scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(uncompressedPubkey));
// Keystore has key, but no P2SH redeemScript
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);