Skip to content

Commit a9e451f

Browse files
committed
Convert CPubKey to WitnessV0KeyHash directly
The round-tripping through PKHash has no effect, and is potentially misleading as such.
1 parent 3fcc468 commit a9e451f

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/outputtype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
5353
case OutputType::P2SH_SEGWIT:
5454
case OutputType::BECH32: {
5555
if (!key.IsCompressed()) return PKHash(key);
56-
CTxDestination witdest = WitnessV0KeyHash(PKHash(key));
56+
CTxDestination witdest = WitnessV0KeyHash(key);
5757
CScript witprog = GetScriptForDestination(witdest);
5858
if (type == OutputType::P2SH_SEGWIT) {
5959
return ScriptHash(witprog);

src/script/standard.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CScriptID::CScriptID(const CScript& in) : uint160(Hash160(in.begin(), in.end()))
2121
ScriptHash::ScriptHash(const CScript& in) : uint160(Hash160(in.begin(), in.end())) {}
2222

2323
PKHash::PKHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
24+
WitnessV0KeyHash::WitnessV0KeyHash(const CPubKey& pubkey) : uint160(pubkey.GetID()) {}
2425

2526
WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)
2627
{

src/script/standard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct WitnessV0KeyHash : public uint160
103103
{
104104
WitnessV0KeyHash() : uint160() {}
105105
explicit WitnessV0KeyHash(const uint160& hash) : uint160(hash) {}
106+
explicit WitnessV0KeyHash(const CPubKey& pubkey);
106107
};
107108

108109
//! CTxDestination subtype to encode any future Witness version

src/wallet/test/ismine_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
167167
keystore.SetupLegacyScriptPubKeyMan();
168168
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
169169

170-
CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
170+
CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0]));
171171
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
172172

173173
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
@@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
202202
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
203203
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
204204

205-
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
205+
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0]));
206206

207207
// Keystore implicitly has key and P2SH redeemScript
208208
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
@@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
217217
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
218218
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
219219

220-
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(uncompressedPubkey)));
220+
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(uncompressedPubkey));
221221

222222
// Keystore has key, but no P2SH redeemScript
223223
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);

0 commit comments

Comments
 (0)