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