mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Move GetAccountBalance from rpcwallet.cpp into CWallet::GetAccountBalance
This commit is contained in:
parent
b3e42b6d02
commit
ecb9741ec3
@ -673,38 +673,6 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter)
|
|
||||||
{
|
|
||||||
CAmount nBalance = 0;
|
|
||||||
|
|
||||||
// Tally wallet transactions
|
|
||||||
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->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;
|
|
||||||
}
|
|
||||||
|
|
||||||
CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter)
|
|
||||||
{
|
|
||||||
CWalletDB walletdb(pwalletMain->strWalletFile);
|
|
||||||
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UniValue getbalance(const UniValue& params, bool fHelp)
|
UniValue getbalance(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (!EnsureWalletIsAvailable(fHelp))
|
if (!EnsureWalletIsAvailable(fHelp))
|
||||||
@ -775,7 +743,7 @@ UniValue getbalance(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
string strAccount = AccountFromValue(params[0]);
|
string strAccount = AccountFromValue(params[0]);
|
||||||
|
|
||||||
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
|
CAmount nBalance = pwalletMain->GetAccountBalance(strAccount, nMinDepth, filter);
|
||||||
|
|
||||||
return ValueFromAmount(nBalance);
|
return ValueFromAmount(nBalance);
|
||||||
}
|
}
|
||||||
@ -923,7 +891,7 @@ UniValue sendfrom(const UniValue& params, bool fHelp)
|
|||||||
EnsureWalletIsUnlocked();
|
EnsureWalletIsUnlocked();
|
||||||
|
|
||||||
// Check funds
|
// Check funds
|
||||||
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
|
CAmount nBalance = pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
|
||||||
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");
|
||||||
|
|
||||||
@ -1026,7 +994,7 @@ UniValue sendmany(const UniValue& params, bool fHelp)
|
|||||||
EnsureWalletIsUnlocked();
|
EnsureWalletIsUnlocked();
|
||||||
|
|
||||||
// Check funds
|
// Check funds
|
||||||
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
|
CAmount nBalance = pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
|
||||||
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");
|
||||||
|
|
||||||
|
@ -2759,6 +2759,37 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAmount CWallet::GetAccountBalance(const std::string& strAccount, int nMinDepth, const isminefilter& filter)
|
||||||
|
{
|
||||||
|
CWalletDB walletdb(strWalletFile);
|
||||||
|
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 (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);
|
||||||
|
@ -776,6 +776,8 @@ 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…
Reference in New Issue
Block a user