Dogecoin Core  1.14.2
P2P Digital Currency
amount.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "amount.h"
7 
8 #include "tinyformat.h"
9 
10 const std::string CURRENCY_UNIT = "DOGE";
11 
12 CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
13 {
14  assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
15  int64_t nSize = int64_t(nBytes_);
16 
17  if (nSize > 0)
18  nSatoshisPerK = nFeePaid * 1000 / nSize;
19  else
20  nSatoshisPerK = 0;
21 }
22 
23 CAmount CFeeRate::GetFee(size_t nBytes_) const
24 {
25  assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
26  int64_t nSize = int64_t(nBytes_);
27 
28  // Dogecoin: Round up to the nearest 1000 bytes so we get round tx fees
29  if (nSize % 1000 > 0) {
30  nSize = nSize + 1000 - (nSize % 1000);
31  }
32 
33  CAmount nFee = nSatoshisPerK * nSize / 1000;
34 
35  if (nFee == 0 && nSize != 0) {
36  if (nSatoshisPerK > 0)
37  nFee = CAmount(1);
38  if (nSatoshisPerK < 0)
39  nFee = CAmount(-1);
40  }
41 
42  return nFee;
43 }
44 
45 std::string CFeeRate::ToString() const
46 {
47  return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
48 }
const std::string CURRENCY_UNIT
Definition: amount.cpp:10
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:15
CAmount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
Definition: amount.cpp:23
std::string ToString() const
Definition: amount.cpp:45
CAmount nSatoshisPerK
Definition: amount.h:40
CFeeRate()
Fee rate of 0 satoshis per kB.
Definition: amount.h:43
#define strprintf
Definition: tinyformat.h:1047