From 788536f1755c6a9ea81394a2199ca27c9e90944e Mon Sep 17 00:00:00 2001 From: Eric Lombrozo Date: Tue, 8 Jan 2013 03:42:22 -0800 Subject: [PATCH] Moved CInPoint to core. Removed GetMinFee from CTransaction and made it a regular function in main. --- src/core.h | 15 +++++++++++++++ src/main.cpp | 11 +++++------ src/main.h | 18 ++---------------- src/wallet.cpp | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/core.h b/src/core.h index 77bd8472e..bd1ddbf5a 100644 --- a/src/core.h +++ b/src/core.h @@ -11,6 +11,8 @@ #include +class CTransaction; + /** An outpoint - a combination of a transaction hash and an index n into its vout */ class COutPoint { @@ -50,4 +52,17 @@ public: } }; +/** An inpoint - a combination of a transaction and an index n into its vin */ +class CInPoint +{ +public: + CTransaction* ptx; + unsigned int n; + + CInPoint() { SetNull(); } + CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; } + void SetNull() { ptx = NULL; n = (unsigned int) -1; } + bool IsNull() const { return (ptx == NULL && n == (unsigned int) -1); } +}; + #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 65ae78a13..5a1345d41 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -591,13 +591,12 @@ bool CTransaction::CheckTransaction(CValidationState &state) const return true; } -int64 CTransaction::GetMinFee(unsigned int nBlockSize, bool fAllowFree, - enum GetMinFee_mode mode) const +int64 GetMinFee(const CTransaction& tx, unsigned int nBlockSize, bool fAllowFree, enum GetMinFee_mode mode) { // Base fee is either nMinTxFee or nMinRelayTxFee - int64 nBaseFee = (mode == GMF_RELAY) ? nMinRelayTxFee : nMinTxFee; + int64 nBaseFee = (mode == GMF_RELAY) ? tx.nMinRelayTxFee : tx.nMinTxFee; - unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION); + unsigned int nBytes = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); unsigned int nNewBlockSize = nBlockSize + nBytes; int64 nMinFee = (1 + (int64)nBytes / 1000) * nBaseFee; @@ -621,7 +620,7 @@ int64 CTransaction::GetMinFee(unsigned int nBlockSize, bool fAllowFree, // To limit dust spam, require base fee if any output is less than 0.01 if (nMinFee < nBaseFee) { - BOOST_FOREACH(const CTxOut& txout, vout) + BOOST_FOREACH(const CTxOut& txout, tx.vout) if (txout.nValue < CENT) nMinFee = nBaseFee; } @@ -757,7 +756,7 @@ bool CTxMemPool::accept(CValidationState &state, CTransaction &tx, bool fCheckIn unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); // Don't accept it if it can't get into a block - int64 txMinFee = tx.GetMinFee(1000, true, GMF_RELAY); + int64 txMinFee = GetMinFee(tx, 1000, true, GMF_RELAY); if (fLimitFree && nFees < txMinFee) return error("CTxMemPool::accept() : not enough fees %s, %"PRI64d" < %"PRI64d, hash.ToString().c_str(), diff --git a/src/main.h b/src/main.h index 099e436d9..c3c7ee396 100644 --- a/src/main.h +++ b/src/main.h @@ -253,20 +253,6 @@ struct CDiskTxPos : public CDiskBlockPos }; -/** An inpoint - a combination of a transaction and an index n into its vin */ -class CInPoint -{ -public: - CTransaction* ptx; - unsigned int n; - - CInPoint() { SetNull(); } - CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; } - void SetNull() { ptx = NULL; n = (unsigned int) -1; } - bool IsNull() const { return (ptx == NULL && n == (unsigned int) -1); } -}; - - /** An input of a transaction. It contains the location of the previous @@ -424,6 +410,8 @@ enum GetMinFee_mode GMF_SEND, }; +int64 GetMinFee(const CTransaction& tx, unsigned int nBlockSize = 1, bool fAllowFree = true, enum GetMinFee_mode mode = GMF_BLOCK); + /** The basic transaction that is broadcasted on the network and contained in * blocks. A transaction can contain multiple inputs and outputs. */ @@ -575,8 +563,6 @@ public: return dPriority > COIN * 144 / 250; } - int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true, enum GetMinFee_mode mode=GMF_BLOCK) const; - friend bool operator==(const CTransaction& a, const CTransaction& b) { return (a.nVersion == b.nVersion && diff --git a/src/wallet.cpp b/src/wallet.cpp index 549d9bbf4..da75752bb 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1277,7 +1277,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, // Check that enough fee is included int64 nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000); bool fAllowFree = CTransaction::AllowFree(dPriority); - int64 nMinFee = wtxNew.GetMinFee(1, fAllowFree, GMF_SEND); + int64 nMinFee = GetMinFee(wtxNew, 1, fAllowFree, GMF_SEND); if (nFeeRet < max(nPayFee, nMinFee)) { nFeeRet = max(nPayFee, nMinFee);