Raven Core  3.0.0
P2P Digital Currency
feerate.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "feerate.h"
8 
9 #include "tinyformat.h"
10 
11 const std::string CURRENCY_UNIT = "RVN";
12 
13 CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
14 {
15  assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
16  int64_t nSize = int64_t(nBytes_);
17 
18  if (nSize > 0)
19  nSatoshisPerK = nFeePaid * 1000 / nSize;
20  else
21  nSatoshisPerK = 0;
22 }
23 
24 CAmount CFeeRate::GetFee(size_t nBytes_) const
25 {
26  assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
27  int64_t nSize = int64_t(nBytes_);
28 
29  CAmount nFee = nSatoshisPerK * nSize / 1000;
30 
31  if (nFee == 0 && nSize != 0) {
32  if (nSatoshisPerK > 0)
33  nFee = CAmount(1);
34  if (nSatoshisPerK < 0)
35  nFee = CAmount(-1);
36  }
37 
38  return nFee;
39 }
40 
41 std::string CFeeRate::ToString() const
42 {
43  return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
44 }
#define strprintf
Definition: tinyformat.h:1054
const std::string CURRENCY_UNIT
Definition: feerate.cpp:11
CAmount nSatoshisPerK
Definition: feerate.h:23
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
CFeeRate()
Fee rate of 0 satoshis per kB.
Definition: feerate.h:27
std::string ToString() const
Definition: feerate.cpp:41
CAmount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
Definition: feerate.cpp:24