Skip to content

Commit

Permalink
[refactor] GetAccount{PubKey,Address} -> GetAccountDestination
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Jan 3, 2018
1 parent 0c8ea63 commit cbe1974
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ UniValue getnewaddress(const JSONRPCRequest& request)
}


CTxDestination GetAccountAddress(CWallet* const pwallet, std::string strAccount, bool bForceNew=false)
CTxDestination GetAccountDestination(CWallet* const pwallet, std::string strAccount, bool bForceNew=false)
{
CPubKey pubKey;
if (!pwallet->GetAccountPubkey(pubKey, strAccount, bForceNew)) {
CTxDestination dest;
if (!pwallet->GetAccountDestination(dest, strAccount, bForceNew)) {
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
}

return pubKey.GetID();
return dest;
}

UniValue getaccountaddress(const JSONRPCRequest& request)
Expand Down Expand Up @@ -214,7 +214,7 @@ UniValue getaccountaddress(const JSONRPCRequest& request)

UniValue ret(UniValue::VSTR);

ret = EncodeDestination(GetAccountAddress(pwallet, strAccount));
ret = EncodeDestination(GetAccountDestination(pwallet, strAccount));
return ret;
}

Expand Down Expand Up @@ -292,8 +292,8 @@ UniValue setaccount(const JSONRPCRequest& request)
// Detect when changing the account of an address that is the 'unused current key' of another account:
if (pwallet->mapAddressBook.count(dest)) {
std::string strOldAccount = pwallet->mapAddressBook[dest].name;
if (dest == GetAccountAddress(pwallet, strOldAccount)) {
GetAccountAddress(pwallet, strOldAccount, true);
if (dest == GetAccountDestination(pwallet, strOldAccount)) {
GetAccountDestination(pwallet, strOldAccount, true);
}
}
pwallet->SetAddressBook(dest, strAccount, "receive");
Expand Down
9 changes: 5 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun
return true;
}

bool CWallet::GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew)
bool CWallet::GetAccountDestination(CTxDestination &dest, std::string strAccount, bool bForceNew)
{
CWalletDB walletdb(*dbw);

Expand Down Expand Up @@ -850,12 +850,13 @@ bool CWallet::GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bFo
if (!GetKeyFromPool(account.vchPubKey, false))
return false;

SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
dest = account.vchPubKey.GetID();
SetAddressBook(dest, strAccount, "receive");
walletdb.WriteAccount(strAccount, account);
} else {
dest = account.vchPubKey.GetID();
}

pubKey = account.vchPubKey;

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
int64_t IncOrderPosNext(CWalletDB *pwalletdb = nullptr);
DBErrors ReorderTransactions();
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false);
bool GetAccountDestination(CTxDestination &dest, std::string strAccount, bool bForceNew = false);

void MarkDirty();
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
Expand Down

0 comments on commit cbe1974

Please sign in to comment.