aboutsummaryrefslogtreecommitdiff
path: root/src/rpcwallet.cpp
diff options
context:
space:
mode:
authorEric Shaw <ericshaw.linux@gmail.com>2014-09-25 18:39:28 -0400
committerWladimir J. van der Laan <laanwj@gmail.com>2014-10-02 19:21:46 +0200
commit31d6390fd17803ab9870e239a0c0c4d0a6be5c68 (patch)
tree1c07e8e8639e5dc9f6a0d7eb48fe7f3ac510700b /src/rpcwallet.cpp
parent4b2b78b9f2bd339cc4505996258e00c186e91792 (diff)
downloadbitcoin-31d6390fd17803ab9870e239a0c0c4d0a6be5c68.tar.xz
Fixed setaccount accepting foreign address
Fixed issue #4209 where using setaccount with a foreign address causes the address to be added to your receiving addresses.
Diffstat (limited to 'src/rpcwallet.cpp')
-rw-r--r--src/rpcwallet.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 35637362a4..b361e67911 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -230,15 +230,20 @@ Value setaccount(const Array& params, bool fHelp)
if (params.size() > 1)
strAccount = AccountFromValue(params[1]);
- // Detect when changing the account of an address that is the 'unused current key' of another account:
- if (pwalletMain->mapAddressBook.count(address.Get()))
+ // Only add the account if the address is yours.
+ if (IsMine(*pwalletMain, address.Get()))
{
- string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name;
- if (address == GetAccountAddress(strOldAccount))
- GetAccountAddress(strOldAccount, true);
+ // Detect when changing the account of an address that is the 'unused current key' of another account:
+ if (pwalletMain->mapAddressBook.count(address.Get()))
+ {
+ string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name;
+ if (address == GetAccountAddress(strOldAccount))
+ GetAccountAddress(strOldAccount, true);
+ }
+ pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
}
-
- pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
+ else
+ throw JSONRPCError(RPC_MISC_ERROR, "setaccount can only be used with own address");
return Value::null;
}