mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
wallet: allow to import same descriptor twice
This commit is contained in:
@@ -1875,6 +1875,12 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const
|
||||
AssertLockHeld(cs_desc_man);
|
||||
assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
|
||||
|
||||
// Check if provided key already exists
|
||||
if (m_map_keys.find(pubkey.GetID()) != m_map_keys.end() ||
|
||||
m_map_crypted_keys.find(pubkey.GetID()) != m_map_crypted_keys.end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_storage.HasEncryptionKeys()) {
|
||||
if (m_storage.IsLocked()) {
|
||||
return false;
|
||||
@@ -2302,3 +2308,37 @@ bool DescriptorScriptPubKeyMan::GetDescriptorString(std::string& out, bool priv)
|
||||
|
||||
return m_wallet_descriptor.descriptor->ToNormalizedString(provider, out, priv);
|
||||
}
|
||||
|
||||
void DescriptorScriptPubKeyMan::UpdateWalletDescriptor(WalletDescriptor& descriptor)
|
||||
{
|
||||
LOCK(cs_desc_man);
|
||||
std::string error;
|
||||
if (!CanUpdateToWalletDescriptor(descriptor, error)) {
|
||||
throw std::runtime_error(std::string(__func__) + ": " + error);
|
||||
}
|
||||
|
||||
m_map_pubkeys.clear();
|
||||
m_map_script_pub_keys.clear();
|
||||
m_max_cached_index = -1;
|
||||
m_wallet_descriptor = descriptor;
|
||||
}
|
||||
|
||||
bool DescriptorScriptPubKeyMan::CanUpdateToWalletDescriptor(const WalletDescriptor& descriptor, std::string& error)
|
||||
{
|
||||
LOCK(cs_desc_man);
|
||||
if (!HasWalletDescriptor(descriptor)) {
|
||||
error = "can only update matching descriptor";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (descriptor.range_start > m_wallet_descriptor.range_start ||
|
||||
descriptor.range_end < m_wallet_descriptor.range_end) {
|
||||
// Use inclusive range for error
|
||||
error = strprintf("new range must include current range = [%d,%d]",
|
||||
m_wallet_descriptor.range_start,
|
||||
m_wallet_descriptor.range_end - 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user