Merge #11886: Clarify getbalance meaning a tiny bit in response to questions.
[bitcoinplatinum.git] / src / policy / feerate.cpp
blob26c44ee0cf11a129e59ccc23a2b63c7eaba1ed0e
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_);
17 if (nSize > 0)
18 nSatoshisPerK = nFeePaid * 1000 / nSize;
19 else
20 nSatoshisPerK = 0;
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)
32 nFee = CAmount(1);
33 if (nSatoshisPerK < 0)
34 nFee = CAmount(-1);
37 return nFee;
40 std::string CFeeRate::ToString() const
42 return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);