aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorS3RK <1466284+S3RK@users.noreply.github.com>2021-06-28 21:37:53 +0200
committerS3RK <1466284+S3RK@users.noreply.github.com>2021-06-28 21:44:50 +0200
commit3efaf83c75cd8dc2fa084537b8ed6715fb58c04d (patch)
tree5cfbf5602d4d1379935bee09713a555bc4970b4a /src/wallet
parent6737d9655bcf527afbd85d610d805a2d0fd28c4f (diff)
downloadbitcoin-3efaf83c75cd8dc2fa084537b8ed6715fb58c04d.tar.xz
wallet: deactivate descriptor
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/rpcdump.cpp4
-rw-r--r--src/wallet/wallet.cpp17
-rw-r--r--src/wallet/wallet.h6
-rw-r--r--src/wallet/walletdb.cpp6
-rw-r--r--src/wallet/walletdb.h1
5 files changed, 34 insertions, 0 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 5f0d88288f..7de12c3a94 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -1584,6 +1584,10 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
} else {
wallet.AddActiveScriptPubKeyMan(spk_manager->GetID(), *w_desc.descriptor->GetOutputType(), internal);
}
+ } else {
+ if (w_desc.descriptor->GetOutputType()) {
+ wallet.DeactivateScriptPubKeyMan(spk_manager->GetID(), *w_desc.descriptor->GetOutputType(), internal);
+ }
}
result.pushKV("success", UniValue(true));
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 5ae490d5cc..521708e69c 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -3171,6 +3171,23 @@ void CWallet::LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool intern
NotifyCanGetAddressesChanged();
}
+void CWallet::DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal)
+{
+ auto spk_man = GetScriptPubKeyMan(type, internal);
+ if (spk_man != nullptr && spk_man->GetID() == id) {
+ WalletLogPrintf("Deactivate spkMan: id = %s, type = %d, internal = %d\n", id.ToString(), static_cast<int>(type), static_cast<int>(internal));
+ WalletBatch batch(GetDatabase());
+ if (!batch.EraseActiveScriptPubKeyMan(static_cast<uint8_t>(type), internal)) {
+ throw std::runtime_error(std::string(__func__) + ": erasing active ScriptPubKeyMan id failed");
+ }
+
+ auto& spk_mans = internal ? m_internal_spk_managers : m_external_spk_managers;
+ spk_mans[type] = nullptr;
+ }
+
+ NotifyCanGetAddressesChanged();
+}
+
bool CWallet::IsLegacy() const
{
if (m_internal_spk_managers.count(OutputType::LEGACY) == 0) {
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index b63938c5f1..001b94047a 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -895,6 +895,12 @@ public:
//! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
+ //! Remove specified ScriptPubKeyMan from set of active SPK managers. Writes the change to the wallet file.
+ //! @param[in] id The unique id for the ScriptPubKeyMan
+ //! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for
+ //! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
+ void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal);
+
//! Create new DescriptorScriptPubKeyMans and add them to the wallet
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 24d5351945..203fca8dd6 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -209,6 +209,12 @@ bool WalletBatch::WriteActiveScriptPubKeyMan(uint8_t type, const uint256& id, bo
return WriteIC(make_pair(key, type), id);
}
+bool WalletBatch::EraseActiveScriptPubKeyMan(uint8_t type, bool internal)
+{
+ const std::string key{internal ? DBKeys::ACTIVEINTERNALSPK : DBKeys::ACTIVEEXTERNALSPK};
+ return EraseIC(make_pair(key, type));
+}
+
bool WalletBatch::WriteDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const CPrivKey& privkey)
{
// hash pubkey/privkey to accelerate wallet load
diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h
index e7b2d7d780..d740aaadb3 100644
--- a/src/wallet/walletdb.h
+++ b/src/wallet/walletdb.h
@@ -253,6 +253,7 @@ public:
bool EraseDestData(const std::string &address, const std::string &key);
bool WriteActiveScriptPubKeyMan(uint8_t type, const uint256& id, bool internal);
+ bool EraseActiveScriptPubKeyMan(uint8_t type, bool internal);
DBErrors LoadWallet(CWallet* pwallet);
DBErrors FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWalletTx>& vWtx);