You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

feerate.h 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2015 The Starwels developers
  3. // Distributed under the MIT software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef STARWELS_POLICY_FEERATE_H
  6. #define STARWELS_POLICY_FEERATE_H
  7. #include "amount.h"
  8. #include "serialize.h"
  9. #include <string>
  10. extern const std::string CURRENCY_UNIT;
  11. /**
  12. * Fee rate in satoshis per kilobyte: CAmount / kB
  13. */
  14. class CFeeRate
  15. {
  16. private:
  17. CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
  18. public:
  19. /** Fee rate of 0 satoshis per kB */
  20. CFeeRate() : nSatoshisPerK(0) { }
  21. explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
  22. /** Constructor for a fee rate in satoshis per kB. The size in bytes must not exceed (2^63 - 1)*/
  23. CFeeRate(const CAmount& nFeePaid, size_t nBytes);
  24. CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
  25. /**
  26. * Return the fee in satoshis for the given size in bytes.
  27. */
  28. CAmount GetFee(size_t nBytes) const;
  29. /**
  30. * Return the fee in satoshis for a size of 1000 bytes
  31. */
  32. CAmount GetFeePerK() const { return GetFee(1000); }
  33. friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
  34. friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
  35. friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
  36. friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
  37. friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
  38. friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
  39. CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
  40. std::string ToString() const;
  41. ADD_SERIALIZE_METHODS;
  42. template <typename Stream, typename Operation>
  43. inline void SerializationOp(Stream& s, Operation ser_action) {
  44. READWRITE(nSatoshisPerK);
  45. }
  46. };
  47. #endif // STARWELS_POLICY_FEERATE_H