1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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.
6 #include <policy/feerate.h>
8 #include <tinyformat.h>
10 const std::string CURRENCY_UNIT
= "BTC";
12 CFeeRate::CFeeRate(const CAmount
& nFeePaid
, size_t nBytes_
)
14 assert(nBytes_
<= uint64_t(std::numeric_limits
<int64_t>::max()));
15 int64_t nSize
= int64_t(nBytes_
);
18 nSatoshisPerK
= nFeePaid
* 1000 / nSize
;
23 CAmount
CFeeRate::GetFee(size_t nBytes_
) const
25 assert(nBytes_
<= uint64_t(std::numeric_limits
<int64_t>::max()));
26 int64_t nSize
= int64_t(nBytes_
);
28 CAmount nFee
= nSatoshisPerK
* nSize
/ 1000;
30 if (nFee
== 0 && nSize
!= 0) {
31 if (nSatoshisPerK
> 0)
33 if (nSatoshisPerK
< 0)
40 std::string
CFeeRate::ToString() const
42 return strprintf("%d.%08d %s/kB", nSatoshisPerK
/ COIN
, nSatoshisPerK
% COIN
, CURRENCY_UNIT
);