@@ -208,6 +208,22 @@ IsMineResult IsMineInner(const LegacyScriptPubKeyMan& keystore, const CScript& s
208208
209209} // namespace
210210
211+ static inline CScript StripAdditionalTransactionData (CScript newScript)
212+ {
213+ const unsigned int scriptSize = newScript.size ();
214+ if (scriptSize >= 29 && scriptSize <= 65 && newScript[0 ] == OP_DUP && newScript[1 ] == OP_HASH160 && newScript[2 ] == 20 && newScript[23 ] == OP_EQUALVERIFY &&
215+ newScript[24 ] == OP_CHECKSIG && newScript[scriptSize - 2 ] == OP_CHECKBLOCKATHEIGHTVERIFY && newScript.back () == OP_2DROP) { // TxoutType::PUBKEYHASH_REPLAY
216+ newScript = CScript (newScript.begin (), newScript.begin () + 25 );
217+ } else if (scriptSize >= 27 && scriptSize <= 63 && newScript[0 ] == OP_HASH160 && newScript[1 ] == 20 && newScript[22 ] == OP_EQUAL &&
218+ newScript[scriptSize - 2 ] == OP_CHECKBLOCKATHEIGHTVERIFY && newScript.back () == OP_2DROP) { // TxoutType::SCRIPTHASH_REPLAY
219+ newScript = CScript (newScript.begin (), newScript.begin () + 23 );
220+ } else if (scriptSize >= (CPubKey::COMPRESSED_SIZE + 6 ) && scriptSize <= (CPubKey::COMPRESSED_SIZE + 125 ) && newScript[0 ] == CPubKey::COMPRESSED_SIZE && newScript[CPubKey::COMPRESSED_SIZE + 1 ] == OP_CHECKSIG &&
221+ newScript[scriptSize - 2 ] == OP_CHECKBLOCKATHEIGHTVERIFY && newScript.back () == OP_2DROP) { // TxoutType::PUBKEY_REPLAY and TxoutType::PUBKEY_DATA_REPLAY
222+ newScript = CScript (newScript.begin (), newScript.begin () + CPubKey::COMPRESSED_SIZE + 2 );
223+ }
224+ return newScript;
225+ }
226+
211227isminetype LegacyScriptPubKeyMan::IsMine (const CScript& script) const
212228{
213229 switch (IsMineInner (*this , script, IsMineSigVersion::TOP)) {
@@ -847,7 +863,7 @@ bool LegacyScriptPubKeyMan::AddCryptedKey(const CPubKey &vchPubKey,
847863bool LegacyScriptPubKeyMan::HaveWatchOnly (const CScript &dest) const
848864{
849865 LOCK (cs_KeyStore);
850- return setWatchOnly.count (dest) > 0 ;
866+ return setWatchOnly.count (StripAdditionalTransactionData ( dest) ) > 0 ;
851867}
852868
853869bool LegacyScriptPubKeyMan::HaveWatchOnly () const
@@ -1455,7 +1471,7 @@ std::vector<CKeyID> GetAffectedKeys(const CScript& spk, const SigningProvider& p
14551471{
14561472 std::vector<CScript> dummy;
14571473 FlatSigningProvider out;
1458- InferDescriptor (spk, provider)->Expand (0 , DUMMY_SIGNING_PROVIDER, dummy, out);
1474+ InferDescriptor (StripAdditionalTransactionData ( spk) , provider)->Expand (0 , DUMMY_SIGNING_PROVIDER, dummy, out);
14591475 std::vector<CKeyID> ret;
14601476 for (const auto & entry : out.pubkeys ) {
14611477 ret.push_back (entry.first );
@@ -1659,22 +1675,6 @@ bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDest
16591675 }
16601676}
16611677
1662- static CScript StripAdditionalTransactionData (CScript newScript)
1663- {
1664- const unsigned int scriptSize = newScript.size ();
1665- if (scriptSize >= 29 && scriptSize <= 65 && newScript[0 ] == OP_DUP && newScript[1 ] == OP_HASH160 && newScript[2 ] == 20 && newScript[23 ] == OP_EQUALVERIFY &&
1666- newScript[24 ] == OP_CHECKSIG && newScript[scriptSize - 2 ] == OP_CHECKBLOCKATHEIGHTVERIFY && newScript.back () == OP_2DROP) { // TxoutType::PUBKEYHASH_REPLAY
1667- newScript = CScript (newScript.begin (), newScript.begin () + 25 );
1668- } else if (scriptSize >= 27 && scriptSize <= 63 && newScript[0 ] == OP_HASH160 && newScript[1 ] == 20 && newScript[22 ] == OP_EQUAL &&
1669- newScript[scriptSize - 2 ] == OP_CHECKBLOCKATHEIGHTVERIFY && newScript.back () == OP_2DROP) { // TxoutType::SCRIPTHASH_REPLAY
1670- newScript = CScript (newScript.begin (), newScript.begin () + 23 );
1671- } else if (scriptSize >= (CPubKey::COMPRESSED_SIZE + 6 ) && scriptSize <= (CPubKey::COMPRESSED_SIZE + 125 ) && newScript[0 ] == CPubKey::COMPRESSED_SIZE && newScript[CPubKey::COMPRESSED_SIZE + 1 ] == OP_CHECKSIG &&
1672- newScript[scriptSize - 2 ] == OP_CHECKBLOCKATHEIGHTVERIFY && newScript.back () == OP_2DROP) { // TxoutType::PUBKEY_REPLAY and TxoutType::PUBKEY_DATA_REPLAY
1673- newScript = CScript (newScript.begin (), newScript.begin () + CPubKey::COMPRESSED_SIZE + 2 );
1674- }
1675- return newScript;
1676- }
1677-
16781678isminetype DescriptorScriptPubKeyMan::IsMine (const CScript& script) const
16791679{
16801680 LOCK (cs_desc_man);
0 commit comments