|
|
|
@ -705,165 +705,13 @@ public:
@@ -705,165 +705,13 @@ public:
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//! filter decides which addresses will count towards the debit
|
|
|
|
|
CAmount GetDebit(const isminefilter& filter) const |
|
|
|
|
{ |
|
|
|
|
if (vin.empty()) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
CAmount debit = 0; |
|
|
|
|
if(filter & ISMINE_SPENDABLE) |
|
|
|
|
{ |
|
|
|
|
if (fDebitCached) |
|
|
|
|
debit += nDebitCached; |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
nDebitCached = pwallet->GetDebit(*this, ISMINE_SPENDABLE); |
|
|
|
|
fDebitCached = true; |
|
|
|
|
debit += nDebitCached; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(filter & ISMINE_WATCH_ONLY) |
|
|
|
|
{ |
|
|
|
|
if(fWatchDebitCached) |
|
|
|
|
debit += nWatchDebitCached; |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
nWatchDebitCached = pwallet->GetDebit(*this, ISMINE_WATCH_ONLY); |
|
|
|
|
fWatchDebitCached = true; |
|
|
|
|
debit += nWatchDebitCached; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return debit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CAmount GetCredit(const isminefilter& filter) const |
|
|
|
|
{ |
|
|
|
|
// Must wait until coinbase is safely deep enough in the chain before valuing it
|
|
|
|
|
if (IsCoinBase() && GetBlocksToMaturity() > 0) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
int64_t credit = 0; |
|
|
|
|
if (filter & ISMINE_SPENDABLE) |
|
|
|
|
{ |
|
|
|
|
// GetBalance can assume transactions in mapWallet won't change
|
|
|
|
|
if (fCreditCached) |
|
|
|
|
credit += nCreditCached; |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
nCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE); |
|
|
|
|
fCreditCached = true; |
|
|
|
|
credit += nCreditCached; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (filter & ISMINE_WATCH_ONLY) |
|
|
|
|
{ |
|
|
|
|
if (fWatchCreditCached) |
|
|
|
|
credit += nWatchCreditCached; |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
nWatchCreditCached = pwallet->GetCredit(*this, ISMINE_WATCH_ONLY); |
|
|
|
|
fWatchCreditCached = true; |
|
|
|
|
credit += nWatchCreditCached; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return credit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CAmount GetImmatureCredit(bool fUseCache=true) const |
|
|
|
|
{ |
|
|
|
|
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) |
|
|
|
|
{ |
|
|
|
|
if (fUseCache && fImmatureCreditCached) |
|
|
|
|
return nImmatureCreditCached; |
|
|
|
|
nImmatureCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE); |
|
|
|
|
fImmatureCreditCached = true; |
|
|
|
|
return nImmatureCreditCached; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CAmount GetAvailableCredit(bool fUseCache=true) const |
|
|
|
|
{ |
|
|
|
|
if (pwallet == 0) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
// Must wait until coinbase is safely deep enough in the chain before valuing it
|
|
|
|
|
if (IsCoinBase() && GetBlocksToMaturity() > 0) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
if (fUseCache && fAvailableCreditCached) |
|
|
|
|
return nAvailableCreditCached; |
|
|
|
|
|
|
|
|
|
CAmount nCredit = 0; |
|
|
|
|
uint256 hashTx = GetHash(); |
|
|
|
|
for (unsigned int i = 0; i < vout.size(); i++) |
|
|
|
|
{ |
|
|
|
|
if (!pwallet->IsSpent(hashTx, i)) |
|
|
|
|
{ |
|
|
|
|
const CTxOut &txout = vout[i]; |
|
|
|
|
nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE); |
|
|
|
|
if (!MoneyRange(nCredit)) |
|
|
|
|
throw std::runtime_error("CWalletTx::GetAvailableCredit(): value out of range"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
nAvailableCreditCached = nCredit; |
|
|
|
|
fAvailableCreditCached = true; |
|
|
|
|
return nCredit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CAmount GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const |
|
|
|
|
{ |
|
|
|
|
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) |
|
|
|
|
{ |
|
|
|
|
if (fUseCache && fImmatureWatchCreditCached) |
|
|
|
|
return nImmatureWatchCreditCached; |
|
|
|
|
nImmatureWatchCreditCached = pwallet->GetCredit(*this, ISMINE_WATCH_ONLY); |
|
|
|
|
fImmatureWatchCreditCached = true; |
|
|
|
|
return nImmatureWatchCreditCached; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CAmount GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const |
|
|
|
|
{ |
|
|
|
|
if (pwallet == 0) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
// Must wait until coinbase is safely deep enough in the chain before valuing it
|
|
|
|
|
if (IsCoinBase() && GetBlocksToMaturity() > 0) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
if (fUseCache && fAvailableWatchCreditCached) |
|
|
|
|
return nAvailableWatchCreditCached; |
|
|
|
|
|
|
|
|
|
CAmount nCredit = 0; |
|
|
|
|
for (unsigned int i = 0; i < vout.size(); i++) |
|
|
|
|
{ |
|
|
|
|
if (!pwallet->IsSpent(GetHash(), i)) |
|
|
|
|
{ |
|
|
|
|
const CTxOut &txout = vout[i]; |
|
|
|
|
nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY); |
|
|
|
|
if (!MoneyRange(nCredit)) |
|
|
|
|
throw std::runtime_error("CWalletTx::GetAvailableCredit(): value out of range"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
nAvailableWatchCreditCached = nCredit; |
|
|
|
|
fAvailableWatchCreditCached = true; |
|
|
|
|
return nCredit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CAmount GetChange() const |
|
|
|
|
{ |
|
|
|
|
if (fChangeCached) |
|
|
|
|
return nChangeCached; |
|
|
|
|
nChangeCached = pwallet->GetChange(*this); |
|
|
|
|
fChangeCached = true; |
|
|
|
|
return nChangeCached; |
|
|
|
|
} |
|
|
|
|
CAmount GetDebit(const isminefilter& filter) const; |
|
|
|
|
CAmount GetCredit(const isminefilter& filter) const; |
|
|
|
|
CAmount GetImmatureCredit(bool fUseCache=true) const; |
|
|
|
|
CAmount GetAvailableCredit(bool fUseCache=true) const; |
|
|
|
|
CAmount GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const; |
|
|
|
|
CAmount GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const; |
|
|
|
|
CAmount GetChange() const; |
|
|
|
|
|
|
|
|
|
void GetAmounts(std::list<COutputEntry>& listReceived, |
|
|
|
|
std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const; |
|
|
|
@ -876,32 +724,7 @@ public:
@@ -876,32 +724,7 @@ public:
|
|
|
|
|
return (GetDebit(filter) > 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsTrusted() const |
|
|
|
|
{ |
|
|
|
|
// Quick answer in most cases
|
|
|
|
|
if (!IsFinalTx(*this)) |
|
|
|
|
return false; |
|
|
|
|
int nDepth = GetDepthInMainChain(); |
|
|
|
|
if (nDepth >= 1) |
|
|
|
|
return true; |
|
|
|
|
if (nDepth < 0) |
|
|
|
|
return false; |
|
|
|
|
if (!bSpendZeroConfChange || !IsFromMe(ISMINE_ALL)) // using wtx's cached debit
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
// Trusted if all inputs are from us and are in the mempool:
|
|
|
|
|
BOOST_FOREACH(const CTxIn& txin, vin) |
|
|
|
|
{ |
|
|
|
|
// Transactions not sent by us: not trusted
|
|
|
|
|
const CWalletTx* parent = pwallet->GetWalletTx(txin.prevout.hash); |
|
|
|
|
if (parent == NULL) |
|
|
|
|
return false; |
|
|
|
|
const CTxOut& parentOut = parent->vout[txin.prevout.n]; |
|
|
|
|
if (pwallet->IsMine(parentOut) != ISMINE_SPENDABLE) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
bool IsTrusted() const; |
|
|
|
|
|
|
|
|
|
bool WriteToDisk(CWalletDB *pwalletdb); |
|
|
|
|
|
|
|
|
|