LCOV - code coverage report
Current view: top level - src/wallet - fees.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 12 14 85.7 %
Date: 2025-02-23 09:33:43 Functions: 2 2 100.0 %

          Line data    Source code
       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         890 : CAmount GetRequiredFee(unsigned int nTxBytes)
      16             : {
      17         890 :     return std::max(CWallet::minTxFee.GetFee(nTxBytes), ::minRelayTxFee.GetFee(nTxBytes));
      18             : }
      19             : 
      20        1086 : CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool)
      21             : {
      22             :     // payTxFee is user-set "I want to pay this much"
      23        1086 :     CAmount nFeeNeeded = payTxFee.GetFee(nTxBytes);
      24             :     // User didn't set: use -txconfirmtarget to estimate...
      25        1086 :     if (nFeeNeeded == 0) {
      26         890 :         int estimateFoundTarget = (int) nConfirmTarget;
      27         890 :         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         890 :         if (nFeeNeeded == 0 || (unsigned int) estimateFoundTarget > nConfirmTarget)
      31        1780 :             nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes));
      32             :     }
      33             :     // prevent user from paying a non-sense fee (like 1 satoshi): 0 < fee < minRelayFee
      34        1086 :     if (nFeeNeeded < ::minRelayTxFee.GetFee(nTxBytes))
      35           0 :         nFeeNeeded = ::minRelayTxFee.GetFee(nTxBytes);
      36             :     // But always obey the maximum
      37        1086 :     if (nFeeNeeded > maxTxFee)
      38           0 :         nFeeNeeded = maxTxFee;
      39        1086 :     return nFeeNeeded;
      40             : }

Generated by: LCOV version 1.14