diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 2f60ca75..c1a5906f 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -14,6 +14,7 @@ #include "util.h" #include "wallet.h" #include "walletdb.h" +#include "webwalletconnector.h" using namespace std; using namespace json_spirit; @@ -351,7 +352,12 @@ Value setaccount(const Array& params, bool fHelp) if (address == GetAccountAddress(strOldAccount)) GetAccountAddress(strOldAccount, true); } - pwalletMain->SetAddressBookName(address.Get(), strAccount); + if (fWebWalletMode) { + pwalletMain->SetAddressAccountIdAssociation(address.Get(), strAccount); + } + else { + pwalletMain->SetAddressBookName(address.Get(), strAccount); + } } else throw JSONRPCError(RPC_MISC_ERROR, "setaccount can only be used with own address"); diff --git a/src/wallet.cpp b/src/wallet.cpp index e51e49f2..7b799e37 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -22,6 +22,7 @@ #include "masternode-payments.h" #include "chainparams.h" #include "smessage.h" +#include "webwalletconnector.h" #include @@ -3444,6 +3445,12 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet) bool CWallet::SetAddressBookName(const CTxDestination& address, const string& strName) { + // never update address book if this is web wallet as this will break account<>address mapping + if (fWebWalletMode) + { + return true; + } + bool fUpdated = false; { LOCK(cs_wallet); // mapAddressBook @@ -3458,6 +3465,29 @@ bool CWallet::SetAddressBookName(const CTxDestination& address, const string& st return CWalletDB(strWalletFile).WriteName(CDigitalNoteAddress(address).ToString(), strName); } +bool CWallet::SetAddressAccountIdAssociation(const CTxDestination& address, const string& strName) +{ + if (!fWebWalletMode) + { + return true; + } + + bool fUpdated = false; + { + LOCK(cs_wallet); + std::map::iterator mi = mapAddressBook.find(address); + fUpdated = mi != mapAddressBook.end(); + // only allow to create association + if (mapAddressBook[address] == "") { + mapAddressBook[address] = strName; + } + } + + if (!fFileBacked) + return false; + return CWalletDB(strWalletFile).WriteName(CDigitalNoteAddress(address).ToString(), strName); +} + bool CWallet::DelAddressBookName(const CTxDestination& address) { { diff --git a/src/wallet.h b/src/wallet.h index 05dd8b31..dbabd251 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -390,6 +390,8 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface bool SetAddressBookName(const CTxDestination& address, const std::string& strName); + bool SetAddressAccountIdAssociation(const CTxDestination& address, const std::string& strName); + bool DelAddressBookName(const CTxDestination& address); bool UpdatedTransaction(const uint256 &hashTx); diff --git a/src/webwalletconnector.cpp b/src/webwalletconnector.cpp index ec081c32..1217b601 100644 --- a/src/webwalletconnector.cpp +++ b/src/webwalletconnector.cpp @@ -63,6 +63,7 @@ typedef websocketpp::server server; typedef std::set > con_list; bool fWebWalletConnectorEnabled = false; +bool fWebWalletMode = false; std::mutex m_action_lock; std::mutex m_connection_lock; @@ -231,6 +232,7 @@ bool WebWalletConnectorStart(bool fDontStart) LogPrint("webwallet", "webwallet: Web wallet connector not started.\n"); return false; } + fWebWalletMode = true; fWebWalletConnectorEnabled = true; threadGroupWebWalletConnector.create_thread(boost::bind(&TraceThread, "webwallet", &ThreadWebsocketServer)); diff --git a/src/webwalletconnector.h b/src/webwalletconnector.h index 396b278c..c3c93105 100644 --- a/src/webwalletconnector.h +++ b/src/webwalletconnector.h @@ -9,6 +9,7 @@ #include "smessage.h" +extern bool fWebWalletMode; extern bool fWebWalletConnectorEnabled; bool WebWalletConnectorStart(bool fDontStart);