Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "util.h"
#include "wallet.h"
#include "walletdb.h"
#include "webwalletconnector.h"

using namespace std;
using namespace json_spirit;
Expand Down Expand Up @@ -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");
Expand Down
30 changes: 30 additions & 0 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "masternode-payments.h"
#include "chainparams.h"
#include "smessage.h"
#include "webwalletconnector.h"

#include <boost/algorithm/string/replace.hpp>

Expand Down Expand Up @@ -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
Expand All @@ -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<CTxDestination, std::string>::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)
{
{
Expand Down
2 changes: 2 additions & 0 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/webwalletconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ typedef websocketpp::server<websocketpp::config::asio> server;
typedef std::set<connection_hdl,std::owner_less<connection_hdl> > con_list;

bool fWebWalletConnectorEnabled = false;
bool fWebWalletMode = false;

std::mutex m_action_lock;
std::mutex m_connection_lock;
Expand Down Expand Up @@ -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<void (*)()>, "webwallet", &ThreadWebsocketServer));
Expand Down
1 change: 1 addition & 0 deletions src/webwalletconnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "smessage.h"

extern bool fWebWalletMode;
extern bool fWebWalletConnectorEnabled;

bool WebWalletConnectorStart(bool fDontStart);
Expand Down