From 18850d359bbc4d3333d9f1ac33607242d205c2ce Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 7 Jan 2018 22:56:53 +0000 Subject: Add Dogecoin current fee calculation logic (#1413) Introduces 1 COIN/kb fees, rounded up to the next 1 COIN. --- src/wallet/wallet.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/wallet/wallet.cpp') diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0e09dc70d..b34cbae3a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -8,6 +8,7 @@ #include "base58.h" #include "checkpoints.h" #include "chain.h" +#include "dogecoin.h" #include "wallet/coincontrol.h" #include "consensus/consensus.h" #include "consensus/validation.h" @@ -2636,7 +2637,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt break; } - CAmount nFeeNeeded = GetMinimumFee(nBytes, currentConfirmationTarget, mempool); + CAmount nFeeNeeded = GetMinimumFee(txNew, nBytes, currentConfirmationTarget, mempool); if (coinControl && nFeeNeeded > 0 && coinControl->nMinimumTotalFee > nFeeNeeded) { nFeeNeeded = coinControl->nMinimumTotalFee; } @@ -2805,18 +2806,30 @@ bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB *pwa return true; } +CAmount CWallet::GetRequiredFee(const CMutableTransaction& tx, unsigned int nTxBytes) +{ + // Dogecoin: Round TX bytes up to the next 1,000 bytes + nTxBytes += 1000 - (nTxBytes % 1000); + + // Dogecoin: Add an increased fee for each dust output + return std::max(minTxFee.GetFee(nTxBytes) + GetDogecoinDustFee(tx.vout, minTxFee), ::minRelayTxFee.GetFee(nTxBytes)); +} + CAmount CWallet::GetRequiredFee(unsigned int nTxBytes) { + // Dogecoin: Round TX bytes up to the next 1,000 bytes + nTxBytes += 1000 - (nTxBytes % 1000); + return std::max(minTxFee.GetFee(nTxBytes), ::minRelayTxFee.GetFee(nTxBytes)); } -CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool) +CAmount CWallet::GetMinimumFee(const CMutableTransaction& tx, unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool) { // payTxFee is the user-set global for desired feerate - return GetMinimumFee(nTxBytes, nConfirmTarget, pool, payTxFee.GetFee(nTxBytes)); + return GetMinimumFee(tx, nTxBytes, nConfirmTarget, pool, payTxFee.GetFee(nTxBytes)); } -CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, CAmount targetFee) +CAmount CWallet::GetMinimumFee(const CMutableTransaction& tx, unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, CAmount targetFee) { CAmount nFeeNeeded = targetFee; // User didn't set: use -txconfirmtarget to estimate... @@ -2828,7 +2841,7 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge nFeeNeeded = fallbackFee.GetFee(nTxBytes); } // prevent user from paying a fee below minRelayTxFee or minTxFee - nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes)); + nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(tx, nTxBytes)); // But always obey the maximum if (nFeeNeeded > maxTxFee) nFeeNeeded = maxTxFee; @@ -2836,8 +2849,6 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge } - - DBErrors CWallet::LoadWallet(bool& fFirstRunRet) { if (!fFileBacked) -- cgit v1.2.3