Skip to content

Commit 02d9f50

Browse files
committed
[wallet] Remove unneeded legacy getbalance code
1 parent 82b7dc3 commit 02d9f50

File tree

3 files changed

+3
-116
lines changed

3 files changed

+3
-116
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -739,45 +739,7 @@ UniValue getbalance(const JSONRPCRequest& request)
739739
if(request.params[2].get_bool())
740740
filter = filter | ISMINE_WATCH_ONLY;
741741

742-
CAmount legacyBalance = pwallet->GetLegacyBalance(filter, nMinDepth, account);
743-
744-
if (request.params[0].get_str() == "*") {
745-
// Calculate total balance in a very different way from GetBalance().
746-
// The biggest difference is that GetBalance() sums up all unspent
747-
// TxOuts paying to the wallet, while this sums up both spent and
748-
// unspent TxOuts paying to the wallet, and then subtracts the values of
749-
// TxIns spending from the wallet. This also has fewer restrictions on
750-
// which unconfirmed transactions are considered trusted.
751-
CAmount nBalance = 0;
752-
for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
753-
const CWalletTx& wtx = pairWtx.second;
754-
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
755-
continue;
756-
757-
CAmount allFee;
758-
std::string strSentAccount;
759-
std::list<COutputEntry> listReceived;
760-
std::list<COutputEntry> listSent;
761-
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
762-
if (wtx.GetDepthInMainChain() >= nMinDepth)
763-
{
764-
BOOST_FOREACH(const COutputEntry& r, listReceived)
765-
nBalance += r.amount;
766-
}
767-
BOOST_FOREACH(const COutputEntry& s, listSent)
768-
nBalance -= s.amount;
769-
nBalance -= allFee;
770-
}
771-
assert(nBalance == legacyBalance);
772-
return ValueFromAmount(nBalance);
773-
}
774-
775-
std::string strAccount = AccountFromValue(request.params[0]);
776-
777-
CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, filter);
778-
779-
assert(nBalance == legacyBalance);
780-
return ValueFromAmount(nBalance);
742+
return ValueFromAmount(pwallet->GetLegacyBalance(filter, nMinDepth, account));
781743
}
782744

783745
UniValue getunconfirmedbalance(const JSONRPCRequest &request)
@@ -907,9 +869,7 @@ UniValue sendfrom(const JSONRPCRequest& request)
907869
EnsureWalletIsUnlocked(pwallet);
908870

909871
// Check funds
910-
CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
911-
CAmount legacyBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
912-
assert(nBalance == legacyBalance);
872+
CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
913873
if (nAmount > nBalance)
914874
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
915875

@@ -1018,9 +978,7 @@ UniValue sendmany(const JSONRPCRequest& request)
1018978
EnsureWalletIsUnlocked(pwallet);
1019979

1020980
// Check funds
1021-
CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
1022-
CAmount legacyBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
1023-
assert(nBalance == legacyBalance);
981+
CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
1024982
if (totalAmount > nBalance)
1025983
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
1026984

src/wallet/wallet.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,41 +1457,6 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
14571457

14581458
}
14591459

1460-
void CWalletTx::GetAccountAmounts(const std::string& strAccount, CAmount& nReceived,
1461-
CAmount& nSent, CAmount& nFee, const isminefilter& filter) const
1462-
{
1463-
nReceived = nSent = nFee = 0;
1464-
1465-
CAmount allFee;
1466-
std::string strSentAccount;
1467-
std::list<COutputEntry> listReceived;
1468-
std::list<COutputEntry> listSent;
1469-
GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
1470-
1471-
if (strAccount == strSentAccount)
1472-
{
1473-
BOOST_FOREACH(const COutputEntry& s, listSent)
1474-
nSent += s.amount;
1475-
nFee = allFee;
1476-
}
1477-
{
1478-
LOCK(pwallet->cs_wallet);
1479-
BOOST_FOREACH(const COutputEntry& r, listReceived)
1480-
{
1481-
if (pwallet->mapAddressBook.count(r.destination))
1482-
{
1483-
std::map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(r.destination);
1484-
if (mi != pwallet->mapAddressBook.end() && (*mi).second.name == strAccount)
1485-
nReceived += r.amount;
1486-
}
1487-
else if (strAccount.empty())
1488-
{
1489-
nReceived += r.amount;
1490-
}
1491-
}
1492-
}
1493-
}
1494-
14951460
/**
14961461
* Scan the block chain (starting in pindexStart) for transactions
14971462
* from or to us. If fUpdate is true, found transactions that already
@@ -3315,37 +3280,6 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
33153280
return ret;
33163281
}
33173282

3318-
CAmount CWallet::GetAccountBalance(const std::string& strAccount, int nMinDepth, const isminefilter& filter)
3319-
{
3320-
CWalletDB walletdb(*dbw);
3321-
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
3322-
}
3323-
3324-
CAmount CWallet::GetAccountBalance(CWalletDB& walletdb, const std::string& strAccount, int nMinDepth, const isminefilter& filter)
3325-
{
3326-
CAmount nBalance = 0;
3327-
3328-
// Tally wallet transactions
3329-
for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
3330-
{
3331-
const CWalletTx& wtx = (*it).second;
3332-
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
3333-
continue;
3334-
3335-
CAmount nReceived, nSent, nFee;
3336-
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
3337-
3338-
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
3339-
nBalance += nReceived;
3340-
nBalance -= nSent + nFee;
3341-
}
3342-
3343-
// Tally internal accounting entries
3344-
nBalance += walletdb.GetAccountCreditDebit(strAccount);
3345-
3346-
return nBalance;
3347-
}
3348-
33493283
std::set<CTxDestination> CWallet::GetAccountAddresses(const std::string& strAccount) const
33503284
{
33513285
LOCK(cs_wallet);

src/wallet/wallet.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,6 @@ class CWalletTx : public CMerkleTx
451451
void GetAmounts(std::list<COutputEntry>& listReceived,
452452
std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
453453

454-
void GetAccountAmounts(const std::string& strAccount, CAmount& nReceived,
455-
CAmount& nSent, CAmount& nFee, const isminefilter& filter) const;
456-
457454
bool IsFromMe(const isminefilter& filter) const
458455
{
459456
return (GetDebit(filter) > 0);
@@ -973,8 +970,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
973970
std::set< std::set<CTxDestination> > GetAddressGroupings();
974971
std::map<CTxDestination, CAmount> GetAddressBalances();
975972

976-
CAmount GetAccountBalance(const std::string& strAccount, int nMinDepth, const isminefilter& filter);
977-
CAmount GetAccountBalance(CWalletDB& walletdb, const std::string& strAccount, int nMinDepth, const isminefilter& filter);
978973
std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const;
979974

980975
isminetype IsMine(const CTxIn& txin) const;

0 commit comments

Comments
 (0)