aboutsummaryrefslogtreecommitdiff
path: root/src/core.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core.h')
-rw-r--r--src/core.h40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/core.h b/src/core.h
index ba7f691119..0e59129349 100644
--- a/src/core.h
+++ b/src/core.h
@@ -112,6 +112,31 @@ public:
+/** Type-safe wrapper class to for fee rates
+ * (how much to pay based on transaction size)
+ */
+class CFeeRate
+{
+private:
+ int64_t nSatoshisPerK; // unit is satoshis-per-1,000-bytes
+public:
+ CFeeRate() : nSatoshisPerK(0) { }
+ explicit CFeeRate(int64_t _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
+ CFeeRate(int64_t nFeePaid, size_t nSize);
+ CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
+
+ int64_t GetFee(size_t size); // unit returned is satoshis
+ int64_t GetFeePerK() { return GetFee(1000); } // satoshis-per-1000-bytes
+
+ friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
+ friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
+ friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
+
+ std::string ToString() const;
+
+ IMPLEMENT_SERIALIZE( READWRITE(nSatoshisPerK); )
+};
+
/** An output of a transaction. It contains the public key that the next input
* must be able to sign with to claim it.
@@ -148,17 +173,18 @@ public:
uint256 GetHash() const;
- bool IsDust(int64_t nMinRelayTxFee) const
+ bool IsDust(CFeeRate minRelayTxFee) const
{
- // "Dust" is defined in terms of CTransaction::nMinRelayTxFee,
+ // "Dust" is defined in terms of CTransaction::minRelayTxFee,
// which has units satoshis-per-kilobyte.
// If you'd pay more than 1/3 in fees
// to spend something, then we consider it dust.
// A typical txout is 34 bytes big, and will
- // need a CTxIn of at least 148 bytes to spend,
+ // need a CTxIn of at least 148 bytes to spend:
// so dust is a txout less than 546 satoshis
- // with default nMinRelayTxFee.
- return ((nValue*1000)/(3*((int)GetSerializeSize(SER_DISK,0)+148)) < nMinRelayTxFee);
+ // with default minRelayTxFee.
+ size_t nSize = GetSerializeSize(SER_DISK,0)+148u;
+ return (nValue < 3*minRelayTxFee.GetFee(nSize));
}
friend bool operator==(const CTxOut& a, const CTxOut& b)
@@ -183,8 +209,8 @@ public:
class CTransaction
{
public:
- static int64_t nMinTxFee;
- static int64_t nMinRelayTxFee;
+ static CFeeRate minTxFee;
+ static CFeeRate minRelayTxFee;
static const int CURRENT_VERSION=1;
int nVersion;
std::vector<CTxIn> vin;