From cfc3dd34284357262bcc7eef2714a210891276c0 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 10 Jun 2015 00:03:08 -0700 Subject: [PATCH] Also remove pay-2-pubkey from watch when adding a priv key --- src/script/standard.cpp | 5 +++++ src/script/standard.h | 1 + src/wallet/wallet.cpp | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/script/standard.cpp b/src/script/standard.cpp index 66657127a..1d5aac7b3 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -286,6 +286,11 @@ CScript GetScriptForDestination(const CTxDestination& dest) return script; } +CScript GetScriptForRawPubKey(const CPubKey& pubKey) +{ + return CScript() << std::vector(pubKey.begin(), pubKey.end()) << OP_CHECKSIG; +} + CScript GetScriptForMultisig(int nRequired, const std::vector& keys) { CScript script; diff --git a/src/script/standard.h b/src/script/standard.h index 46ae5f9f1..9e17dac70 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -73,6 +73,7 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet) bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector& addressRet, int& nRequiredRet); CScript GetScriptForDestination(const CTxDestination& dest); +CScript GetScriptForRawPubKey(const CPubKey& pubkey); CScript GetScriptForMultisig(int nRequired, const std::vector& keys); #endif // BITCOIN_SCRIPT_STANDARD_H diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7b3cd9803..c11800863 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -106,6 +106,9 @@ bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey) // check if we need to remove from watch-only CScript script; script = GetScriptForDestination(pubkey.GetID()); + if (HaveWatchOnly(script)) + RemoveWatchOnly(script); + script = GetScriptForRawPubKey(pubkey); if (HaveWatchOnly(script)) RemoveWatchOnly(script);