aboutsummaryrefslogtreecommitdiff
path: root/src/amount.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2016-04-03 13:44:01 +0200
committerMarcoFalke <falke.marco@gmail.com>2016-04-08 19:59:53 +0200
commitfa2da2cb607ba359231fccc9635abe7c8616de56 (patch)
tree1b6ce7e9c2fa24ecf3e6e7d1a573027310249da3 /src/amount.cpp
parent11114a69c86e9abf4dd7e88ac268f5d078f40913 (diff)
downloadbitcoin-fa2da2cb607ba359231fccc9635abe7c8616de56.tar.xz
[amount] Add support for negative fee rates
Currently negative fee rates are not supported on archs of 64-bit or more
Diffstat (limited to 'src/amount.cpp')
-rw-r--r--src/amount.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/amount.cpp b/src/amount.cpp
index 68806ff062..7b8618de33 100644
--- a/src/amount.cpp
+++ b/src/amount.cpp
@@ -9,20 +9,30 @@
const std::string CURRENCY_UNIT = "BTC";
-CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
+CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
{
+ assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
+ int64_t nSize = int64_t(nBytes_);
+
if (nSize > 0)
- nSatoshisPerK = nFeePaid*1000/nSize;
+ nSatoshisPerK = nFeePaid * 1000 / nSize;
else
nSatoshisPerK = 0;
}
-CAmount CFeeRate::GetFee(size_t nSize) const
+CAmount CFeeRate::GetFee(size_t nBytes_) const
{
+ assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
+ int64_t nSize = int64_t(nBytes_);
+
CAmount nFee = nSatoshisPerK * nSize / 1000;
- if (nFee == 0 && nSize != 0 && nSatoshisPerK > 0)
- nFee = CAmount(1);
+ if (nFee == 0 && nSize != 0) {
+ if (nSatoshisPerK > 0)
+ nFee = CAmount(1);
+ if (nSatoshisPerK < 0)
+ nFee = CAmount(-1);
+ }
return nFee;
}