diff options
| author | Alan Westbrook <[email protected]> | 2014-04-05 00:09:56 -0700 |
|---|---|---|
| committer | Alan Westbrook <[email protected]> | 2014-04-05 00:17:09 -0700 |
| commit | 30053cfaa3a8ce403438b26638d1d9aacfe3e7ae (patch) | |
| tree | 8832547e83917de811cc0d378a68205efa0b30b3 /src/wallet.cpp | |
| parent | Merge pull request #417 from leofidus/1.7-uritests (diff) | |
| download | discoin-30053cfaa3a8ce403438b26638d1d9aacfe3e7ae.tar.xz discoin-30053cfaa3a8ce403438b26638d1d9aacfe3e7ae.zip | |
Lets get at least dogecoind building
This is an Xcode project and a script to wrangle boost to work on the
mac.
Diffstat (limited to 'src/wallet.cpp')
| -rw-r--r-- | src/wallet.cpp | 112 |
1 files changed, 111 insertions, 1 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp index 5dd2cdafd..fb9c61f7c 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -686,6 +686,116 @@ bool CWallet::IsChange(const CTxOut& txout) const return false; } +#pragma mark - CWalletTx + +bool CWalletTx::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()) // 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)) + return false; + } + return true; +} + +int64_t CWalletTx::GetAvailableCredit(bool fUseCache) 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; + + int64_t 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); + if (!MoneyRange(nCredit)) + throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range"); + } + } + + nAvailableCreditCached = nCredit; + fAvailableCreditCached = true; + return nCredit; +} + + +int64_t CWalletTx::GetChange() const +{ + if (fChangeCached) + return nChangeCached; + nChangeCached = pwallet->GetChange(*this); + fChangeCached = true; + return nChangeCached; +} + + +int64_t CWalletTx::GetCredit(bool fUseCache) const +{ + // Must wait until coinbase is safely deep enough in the chain before valuing it + if (IsCoinBase() && GetBlocksToMaturity() > 0) + return 0; + + // GetBalance can assume transactions in mapWallet won't change + if (fUseCache && fCreditCached) + return nCreditCached; + nCreditCached = pwallet->GetCredit(*this); + fCreditCached = true; + return nCreditCached; +} + +int64_t CWalletTx::GetImmatureCredit(bool fUseCache) const +{ + if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) + { + if (fUseCache && fImmatureCreditCached) + return nImmatureCreditCached; + nImmatureCreditCached = pwallet->GetCredit(*this); + fImmatureCreditCached = true; + return nImmatureCreditCached; + } + + return 0; +} + +int64_t CWalletTx::GetDebit() const +{ + if (vin.empty()) + return 0; + if (fDebitCached) + return nDebitCached; + nDebitCached = pwallet->GetDebit(*this); + fDebitCached = true; + return nDebitCached; +} + + int64_t CWalletTx::GetTxTime() const { int64_t n = nTimeSmart; @@ -1630,7 +1740,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize) if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) throw runtime_error("TopUpKeyPool() : writing generated key failed"); setKeyPool.insert(nEnd); - LogPrintf("keypool added key %d, size=%"PRIszu"\n", nEnd, setKeyPool.size()); + LogPrintf("keypool added key %d, size=%" PRIszu"\n", nEnd, setKeyPool.size()); } } return true; |