Changeset View
Changeset View
Standalone View
Standalone View
src/feerate.h
Show All 21 Lines | |||||
private: | private: | ||||
// unit is satoshis-per-1,000-bytes | // unit is satoshis-per-1,000-bytes | ||||
Amount nSatoshisPerK; | Amount nSatoshisPerK; | ||||
public: | public: | ||||
/** | /** | ||||
* Fee rate of 0 satoshis per kB. | * Fee rate of 0 satoshis per kB. | ||||
*/ | */ | ||||
CFeeRate() : nSatoshisPerK() {} | constexpr CFeeRate() : nSatoshisPerK() {} | ||||
explicit CFeeRate(const Amount _nSatoshisPerK) | explicit constexpr CFeeRate(const Amount _nSatoshisPerK) | ||||
: nSatoshisPerK(_nSatoshisPerK) {} | : nSatoshisPerK(_nSatoshisPerK) {} | ||||
/** | /** | ||||
* Constructor for a fee rate in satoshis per kB. The size in bytes must not | * Constructor for a fee rate in satoshis per kB. The size in bytes must not | ||||
* exceed (2^63 - 1) | * exceed (2^63 - 1) | ||||
*/ | */ | ||||
CFeeRate(const Amount nFeePaid, size_t nBytes); | CFeeRate(const Amount nFeePaid, size_t nBytes); | ||||
CFeeRate(const CFeeRate &other) { nSatoshisPerK = other.nSatoshisPerK; } | constexpr CFeeRate(const CFeeRate &other) | ||||
: nSatoshisPerK(other.nSatoshisPerK) {} | |||||
/** | /** | ||||
* Return the fee in satoshis for the given size in bytes. | * Return the fee in satoshis for the given size in bytes. | ||||
*/ | */ | ||||
Amount GetFee(size_t nBytes) const; | Amount GetFee(size_t nBytes) const; | ||||
/** | /** | ||||
* Return the ceiling of a fee calculation in satoshis for the given size in | * Return the ceiling of a fee calculation in satoshis for the given size in | ||||
* bytes. | * bytes. | ||||
*/ | */ | ||||
Amount GetFeeCeiling(size_t nBytes) const; | Amount GetFeeCeiling(size_t nBytes) const; | ||||
/** | /** | ||||
* Return the fee in satoshis for a size of 1000 bytes | * Return the fee in satoshis for a size of 1000 bytes | ||||
*/ | */ | ||||
Amount GetFeePerK() const { return GetFee(1000); } | Amount GetFeePerK() const { return GetFee(1000); } | ||||
/** | |||||
* Equality | |||||
*/ | |||||
friend constexpr bool operator==(const CFeeRate a, const CFeeRate b) { | |||||
return a.nSatoshisPerK == b.nSatoshisPerK; | |||||
} | |||||
friend constexpr bool operator!=(const CFeeRate a, const CFeeRate b) { | |||||
return !(a == b); | |||||
} | |||||
/** | |||||
* Comparison | |||||
*/ | |||||
friend bool operator<(const CFeeRate &a, const CFeeRate &b) { | friend bool operator<(const CFeeRate &a, const CFeeRate &b) { | ||||
return a.nSatoshisPerK < b.nSatoshisPerK; | return a.nSatoshisPerK < b.nSatoshisPerK; | ||||
} | } | ||||
friend bool operator>(const CFeeRate &a, const CFeeRate &b) { | friend bool operator>(const CFeeRate &a, const CFeeRate &b) { | ||||
return a.nSatoshisPerK > b.nSatoshisPerK; | 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) { | friend bool operator<=(const CFeeRate &a, const CFeeRate &b) { | ||||
return a.nSatoshisPerK <= b.nSatoshisPerK; | return a.nSatoshisPerK <= b.nSatoshisPerK; | ||||
} | } | ||||
friend bool operator>=(const CFeeRate &a, const CFeeRate &b) { | friend bool operator>=(const CFeeRate &a, const CFeeRate &b) { | ||||
return a.nSatoshisPerK >= b.nSatoshisPerK; | return a.nSatoshisPerK >= b.nSatoshisPerK; | ||||
} | } | ||||
CFeeRate &operator+=(const CFeeRate &a) { | CFeeRate &operator+=(const CFeeRate &a) { | ||||
nSatoshisPerK += a.nSatoshisPerK; | nSatoshisPerK += a.nSatoshisPerK; | ||||
Show All 13 Lines |