Browse Source

[wallet] Remove unneeded legacy getbalance code

0.15
Russell Yanofsky 8 years ago
parent
commit
02d9f50d5f
  1. 48
      src/wallet/rpcwallet.cpp
  2. 66
      src/wallet/wallet.cpp
  3. 5
      src/wallet/wallet.h

48
src/wallet/rpcwallet.cpp

@ -739,45 +739,7 @@ UniValue getbalance(const JSONRPCRequest& request)
if(request.params[2].get_bool()) if(request.params[2].get_bool())
filter = filter | ISMINE_WATCH_ONLY; filter = filter | ISMINE_WATCH_ONLY;
CAmount legacyBalance = pwallet->GetLegacyBalance(filter, nMinDepth, account); return ValueFromAmount(pwallet->GetLegacyBalance(filter, nMinDepth, account));
if (request.params[0].get_str() == "*") {
// Calculate total balance in a very different way from GetBalance().
// The biggest difference is that GetBalance() sums up all unspent
// TxOuts paying to the wallet, while this sums up both spent and
// unspent TxOuts paying to the wallet, and then subtracts the values of
// TxIns spending from the wallet. This also has fewer restrictions on
// which unconfirmed transactions are considered trusted.
CAmount nBalance = 0;
for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
const CWalletTx& wtx = pairWtx.second;
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
continue;
CAmount allFee;
std::string strSentAccount;
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
if (wtx.GetDepthInMainChain() >= nMinDepth)
{
BOOST_FOREACH(const COutputEntry& r, listReceived)
nBalance += r.amount;
}
BOOST_FOREACH(const COutputEntry& s, listSent)
nBalance -= s.amount;
nBalance -= allFee;
}
assert(nBalance == legacyBalance);
return ValueFromAmount(nBalance);
}
std::string strAccount = AccountFromValue(request.params[0]);
CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, filter);
assert(nBalance == legacyBalance);
return ValueFromAmount(nBalance);
} }
UniValue getunconfirmedbalance(const JSONRPCRequest &request) UniValue getunconfirmedbalance(const JSONRPCRequest &request)
@ -907,9 +869,7 @@ UniValue sendfrom(const JSONRPCRequest& request)
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
// Check funds // Check funds
CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
CAmount legacyBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
assert(nBalance == legacyBalance);
if (nAmount > nBalance) if (nAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
@ -1018,9 +978,7 @@ UniValue sendmany(const JSONRPCRequest& request)
EnsureWalletIsUnlocked(pwallet); EnsureWalletIsUnlocked(pwallet);
// Check funds // Check funds
CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
CAmount legacyBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
assert(nBalance == legacyBalance);
if (totalAmount > nBalance) if (totalAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");

66
src/wallet/wallet.cpp

@ -1457,41 +1457,6 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
} }
void CWalletTx::GetAccountAmounts(const std::string& strAccount, CAmount& nReceived,
CAmount& nSent, CAmount& nFee, const isminefilter& filter) const
{
nReceived = nSent = nFee = 0;
CAmount allFee;
std::string strSentAccount;
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
if (strAccount == strSentAccount)
{
BOOST_FOREACH(const COutputEntry& s, listSent)
nSent += s.amount;
nFee = allFee;
}
{
LOCK(pwallet->cs_wallet);
BOOST_FOREACH(const COutputEntry& r, listReceived)
{
if (pwallet->mapAddressBook.count(r.destination))
{
std::map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(r.destination);
if (mi != pwallet->mapAddressBook.end() && (*mi).second.name == strAccount)
nReceived += r.amount;
}
else if (strAccount.empty())
{
nReceived += r.amount;
}
}
}
}
/** /**
* Scan the block chain (starting in pindexStart) for transactions * Scan the block chain (starting in pindexStart) for transactions
* from or to us. If fUpdate is true, found transactions that already * from or to us. If fUpdate is true, found transactions that already
@ -3315,37 +3280,6 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
return ret; return ret;
} }
CAmount CWallet::GetAccountBalance(const std::string& strAccount, int nMinDepth, const isminefilter& filter)
{
CWalletDB walletdb(*dbw);
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
}
CAmount CWallet::GetAccountBalance(CWalletDB& walletdb, const std::string& strAccount, int nMinDepth, const isminefilter& filter)
{
CAmount nBalance = 0;
// Tally wallet transactions
for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
continue;
CAmount nReceived, nSent, nFee;
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
nBalance += nReceived;
nBalance -= nSent + nFee;
}
// Tally internal accounting entries
nBalance += walletdb.GetAccountCreditDebit(strAccount);
return nBalance;
}
std::set<CTxDestination> CWallet::GetAccountAddresses(const std::string& strAccount) const std::set<CTxDestination> CWallet::GetAccountAddresses(const std::string& strAccount) const
{ {
LOCK(cs_wallet); LOCK(cs_wallet);

5
src/wallet/wallet.h

@ -451,9 +451,6 @@ public:
void GetAmounts(std::list<COutputEntry>& listReceived, void GetAmounts(std::list<COutputEntry>& listReceived,
std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const; std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
void GetAccountAmounts(const std::string& strAccount, CAmount& nReceived,
CAmount& nSent, CAmount& nFee, const isminefilter& filter) const;
bool IsFromMe(const isminefilter& filter) const bool IsFromMe(const isminefilter& filter) const
{ {
return (GetDebit(filter) > 0); return (GetDebit(filter) > 0);
@ -973,8 +970,6 @@ public:
std::set< std::set<CTxDestination> > GetAddressGroupings(); std::set< std::set<CTxDestination> > GetAddressGroupings();
std::map<CTxDestination, CAmount> GetAddressBalances(); std::map<CTxDestination, CAmount> GetAddressBalances();
CAmount GetAccountBalance(const std::string& strAccount, int nMinDepth, const isminefilter& filter);
CAmount GetAccountBalance(CWalletDB& walletdb, const std::string& strAccount, int nMinDepth, const isminefilter& filter);
std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const; std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const;
isminetype IsMine(const CTxIn& txin) const; isminetype IsMine(const CTxIn& txin) const;

Loading…
Cancel
Save