Skip to content

Commit

Permalink
Update feerate.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan authored Feb 28, 2024
1 parent bb186ef commit 3904bf5
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/policy/feerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@

CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes)
{
assert(num_bytes <= uint64_t(std::numeric_limits<int64_t>::max()));
int64_t nSize = int64_t(num_bytes);
const int64_t nSize{num_bytes};

if (nSize > 0) {
nSatoshisPerK = nFeePaid * 1000 / nSize;
} else {
nSatoshisPerK = 0;
}
}
}

CAmount CFeeRate::GetFee(uint32_t num_bytes) const
{
assert(num_bytes <= uint64_t(std::numeric_limits<int64_t>::max()));
int64_t nSize = int64_t(num_bytes);
const int64_t nSize{num_bytes};

CAmount nFee{static_cast<CAmount>(std::ceil(nSatoshisPerK * nSize / 1000.0))};

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;
}

Expand Down

0 comments on commit 3904bf5

Please sign in to comment.