PIVX Core  5.6.99
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 developers
3 // Copyright (c) 2017-2020 The PIVX 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 = "PIV";
12 
13 CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
14 {
15  if (nSize > 0)
16  nSatoshisPerK = nFeePaid * 1000 / nSize;
17  else
18  nSatoshisPerK = 0;
19 }
20 
21 CAmount CFeeRate::GetFee(size_t nSize) const
22 {
23  CAmount nFee = nSatoshisPerK * nSize / 1000;
24 
25  if (nFee == 0 && nSatoshisPerK > 0)
26  nFee = nSatoshisPerK;
27 
28  return nFee;
29 }
30 
31 std::string CFeeRate::ToString() const
32 {
33  return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
34 }
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
std::string ToString() const
Definition: feerate.cpp:31
CAmount GetFee(size_t size) const
Definition: feerate.cpp:21
CAmount nSatoshisPerK
Definition: feerate.h:22
CFeeRate()
Definition: feerate.h:24
const std::string CURRENCY_UNIT
Definition: feerate.cpp:11
#define strprintf
Definition: tinyformat.h:1056