aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-10-13 13:56:54 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-10-13 13:57:07 +0200
commitd7e195048342afae9168377cebfc22ab000728a5 (patch)
treeee5b07604ef073ef35d8aa13598fb7d6a4877bc4 /src/wallet.cpp
parentf98bd4eae1bc6d57c27cc13d0495941f15eddf19 (diff)
parentccca27a788fe1ae13661308243c20a1d7a3d0074 (diff)
Merge pull request #4937
ccca27a [Wallet] Watch-only fixes (Cozz Lovan)
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 026c53aa2e..19e43f6ec2 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -89,6 +89,13 @@ bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey)
AssertLockHeld(cs_wallet); // mapKeyMetadata
if (!CCryptoKeyStore::AddKeyPubKey(secret, pubkey))
return false;
+
+ // check if we need to remove from watch-only
+ CScript script;
+ script = GetScriptForDestination(pubkey.GetID());
+ if (HaveWatchOnly(script))
+ RemoveWatchOnly(script);
+
if (!fFileBacked)
return true;
if (!IsCrypted()) {
@@ -171,6 +178,20 @@ bool CWallet::AddWatchOnly(const CScript &dest)
return CWalletDB(strWalletFile).WriteWatchOnly(dest);
}
+bool CWallet::RemoveWatchOnly(const CScript &dest)
+{
+ AssertLockHeld(cs_wallet);
+ if (!CCryptoKeyStore::RemoveWatchOnly(dest))
+ return false;
+ if (!HaveWatchOnly())
+ NotifyWatchonlyChanged(false);
+ if (fFileBacked)
+ if (!CWalletDB(strWalletFile).EraseWatchOnly(dest))
+ return false;
+
+ return true;
+}
+
bool CWallet::LoadWatchOnly(const CScript &dest)
{
return CCryptoKeyStore::AddWatchOnly(dest);