refactor: Make CFeeRate constructor architecture-independent

This commit is contained in:
MarcoFalke
2021-05-04 10:14:12 +02:00
parent c857148636
commit fafd121026
4 changed files with 16 additions and 22 deletions

View File

@@ -7,29 +7,26 @@
#include <tinyformat.h>
CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes)
{
assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
int64_t nSize = int64_t(nBytes_);
const int64_t nSize{num_bytes};
if (nSize > 0)
if (nSize > 0) {
nSatoshisPerK = nFeePaid * 1000 / nSize;
else
} else {
nSatoshisPerK = 0;
}
}
CAmount CFeeRate::GetFee(size_t nBytes_) const
CAmount CFeeRate::GetFee(uint32_t num_bytes) const
{
assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
int64_t nSize = int64_t(nBytes_);
const int64_t nSize{num_bytes};
CAmount nFee = nSatoshisPerK * nSize / 1000;
if (nFee == 0 && nSize != 0) {
if (nSatoshisPerK > 0)
nFee = CAmount(1);
if (nSatoshisPerK < 0)
nFee = CAmount(-1);
if (nSatoshisPerK > 0) nFee = CAmount(1);
if (nSatoshisPerK < 0) nFee = CAmount(-1);
}
return nFee;