PIVX Core  5.6.99
P2P Digital Currency
fees.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 The Bitcoin Core developers
3 // Copyright (c) 2021 The PIVX Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "wallet/fees.h"
8 
9 #include "policy/policy.h"
10 #include "txmempool.h"
11 #include "util/system.h"
12 #include "validation.h"
13 #include "wallet/wallet.h"
14 
15 CAmount GetRequiredFee(unsigned int nTxBytes)
16 {
17  return std::max(CWallet::minTxFee.GetFee(nTxBytes), ::minRelayTxFee.GetFee(nTxBytes));
18 }
19 
20 CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool)
21 {
22  // payTxFee is user-set "I want to pay this much"
23  CAmount nFeeNeeded = payTxFee.GetFee(nTxBytes);
24  // User didn't set: use -txconfirmtarget to estimate...
25  if (nFeeNeeded == 0) {
26  int estimateFoundTarget = (int) nConfirmTarget;
27  nFeeNeeded = pool.estimateSmartFee((int) nConfirmTarget, &estimateFoundTarget).GetFee(nTxBytes);
28  // ... unless we don't have enough mempool data for our desired target
29  // so we make sure we're paying at least minTxFee
30  if (nFeeNeeded == 0 || (unsigned int) estimateFoundTarget > nConfirmTarget)
31  nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes));
32  }
33  // prevent user from paying a non-sense fee (like 1 satoshi): 0 < fee < minRelayFee
34  if (nFeeNeeded < ::minRelayTxFee.GetFee(nTxBytes))
35  nFeeNeeded = ::minRelayTxFee.GetFee(nTxBytes);
36  // But always obey the maximum
37  if (nFeeNeeded > maxTxFee)
38  nFeeNeeded = maxTxFee;
39  return nFeeNeeded;
40 }
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
CAmount GetFee(size_t size) const
Definition: feerate.cpp:21
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:384
CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks=nullptr) const
Estimate fee rate needed to get into the next nBlocks If no answer can be given at nBlocks,...
Definition: txmempool.cpp:1206
static CFeeRate minTxFee
Fees smaller than this (in upiv) are considered zero fee (for transaction creation) We are ~100 times...
Definition: wallet.h:1129
CFeeRate minRelayTxFee
Fees smaller than this (in upiv) are considered zero fee (for relaying, mining and transaction creati...
Definition: validation.cpp:108
CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool &pool)
Estimate the minimum fee considering user set parameters and the required fee.
Definition: fees.cpp:20
CAmount GetRequiredFee(unsigned int nTxBytes)
Return the minimum required fee taking into account the floating relay fee and user set minimum trans...
Definition: fees.cpp:15
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE)
Settings.
CAmount maxTxFee
Definition: wallet.cpp:38