Line data Source code
1 : // Copyright (c) 2009-2010 Satoshi Nakamoto
2 : // Copyright (c) 2009-2014 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 "amount.h"
7 :
8 : #include "tinyformat.h"
9 :
10 192 : const std::string CURRENCY_UNIT = "BTC";
11 :
12 32912 : CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
13 : {
14 32912 : if (nSize > 0)
15 32912 : nSatoshisPerK = nFeePaid*1000/nSize;
16 : else
17 0 : nSatoshisPerK = 0;
18 32912 : }
19 :
20 29285 : CAmount CFeeRate::GetFee(size_t nSize) const
21 : {
22 29285 : CAmount nFee = nSatoshisPerK*nSize / 1000;
23 :
24 29285 : if (nFee == 0 && nSatoshisPerK > 0)
25 0 : nFee = nSatoshisPerK;
26 :
27 29285 : return nFee;
28 : }
29 :
30 0 : std::string CFeeRate::ToString() const
31 : {
32 0 : return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
33 288 : }
|