diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-01-18 14:33:18 -0500 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2011-01-18 14:33:18 -0500 |
commit | 1aefe491fb1b1311973c9561493d201c7504a120 (patch) | |
tree | a105cf17ea86d8dbcd8e0f62e30bd2d037f13635 /rpc.cpp | |
parent | 04a9217dcf8c1c73e30b89e886c199522c4bbe9d (diff) | |
parent | fa446a563e4dab12ed68daf0832652b1bf133a21 (diff) | |
download | bitcoin-1aefe491fb1b1311973c9561493d201c7504a120.tar.xz |
Merge branch 'setaccountbug' of https://github.com/gavinandresen/bitcoin-git into integration
Diffstat (limited to 'rpc.cpp')
-rw-r--r-- | rpc.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
@@ -315,15 +315,9 @@ Value getnewaddress(const Array& params, bool fHelp) } -Value getaccountaddress(const Array& params, bool fHelp) +string GetAccountAddress(string strAccount, bool bForceNew=false) { - if (fHelp || params.size() != 1) - throw runtime_error( - "getaccountaddress <account>\n" - "Returns the current bitcoin address for receiving payments to this account."); - - // Parse the account first so we don't generate a key if there's an error - string strAccount = AccountFromValue(params[0]); + string strAddress; CRITICAL_BLOCK(cs_mapWallet) { @@ -350,7 +344,7 @@ Value getaccountaddress(const Array& params, bool fHelp) } // Generate a new key - if (account.vchPubKey.empty()) + if (account.vchPubKey.empty() || bForceNew) { account.vchPubKey = GetKeyFromKeyPool(); string strAddress = PubKeyToAddress(account.vchPubKey); @@ -359,11 +353,26 @@ Value getaccountaddress(const Array& params, bool fHelp) } walletdb.TxnCommit(); - return PubKeyToAddress(account.vchPubKey); + strAddress = PubKeyToAddress(account.vchPubKey); } + return strAddress; +} + +Value getaccountaddress(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "getaccountaddress <account>\n" + "Returns the current bitcoin address for receiving payments to this account."); + + // Parse the account first so we don't generate a key if there's an error + string strAccount = AccountFromValue(params[0]); + + return GetAccountAddress(strAccount); } + Value setaccount(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) @@ -376,6 +385,17 @@ 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: + CRITICAL_BLOCK(cs_mapAddressBook) + { + if (mapAddressBook.count(strAddress)) + { + string strOldAccount = mapAddressBook[strAddress]; + if (strAddress == GetAccountAddress(strOldAccount)) + GetAccountAddress(strOldAccount, true); + } + } + SetAddressBookName(strAddress, strAccount); return Value::null; } |