Changeset View
Changeset View
Standalone View
Standalone View
src/amount.cpp
Show All 15 Lines | |||||
CFeeRate::CFeeRate(const Amount nFeePaid, size_t nBytes_) { | CFeeRate::CFeeRate(const Amount nFeePaid, size_t nBytes_) { | ||||
assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max())); | assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max())); | ||||
int64_t nSize = int64_t(nBytes_); | int64_t nSize = int64_t(nBytes_); | ||||
if (nSize > 0) { | if (nSize > 0) { | ||||
nSatoshisPerK = 1000 * nFeePaid / nSize; | nSatoshisPerK = 1000 * nFeePaid / nSize; | ||||
} else { | } else { | ||||
nSatoshisPerK = 0; | nSatoshisPerK = Amount(0); | ||||
} | } | ||||
} | } | ||||
Amount CFeeRate::GetFee(size_t nBytes_) const { | Amount CFeeRate::GetFee(size_t nBytes_) const { | ||||
assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max())); | assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max())); | ||||
int64_t nSize = int64_t(nBytes_); | int64_t nSize = int64_t(nBytes_); | ||||
Amount nFee = nSize * nSatoshisPerK / 1000; | Amount nFee = nSize * nSatoshisPerK / 1000; | ||||
if (nFee == 0 && nSize != 0) { | if (nFee == Amount(0) && nSize != 0) { | ||||
if (nSatoshisPerK > 0) { | if (nSatoshisPerK > Amount(0)) { | ||||
nFee = Amount(1); | nFee = Amount(1); | ||||
} | } | ||||
if (nSatoshisPerK < 0) { | if (nSatoshisPerK < Amount(0)) { | ||||
nFee = Amount(-1); | nFee = Amount(-1); | ||||
} | } | ||||
} | } | ||||
return nFee; | return nFee; | ||||
} | } | ||||
std::string CFeeRate::ToString() const { | std::string CFeeRate::ToString() const { | ||||
return strprintf( | return strprintf( | ||||
"%d.%08d %s/kB", nSatoshisPerK.GetSatoshis() / COIN.GetSatoshis(), | "%d.%08d %s/kB", nSatoshisPerK.GetSatoshis() / COIN.GetSatoshis(), | ||||
nSatoshisPerK.GetSatoshis() % COIN.GetSatoshis(), CURRENCY_UNIT); | nSatoshisPerK.GetSatoshis() % COIN.GetSatoshis(), CURRENCY_UNIT); | ||||
} | } |