Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,602 Lines • ▼ Show 20 Lines | if (IsCoinBase()) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return nRequests; | return nRequests; | ||||
} | } | ||||
void CWalletTx::GetAmounts(std::list<COutputEntry> &listReceived, | void CWalletTx::GetAmounts(std::list<COutputEntry> &listReceived, | ||||
std::list<COutputEntry> &listSent, CAmount &nFee, | std::list<COutputEntry> &listSent, Amount &nFee, | ||||
std::string &strSentAccount, | std::string &strSentAccount, | ||||
const isminefilter &filter) const { | const isminefilter &filter) const { | ||||
nFee = 0; | nFee = 0; | ||||
listReceived.clear(); | listReceived.clear(); | ||||
listSent.clear(); | listSent.clear(); | ||||
strSentAccount = strFromAccount; | strSentAccount = strFromAccount; | ||||
// Compute fee: | // Compute fee: | ||||
Amount nDebit = GetDebit(filter); | Amount nDebit = GetDebit(filter); | ||||
// debit>0 means we signed/sent this transaction. | // debit>0 means we signed/sent this transaction. | ||||
if (nDebit > 0) { | if (nDebit > 0) { | ||||
Amount nValueOut = tx->GetValueOut(); | Amount nValueOut = tx->GetValueOut(); | ||||
nFee = (nDebit - nValueOut).GetSatoshis(); | nFee = (nDebit - nValueOut); | ||||
} | } | ||||
// Sent/received. | // Sent/received. | ||||
for (unsigned int i = 0; i < tx->vout.size(); ++i) { | for (unsigned int i = 0; i < tx->vout.size(); ++i) { | ||||
const CTxOut &txout = tx->vout[i]; | const CTxOut &txout = tx->vout[i]; | ||||
isminetype fIsMine = pwallet->IsMine(txout); | isminetype fIsMine = pwallet->IsMine(txout); | ||||
// Only need to handle txouts if AT LEAST one of these is true: | // Only need to handle txouts if AT LEAST one of these is true: | ||||
// 1) they debit from us (sent) | // 1) they debit from us (sent) | ||||
Show All 29 Lines | for (unsigned int i = 0; i < tx->vout.size(); ++i) { | ||||
// If we are receiving the output, add it as a "received" entry. | // If we are receiving the output, add it as a "received" entry. | ||||
if (fIsMine & filter) { | if (fIsMine & filter) { | ||||
listReceived.push_back(output); | listReceived.push_back(output); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void CWalletTx::GetAccountAmounts(const std::string &strAccount, | void CWalletTx::GetAccountAmounts(const std::string &strAccount, | ||||
CAmount &nReceived, CAmount &nSent, | Amount &nReceived, Amount &nSent, | ||||
CAmount &nFee, | Amount &nFee, | ||||
const isminefilter &filter) const { | const isminefilter &filter) const { | ||||
nReceived = nSent = nFee = 0; | nReceived = nSent = nFee = 0; | ||||
CAmount allFee; | Amount allFee; | ||||
std::string strSentAccount; | std::string strSentAccount; | ||||
std::list<COutputEntry> listReceived; | std::list<COutputEntry> listReceived; | ||||
std::list<COutputEntry> listSent; | std::list<COutputEntry> listSent; | ||||
GetAmounts(listReceived, listSent, allFee, strSentAccount, filter); | GetAmounts(listReceived, listSent, allFee, strSentAccount, filter); | ||||
if (strAccount == strSentAccount) { | if (strAccount == strSentAccount) { | ||||
for (const COutputEntry &s : listSent) { | for (const COutputEntry &s : listSent) { | ||||
nSent += s.amount; | nSent += s.amount; | ||||
▲ Show 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { | ||||
pwallet->GetCredit(*this, ISMINE_SPENDABLE).GetSatoshis(); | pwallet->GetCredit(*this, ISMINE_SPENDABLE).GetSatoshis(); | ||||
fImmatureCreditCached = true; | fImmatureCreditCached = true; | ||||
return nImmatureCreditCached; | return nImmatureCreditCached; | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const { | Amount CWalletTx::GetAvailableCredit(bool fUseCache) const { | ||||
if (pwallet == 0) { | if (pwallet == 0) { | ||||
return 0; | return 0; | ||||
} | } | ||||
// Must wait until coinbase is safely deep enough in the chain before | // Must wait until coinbase is safely deep enough in the chain before | ||||
// valuing it. | // valuing it. | ||||
if (IsCoinBase() && GetBlocksToMaturity() > 0) { | if (IsCoinBase() && GetBlocksToMaturity() > 0) { | ||||
return 0; | return 0; | ||||
} | } | ||||
if (fUseCache && fAvailableCreditCached) { | if (fUseCache && fAvailableCreditCached) { | ||||
return nAvailableCreditCached; | return nAvailableCreditCached; | ||||
} | } | ||||
CAmount nCredit = 0; | Amount nCredit = 0; | ||||
uint256 hashTx = GetId(); | uint256 hashTx = GetId(); | ||||
for (unsigned int i = 0; i < tx->vout.size(); i++) { | for (unsigned int i = 0; i < tx->vout.size(); i++) { | ||||
if (!pwallet->IsSpent(hashTx, i)) { | if (!pwallet->IsSpent(hashTx, i)) { | ||||
const CTxOut &txout = tx->vout[i]; | const CTxOut &txout = tx->vout[i]; | ||||
nCredit += | nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE); | ||||
pwallet->GetCredit(txout, ISMINE_SPENDABLE).GetSatoshis(); | |||||
if (!MoneyRange(nCredit)) { | if (!MoneyRange(nCredit)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"CWalletTx::GetAvailableCredit() : value out of range"); | "CWalletTx::GetAvailableCredit() : value out of range"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
nAvailableCreditCached = nCredit; | nAvailableCreditCached = nCredit; | ||||
fAvailableCreditCached = true; | fAvailableCreditCached = true; | ||||
return nCredit; | return nCredit; | ||||
} | } | ||||
CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool &fUseCache) const { | Amount CWalletTx::GetImmatureWatchOnlyCredit(const bool &fUseCache) const { | ||||
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { | if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { | ||||
if (fUseCache && fImmatureWatchCreditCached) { | if (fUseCache && fImmatureWatchCreditCached) { | ||||
return nImmatureWatchCreditCached; | return nImmatureWatchCreditCached; | ||||
} | } | ||||
nImmatureWatchCreditCached = | nImmatureWatchCreditCached = | ||||
pwallet->GetCredit(*this, ISMINE_WATCH_ONLY).GetSatoshis(); | pwallet->GetCredit(*this, ISMINE_WATCH_ONLY).GetSatoshis(); | ||||
fImmatureWatchCreditCached = true; | fImmatureWatchCreditCached = true; | ||||
return nImmatureWatchCreditCached; | return nImmatureWatchCreditCached; | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
CAmount CWalletTx::GetAvailableWatchOnlyCredit(const bool &fUseCache) const { | Amount CWalletTx::GetAvailableWatchOnlyCredit(const bool &fUseCache) const { | ||||
if (pwallet == 0) { | if (pwallet == 0) { | ||||
return 0; | return 0; | ||||
} | } | ||||
// Must wait until coinbase is safely deep enough in the chain before | // Must wait until coinbase is safely deep enough in the chain before | ||||
// valuing it. | // valuing it. | ||||
if (IsCoinBase() && GetBlocksToMaturity() > 0) { | if (IsCoinBase() && GetBlocksToMaturity() > 0) { | ||||
return 0; | return 0; | ||||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* @defgroup Actions | * @defgroup Actions | ||||
* | * | ||||
* @{ | * @{ | ||||
*/ | */ | ||||
CAmount CWallet::GetBalance() const { | CAmount CWallet::GetBalance() const { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
CAmount nTotal = 0; | Amount nTotal = 0; | ||||
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const CWalletTx *pcoin = &(*it).second; | const CWalletTx *pcoin = &(*it).second; | ||||
if (pcoin->IsTrusted()) { | if (pcoin->IsTrusted()) { | ||||
nTotal += pcoin->GetAvailableCredit(); | nTotal += pcoin->GetAvailableCredit(); | ||||
} | } | ||||
} | } | ||||
return nTotal; | return nTotal.GetSatoshis(); | ||||
} | } | ||||
CAmount CWallet::GetUnconfirmedBalance() const { | CAmount CWallet::GetUnconfirmedBalance() const { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
CAmount nTotal = 0; | Amount nTotal = 0; | ||||
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const CWalletTx *pcoin = &(*it).second; | const CWalletTx *pcoin = &(*it).second; | ||||
if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && | if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && | ||||
pcoin->InMempool()) { | pcoin->InMempool()) { | ||||
nTotal += pcoin->GetAvailableCredit(); | nTotal += pcoin->GetAvailableCredit(); | ||||
} | } | ||||
} | } | ||||
return nTotal; | return nTotal.GetSatoshis(); | ||||
} | } | ||||
CAmount CWallet::GetImmatureBalance() const { | CAmount CWallet::GetImmatureBalance() const { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
Amount nTotal = 0; | Amount nTotal = 0; | ||||
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const CWalletTx *pcoin = &(*it).second; | const CWalletTx *pcoin = &(*it).second; | ||||
nTotal += pcoin->GetImmatureCredit(); | nTotal += pcoin->GetImmatureCredit(); | ||||
} | } | ||||
return nTotal.GetSatoshis(); | return nTotal.GetSatoshis(); | ||||
} | } | ||||
CAmount CWallet::GetWatchOnlyBalance() const { | CAmount CWallet::GetWatchOnlyBalance() const { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
CAmount nTotal = 0; | Amount nTotal = 0; | ||||
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const CWalletTx *pcoin = &(*it).second; | const CWalletTx *pcoin = &(*it).second; | ||||
if (pcoin->IsTrusted()) { | if (pcoin->IsTrusted()) { | ||||
nTotal += pcoin->GetAvailableWatchOnlyCredit(); | nTotal += pcoin->GetAvailableWatchOnlyCredit(); | ||||
} | } | ||||
} | } | ||||
return nTotal; | return nTotal.GetSatoshis(); | ||||
} | } | ||||
CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const { | CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
CAmount nTotal = 0; | Amount nTotal = 0; | ||||
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const CWalletTx *pcoin = &(*it).second; | const CWalletTx *pcoin = &(*it).second; | ||||
if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && | if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && | ||||
pcoin->InMempool()) { | pcoin->InMempool()) { | ||||
nTotal += pcoin->GetAvailableWatchOnlyCredit(); | nTotal += pcoin->GetAvailableWatchOnlyCredit(); | ||||
} | } | ||||
} | } | ||||
return nTotal; | return nTotal.GetSatoshis(); | ||||
} | } | ||||
CAmount CWallet::GetImmatureWatchOnlyBalance() const { | CAmount CWallet::GetImmatureWatchOnlyBalance() const { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
CAmount nTotal = 0; | Amount nTotal = 0; | ||||
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const CWalletTx *pcoin = &(*it).second; | const CWalletTx *pcoin = &(*it).second; | ||||
nTotal += pcoin->GetImmatureWatchOnlyCredit(); | nTotal += pcoin->GetImmatureWatchOnlyCredit(); | ||||
} | } | ||||
return nTotal; | return nTotal.GetSatoshis(); | ||||
} | } | ||||
void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlyConfirmed, | void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlyConfirmed, | ||||
const CCoinControl *coinControl, | const CCoinControl *coinControl, | ||||
bool fIncludeZeroValue) const { | bool fIncludeZeroValue) const { | ||||
vCoins.clear(); | vCoins.clear(); | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
▲ Show 20 Lines • Show All 1,372 Lines • ▼ Show 20 Lines | Amount CWallet::GetAccountBalance(CWalletDB &walletdb, | ||||
for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin(); | for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || | if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || | ||||
wtx.GetDepthInMainChain() < 0) { | wtx.GetDepthInMainChain() < 0) { | ||||
continue; | continue; | ||||
} | } | ||||
CAmount nReceived, nSent, nFee; | Amount nReceived, nSent, nFee; | ||||
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter); | wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter); | ||||
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth) { | if (nReceived != Amount(0) && wtx.GetDepthInMainChain() >= nMinDepth) { | ||||
nBalance += nReceived; | nBalance += nReceived; | ||||
} | } | ||||
nBalance -= nSent + nFee; | nBalance -= nSent + nFee; | ||||
} | } | ||||
// Tally internal accounting entries. | // Tally internal accounting entries. | ||||
nBalance += walletdb.GetAccountCreditDebit(strAccount); | nBalance += walletdb.GetAccountCreditDebit(strAccount); | ||||
▲ Show 20 Lines • Show All 870 Lines • Show Last 20 Lines |