Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE); | CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE); | ||||
unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET; | unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET; | ||||
bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE; | bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE; | ||||
const char *DEFAULT_WALLET_DAT = "wallet.dat"; | const char *DEFAULT_WALLET_DAT = "wallet.dat"; | ||||
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000; | const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000; | ||||
/** | /** | ||||
* Fees smaller than this (in satoshi) are considered zero fee (for transaction | |||||
* creation) | |||||
* Override with -mintxfee | |||||
*/ | |||||
CFeeRate CWallet::minTxFee = CFeeRate(DEFAULT_TRANSACTION_MINFEE); | |||||
/** | |||||
* If fee estimation does not have enough data to provide estimates, use this | * If fee estimation does not have enough data to provide estimates, use this | ||||
* fee instead. Has no effect if not using fee estimation. | * fee instead. Has no effect if not using fee estimation. | ||||
* Override with -fallbackfee | * Override with -fallbackfee | ||||
*/ | */ | ||||
CFeeRate CWallet::fallbackFee = CFeeRate(DEFAULT_FALLBACK_FEE); | CFeeRate CWallet::fallbackFee = CFeeRate(DEFAULT_FALLBACK_FEE); | ||||
const uint256 CMerkleTx::ABANDON_HASH(uint256S( | const uint256 CMerkleTx::ABANDON_HASH(uint256S( | ||||
"0000000000000000000000000000000000000000000000000000000000000001")); | "0000000000000000000000000000000000000000000000000000000000000001")); | ||||
▲ Show 20 Lines • Show All 3,101 Lines • ▼ Show 20 Lines | bool CWallet::AddAccountingEntry(const CAccountingEntry &acentry, | ||||
laccentries.push_back(acentry); | laccentries.push_back(acentry); | ||||
CAccountingEntry &entry = laccentries.back(); | CAccountingEntry &entry = laccentries.back(); | ||||
wtxOrdered.insert(std::make_pair(entry.nOrderPos, TxPair(nullptr, &entry))); | wtxOrdered.insert(std::make_pair(entry.nOrderPos, TxPair(nullptr, &entry))); | ||||
return true; | return true; | ||||
} | } | ||||
Amount CWallet::GetRequiredFee(unsigned int nTxBytes) { | |||||
return std::max(minTxFee.GetFee(nTxBytes), | |||||
GetConfig().GetMinFeePerKB().GetFee(nTxBytes)); | |||||
} | |||||
Amount CWallet::GetMinimumFee(unsigned int nTxBytes, | Amount CWallet::GetMinimumFee(unsigned int nTxBytes, | ||||
unsigned int nConfirmTarget, | unsigned int nConfirmTarget, | ||||
const CTxMemPool &pool) { | const CTxMemPool &pool) { | ||||
// payTxFee is the user-set global for desired feerate. | // payTxFee is the user-set global for desired feerate. | ||||
return GetMinimumFee(nTxBytes, nConfirmTarget, pool, | return GetMinimumFee(nTxBytes, nConfirmTarget, pool, | ||||
payTxFee.GetFee(nTxBytes)); | payTxFee.GetFee(nTxBytes)); | ||||
} | } | ||||
Amount CWallet::GetMinimumFee(unsigned int nTxBytes, | Amount CWallet::GetMinimumFee(unsigned int nTxBytes, | ||||
unsigned int nConfirmTarget, | unsigned int nConfirmTarget, | ||||
const CTxMemPool &pool, Amount targetFee) { | const CTxMemPool &pool, Amount targetFee) { | ||||
Amount nFeeNeeded = targetFee; | Amount nFeeNeeded = targetFee; | ||||
// User didn't set: use -txconfirmtarget to estimate... | // User didn't set: use -txconfirmtarget to estimate... | ||||
if (nFeeNeeded == Amount::zero()) { | if (nFeeNeeded == Amount::zero()) { | ||||
int estimateFoundTarget = nConfirmTarget; | int estimateFoundTarget = nConfirmTarget; | ||||
nFeeNeeded = pool.estimateSmartFee(nConfirmTarget, &estimateFoundTarget) | nFeeNeeded = pool.estimateSmartFee(nConfirmTarget, &estimateFoundTarget) | ||||
.GetFee(nTxBytes); | .GetFee(nTxBytes); | ||||
// ... unless we don't have enough mempool data for estimatefee, then | // ... unless we don't have enough mempool data for estimatefee, then | ||||
// use fallbackFee. | // use fallbackFee. | ||||
if (nFeeNeeded == Amount::zero()) { | if (nFeeNeeded == Amount::zero()) { | ||||
nFeeNeeded = fallbackFee.GetFee(nTxBytes); | nFeeNeeded = fallbackFee.GetFee(nTxBytes); | ||||
} | } | ||||
} | } | ||||
// Prevent user from paying a fee below minRelayTxFee or minTxFee. | // Prevent user from paying a fee below minRelayTxFee. | ||||
nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes)); | nFeeNeeded = std::max(nFeeNeeded, | ||||
GetConfig().GetMinFeePerKB().GetFeeCeiling(nTxBytes)); | |||||
// But always obey the maximum. | // But always obey the maximum. | ||||
if (nFeeNeeded > maxTxFee) { | if (nFeeNeeded > maxTxFee) { | ||||
nFeeNeeded = maxTxFee; | nFeeNeeded = maxTxFee; | ||||
} | } | ||||
return nFeeNeeded; | return nFeeNeeded; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 843 Lines • ▼ Show 20 Lines | strUsage += HelpMessageOpt( | ||||
"-keypool=<n>", strprintf(_("Set key pool size to <n> (default: %u)"), | "-keypool=<n>", strprintf(_("Set key pool size to <n> (default: %u)"), | ||||
DEFAULT_KEYPOOL_SIZE)); | DEFAULT_KEYPOOL_SIZE)); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
"-fallbackfee=<amt>", | "-fallbackfee=<amt>", | ||||
strprintf(_("A fee rate (in %s/kB) that will be used when fee " | strprintf(_("A fee rate (in %s/kB) that will be used when fee " | ||||
"estimation has insufficient data (default: %s)"), | "estimation has insufficient data (default: %s)"), | ||||
CURRENCY_UNIT, FormatMoney(DEFAULT_FALLBACK_FEE))); | CURRENCY_UNIT, FormatMoney(DEFAULT_FALLBACK_FEE))); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
"-mintxfee=<amt>", | |||||
strprintf(_("Fees (in %s/kB) smaller than this are considered zero fee " | |||||
"for transaction creation (default: %s)"), | |||||
CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MINFEE))); | |||||
strUsage += HelpMessageOpt( | |||||
"-paytxfee=<amt>", | "-paytxfee=<amt>", | ||||
strprintf( | strprintf( | ||||
_("Fee (in %s/kB) to add to transactions you send (default: %s)"), | _("Fee (in %s/kB) to add to transactions you send (default: %s)"), | ||||
CURRENCY_UNIT, FormatMoney(payTxFee.GetFeePerK()))); | CURRENCY_UNIT, FormatMoney(payTxFee.GetFeePerK()))); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
"-rescan", | "-rescan", | ||||
_("Rescan the block chain for missing wallet transactions on startup")); | _("Rescan the block chain for missing wallet transactions on startup")); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
▲ Show 20 Lines • Show All 379 Lines • ▼ Show 20 Lines | bool CWallet::ParameterInteraction() { | ||||
} | } | ||||
if (minRelayTxFee.GetFeePerK() > HIGH_TX_FEE_PER_KB) { | if (minRelayTxFee.GetFeePerK() > HIGH_TX_FEE_PER_KB) { | ||||
InitWarning( | InitWarning( | ||||
AmountHighWarn("-minrelaytxfee") + " " + | AmountHighWarn("-minrelaytxfee") + " " + | ||||
_("The wallet will avoid paying less than the minimum relay fee.")); | _("The wallet will avoid paying less than the minimum relay fee.")); | ||||
} | } | ||||
if (gArgs.IsArgSet("-mintxfee")) { | |||||
Amount n = Amount::zero(); | |||||
auto parsed = ParseMoney(gArgs.GetArg("-mintxfee", ""), n); | |||||
if (!parsed || Amount::zero() == n) { | |||||
return InitError( | |||||
AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", ""))); | |||||
} | |||||
if (n > HIGH_TX_FEE_PER_KB) { | |||||
InitWarning(AmountHighWarn("-mintxfee") + " " + | |||||
_("This is the minimum transaction fee you pay on " | |||||
"every transaction.")); | |||||
} | |||||
CWallet::minTxFee = CFeeRate(n); | |||||
} | |||||
if (gArgs.IsArgSet("-fallbackfee")) { | if (gArgs.IsArgSet("-fallbackfee")) { | ||||
Amount nFeePerK = Amount::zero(); | Amount nFeePerK = Amount::zero(); | ||||
if (!ParseMoney(gArgs.GetArg("-fallbackfee", ""), nFeePerK)) { | if (!ParseMoney(gArgs.GetArg("-fallbackfee", ""), nFeePerK)) { | ||||
return InitError( | return InitError( | ||||
strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), | strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), | ||||
gArgs.GetArg("-fallbackfee", ""))); | gArgs.GetArg("-fallbackfee", ""))); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |