diff options
| author | Ross Nicoll <[email protected]> | 2018-01-07 22:56:53 +0000 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2018-09-19 21:09:16 +0100 |
| commit | 18850d359bbc4d3333d9f1ac33607242d205c2ce (patch) | |
| tree | 45cb5ac9949143efb71ddd7f3f7f4cf8c152df2d /src/dogecoin.cpp | |
| parent | Verify when doing 'backupwallet' that destination is not the same path of the... (diff) | |
| download | discoin-18850d359bbc4d3333d9f1ac33607242d205c2ce.tar.xz discoin-18850d359bbc4d3333d9f1ac33607242d205c2ce.zip | |
Add Dogecoin current fee calculation logic (#1413)
Introduces 1 COIN/kb fees, rounded up to the next 1 COIN.
Diffstat (limited to 'src/dogecoin.cpp')
| -rw-r--r-- | src/dogecoin.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp index f06849d61..b34437ca0 100644 --- a/src/dogecoin.cpp +++ b/src/dogecoin.cpp @@ -5,9 +5,12 @@ #include <boost/random/uniform_int.hpp> #include <boost/random/mersenne_twister.hpp> +#include "policy/policy.h" #include "arith_uint256.h" #include "dogecoin.h" +#include "txmempool.h" #include "util.h" +#include "validation.h" int static generateMTRandom(unsigned int s, int range) { @@ -142,3 +145,44 @@ CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusP return 10000 * COIN; } } + +CAmount GetDogecoinMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree) +{ + { + LOCK(mempool.cs); + uint256 hash = tx.GetHash(); + double dPriorityDelta = 0; + CAmount nFeeDelta = 0; + mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); + if (dPriorityDelta > 0 || nFeeDelta > 0) + return 0; + } + + CAmount nMinFee = ::minRelayTxFee.GetFee(nBytes); + nMinFee += GetDogecoinDustFee(tx.vout, ::minRelayTxFee); + + if (fAllowFree) + { + // There is a free transaction area in blocks created by most miners, + // * If we are relaying we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 1000 + // to be considered to fall into this category. We don't want to encourage sending + // multiple transactions instead of one big transaction to avoid fees. + if (nBytes < (DEFAULT_BLOCK_PRIORITY_SIZE - 1000)) + nMinFee = 0; + } + + if (!MoneyRange(nMinFee)) + nMinFee = MAX_MONEY; + return nMinFee; +} + +CAmount GetDogecoinDustFee(const std::vector<CTxOut> &vout, CFeeRate &baseFeeRate) { + CAmount nFee = 0; + + // To limit dust spam, add base fee for each output less than DUST_SOFT_LIMIT + BOOST_FOREACH(const CTxOut& txout, vout) + if (txout.IsDust(::minRelayTxFee)) + nFee += baseFeeRate.GetFeePerK(); + + return nFee; +} |