Merge #9226: Remove fNetworkNode and pnodeLocalHost.
[bitcoinplatinum.git] / src / amount.cpp
blob7b8618de332a68c79c9a966ae4a02631c3e0f6c7
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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 "amount.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);