diff options
| author | Wladimir J. van der Laan <[email protected]> | 2016-04-14 11:40:11 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2016-04-14 12:07:52 +0200 |
| commit | 536b75e946fb61a7431f429820c95b8e434cb62a (patch) | |
| tree | 9090069638f116c9c99caa7b8f259307be2783ad /src/amount.cpp | |
| parent | Merge #7838: [Doc] Update gitian build guide to debian 8.4.0 (diff) | |
| parent | [amount] tests: Fix off-by-one mistake (diff) | |
| download | discoin-536b75e946fb61a7431f429820c95b8e434cb62a.tar.xz discoin-536b75e946fb61a7431f429820c95b8e434cb62a.zip | |
Merge #7796: [amount] Add support for negative fee rates
facf5a4 [amount] tests: Fix off-by-one mistake (MarcoFalke)
fa2da2c [amount] Add support for negative fee rates (MarcoFalke)
11114a6 [amount] test negative fee rates and full constructor (MarcoFalke)
Diffstat (limited to 'src/amount.cpp')
| -rw-r--r-- | src/amount.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/amount.cpp b/src/amount.cpp index 68806ff06..7b8618de3 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; } |