Skip to content

Commit bd93fc9

Browse files
committed
Fix change detection of imported internal descriptors
1 parent 42b66a6 commit bd93fc9

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
15591559
}
15601560

15611561
// Add descriptor to the wallet
1562-
auto spk_manager = pwallet->AddWalletDescriptor(w_desc, keys, label);
1562+
auto spk_manager = pwallet->AddWalletDescriptor(w_desc, keys, label, internal);
15631563
if (spk_manager == nullptr) {
15641564
throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Could not add descriptor '%s'", descriptor));
15651565
}

src/wallet/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4510,7 +4510,7 @@ DescriptorScriptPubKeyMan* CWallet::GetDescriptorScriptPubKeyMan(const WalletDes
45104510
return nullptr;
45114511
}
45124512

4513-
ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label)
4513+
ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal)
45144514
{
45154515
if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
45164516
WalletLogPrintf("Cannot add WalletDescriptor to a non-descriptor wallet\n");
@@ -4567,7 +4567,7 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat
45674567
}
45684568

45694569
CTxDestination dest;
4570-
if (ExtractDestination(script_pub_keys.at(0), dest)) {
4570+
if (!internal && ExtractDestination(script_pub_keys.at(0), dest)) {
45714571
SetAddressBook(dest, label, "receive");
45724572
}
45734573
}

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
12801280
DescriptorScriptPubKeyMan* GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const;
12811281

12821282
//! Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type
1283-
ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label);
1283+
ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal);
12841284
};
12851285

12861286
/**

test/functional/wallet_importdescriptors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- `test_address()` is called to call getaddressinfo for an address on node1
1616
and test the values returned."""
1717

18+
from test_framework.address import key_to_p2pkh
1819
from test_framework.test_framework import BitcoinTestFramework
1920
from test_framework.descriptors import descsum_create
2021
from test_framework.util import (
@@ -105,6 +106,17 @@ def run_test(self):
105106
error_code=-8,
106107
error_message="Internal addresses should not have a label")
107108

109+
self.log.info("Internal addresses should be detected as such")
110+
key = get_generate_key()
111+
addr = key_to_p2pkh(key.pubkey)
112+
self.test_importdesc({"desc": descsum_create("pkh(" + key.pubkey + ")"),
113+
"timestamp": "now",
114+
"internal": True},
115+
success=True)
116+
info = w1.getaddressinfo(addr)
117+
assert_equal(info["ismine"], True)
118+
assert_equal(info["ischange"], True)
119+
108120
# # Test importing of a P2SH-P2WPKH descriptor
109121
key = get_generate_key()
110122
self.log.info("Should not import a p2sh-p2wpkh descriptor without checksum")

0 commit comments

Comments
 (0)