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.cpp 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2016 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. #include "feerate.h"
  6. #include "tinyformat.h"
  7. const std::string CURRENCY_UNIT = "MAI";
  8. CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
  9. {
  10. assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
  11. int64_t nSize = int64_t(nBytes_);
  12. if (nSize > 0)
  13. nSatoshisPerK = nFeePaid * 1000 / nSize;
  14. else
  15. nSatoshisPerK = 0;
  16. }
  17. CAmount CFeeRate::GetFee(size_t nBytes_) const
  18. {
  19. assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
  20. int64_t nSize = int64_t(nBytes_);
  21. CAmount nFee = nSatoshisPerK * nSize / 1000;
  22. if (nFee == 0 && nSize != 0) {
  23. if (nSatoshisPerK > 0)
  24. nFee = CAmount(1);
  25. if (nSatoshisPerK < 0)
  26. nFee = CAmount(-1);
  27. }
  28. return nFee;
  29. }
  30. std::string CFeeRate::ToString() const
  31. {
  32. return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
  33. }