Branch data Line data Source code
# 1 : : // Copyright (c) 2009-2010 Satoshi Nakamoto # 2 : : // Copyright (c) 2009-2020 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 <policy/feerate.h> # 7 : : # 8 : : #include <tinyformat.h> # 9 : : # 10 : : CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes) # 11 : 134470 : { # 12 : 134470 : const int64_t nSize{num_bytes}; # 13 : : # 14 [ + + ]: 134470 : if (nSize > 0) { # 15 : 134464 : nSatoshisPerK = nFeePaid * 1000 / nSize; # 16 : 134464 : } else { # 17 : 6 : nSatoshisPerK = 0; # 18 : 6 : } # 19 : 134470 : } # 20 : : # 21 : : CAmount CFeeRate::GetFee(uint32_t num_bytes) const # 22 : 2864814 : { # 23 : 2864814 : const int64_t nSize{num_bytes}; # 24 : : # 25 : 2864814 : CAmount nFee = nSatoshisPerK * nSize / 1000; # 26 : : # 27 [ + + ][ + + ]: 2864814 : if (nFee == 0 && nSize != 0) { # 28 [ + + ]: 404822 : if (nSatoshisPerK > 0) nFee = CAmount(1); # 29 [ + + ]: 404822 : if (nSatoshisPerK < 0) nFee = CAmount(-1); # 30 : 404822 : } # 31 : : # 32 : 2864814 : return nFee; # 33 : 2864814 : } # 34 : : # 35 : : std::string CFeeRate::ToString(const FeeEstimateMode& fee_estimate_mode) const # 36 : 3966 : { # 37 : 3966 : switch (fee_estimate_mode) { # 38 [ + + ]: 2972 : case FeeEstimateMode::SAT_VB: return strprintf("%d.%03d %s/vB", nSatoshisPerK / 1000, nSatoshisPerK % 1000, CURRENCY_ATOM); # 39 [ + + ]: 994 : default: return strprintf("%d.%08d %s/kvB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT); # 40 : 3966 : } # 41 : 3966 : }