diff options
Diffstat (limited to 'main.h')
-rw-r--r-- | main.h | 100 |
1 files changed, 38 insertions, 62 deletions
@@ -469,44 +469,6 @@ public: return (vin.size() == 1 && vin[0].prevout.IsNull()); } - bool CheckTransaction() const - { - // Basic checks that don't depend on any context - if (vin.empty() || vout.empty()) - return error("CTransaction::CheckTransaction() : vin or vout empty"); - - // Size limits - if (::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE) - return error("CTransaction::CheckTransaction() : size limits failed"); - - // Check for negative or overflow output values - int64 nValueOut = 0; - foreach(const CTxOut& txout, vout) - { - if (txout.nValue < 0) - return error("CTransaction::CheckTransaction() : txout.nValue negative"); - if (txout.nValue > MAX_MONEY) - return error("CTransaction::CheckTransaction() : txout.nValue too high"); - nValueOut += txout.nValue; - if (!MoneyRange(nValueOut)) - return error("CTransaction::CheckTransaction() : txout total out of range"); - } - - if (IsCoinBase()) - { - if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100) - return error("CTransaction::CheckTransaction() : coinbase script size"); - } - else - { - foreach(const CTxIn& txin, vin) - if (txin.prevout.IsNull()) - return error("CTransaction::CheckTransaction() : prevout is null"); - } - - return true; - } - int GetSigOpCount() const { int n = 0; @@ -655,20 +617,17 @@ public: } - bool DisconnectInputs(CTxDB& txdb); bool ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx, CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee=0); bool ClientConnectInputs(); - + bool CheckTransaction() const; bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL); - bool AcceptToMemoryPool(bool fCheckInputs=true, bool* pfMissingInputs=NULL) { CTxDB txdb("r"); return AcceptToMemoryPool(txdb, fCheckInputs, pfMissingInputs); } - protected: bool AddToMemoryPoolUnchecked(); public: @@ -690,9 +649,7 @@ public: int nIndex; // memory only - mutable bool fMerkleVerified; - mutable bool fGetCreditCached; - mutable int64 nGetCreditCached; + mutable char fMerkleVerified; CMerkleTx() @@ -710,8 +667,6 @@ public: hashBlock = 0; nIndex = -1; fMerkleVerified = false; - fGetCreditCached = false; - nGetCreditCached = 0; } IMPLEMENT_SERIALIZE @@ -723,20 +678,6 @@ public: READWRITE(nIndex); ) - int64 GetCredit(bool fUseCache=false) 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 && fGetCreditCached) - return nGetCreditCached; - nGetCreditCached = CTransaction::GetCredit(); - fGetCreditCached = true; - return nGetCreditCached; - } - int SetMerkleBranch(const CBlock* pblock=NULL); int GetDepthInMainChain(int& nHeightRet) const; @@ -767,9 +708,16 @@ public: char fSpent; //// probably need to sign the order info so know it came from payer + // memory only + mutable char fDebitCached; + mutable char fCreditCached; + mutable int64 nDebitCached; + mutable int64 nCreditCached; + // memory only UI hints mutable unsigned int nTimeDisplayed; mutable int nLinesDisplayed; + mutable char fConfirmedDisplayed; CWalletTx() @@ -793,6 +741,10 @@ public: nTimeReceived = 0; fFromMe = false; fSpent = false; + fDebitCached = false; + fCreditCached = false; + nDebitCached = 0; + nCreditCached = 0; nTimeDisplayed = 0; nLinesDisplayed = 0; } @@ -810,6 +762,31 @@ public: READWRITE(fSpent); ) + int64 GetDebit() const + { + if (vin.empty()) + return 0; + if (fDebitCached) + return nDebitCached; + nDebitCached = CTransaction::GetDebit(); + fDebitCached = true; + return nDebitCached; + } + + int64 GetCredit(bool fUseCache=false) 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 = CTransaction::GetCredit(); + fCreditCached = true; + return nCreditCached; + } + bool WriteToDisk() { return CWalletDB().WriteTx(GetHash(), *this); @@ -1103,7 +1080,6 @@ public: } - int64 GetBlockValue(int nHeight, int64 nFees) const; bool DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex); bool ConnectBlock(CTxDB& txdb, CBlockIndex* pindex); bool ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions=true); |