Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/policy/feerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
nSatoshisPerK = 0;
}

CAmount CFeeRate::GetFee(size_t nBytes_) const
CAmount CFeeRate::GetTruncatedFee(size_t bytes) const
{
assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
int64_t nSize = int64_t(nBytes_);
assert(bytes <= uint64_t(std::numeric_limits<int64_t>::max()));
return nSatoshisPerK * int64_t(bytes) / 1000;
}

CAmount nFee = nSatoshisPerK * nSize / 1000;
CAmount CFeeRate::GetFee(size_t bytes) const
{
CAmount nFee = GetTruncatedFee(bytes);

if (nFee == 0 && nSize != 0) {
if (nFee == 0 && bytes != 0) {
if (nSatoshisPerK > 0)
nFee = CAmount(1);
if (nSatoshisPerK < 0)
nFee = CAmount(-1);
}

return nFee;
}

Expand Down
7 changes: 6 additions & 1 deletion src/policy/feerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ class CFeeRate
/**
* Return the fee in satoshis for the given size in bytes.
*/
CAmount GetFee(size_t nBytes) const;
CAmount GetTruncatedFee(size_t bytes) const;
/**
* Return the fee in satoshis for the given size in bytes. If the
* result is zero, return 1 if the fee was positive or -1 if was negative.
*/
CAmount GetFee(size_t bytes) const;
/**
* Return the fee in satoshis for a size of 1000 bytes
*/
Expand Down
Loading