Line data Source code
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 280785 : CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize) 14 : { 15 280785 : if (nSize > 0) 16 280785 : nSatoshisPerK = nFeePaid * 1000 / nSize; 17 : else 18 0 : nSatoshisPerK = 0; 19 280785 : } 20 : 21 1387661 : CAmount CFeeRate::GetFee(size_t nSize) const 22 : { 23 1387661 : CAmount nFee = nSatoshisPerK * nSize / 1000; 24 : 25 1387661 : if (nFee == 0 && nSatoshisPerK > 0) 26 0 : nFee = nSatoshisPerK; 27 : 28 1387661 : return nFee; 29 : } 30 : 31 2 : std::string CFeeRate::ToString() const 32 : { 33 2 : return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT); 34 : }