23 if (wallet->HasWalletSpend(wtx.GetHash())) {
24 errors.push_back(
"Transaction has descendants in the wallet");
30 auto it_mp =
mempool.mapTx.find(wtx.GetHash());
31 if (it_mp !=
mempool.mapTx.end() && it_mp->GetCountWithDescendants() > 1) {
32 errors.push_back(
"Transaction has descendants in the mempool");
37 if (wtx.GetDepthInMainChain() != 0) {
38 errors.push_back(
"Transaction has been mined, or is conflicted with a mined transaction");
43 errors.push_back(
"Transaction is not BIP 125 replaceable");
47 if (wtx.mapValue.count(
"replaced_by_txid")) {
48 errors.push_back(
strprintf(
"Cannot bump transaction %s which was already bumped by transaction %s", wtx.GetHash().ToString(), wtx.mapValue.at(
"replaced_by_txid")));
55 errors.push_back(
"Transaction contains inputs that don't belong to this wallet");
69 if (wtx ==
nullptr)
return false;
71 std::vector<std::string> errors_dummy;
81 auto it = wallet->mapWallet.find(txid);
82 if (it == wallet->mapWallet.end()) {
83 errors.push_back(
"Invalid or non-wallet transaction id");
88 Result result = PreconditionChecks(wallet, wtx, errors);
96 for (
size_t i = 0; i < wtx.
tx->vout.size(); ++i) {
99 errors.push_back(
"Transaction has multiple change outputs");
106 errors.push_back(
"Transaction does not have a change output");
113 if (maxNewTxSize < 0) {
114 errors.push_back(
"Transaction contains inputs that cannot be signed");
120 CFeeRate nOldFeeRate(old_fee, txSize);
125 CFeeRate walletIncrementalRelayFee =
CFeeRate(WALLET_INCREMENTAL_RELAY_FEE);
132 if (total_fee < minTotalFee) {
133 errors.push_back(
strprintf(
"Insufficient totalFee, must be at least %s (oldFee %s + incrementalFee %s)",
138 if (total_fee < requiredFee) {
139 errors.push_back(
strprintf(
"Insufficient totalFee (cannot be less than required fee %s)",
144 nNewFeeRate =
CFeeRate(total_fee, maxNewTxSize);
147 nNewFeeRate =
CFeeRate(new_fee, maxNewTxSize);
156 new_fee = nNewFeeRate.
GetFee(maxNewTxSize);
162 errors.push_back(
strprintf(
"Specified or calculated fee %s is too high (cannot be higher than maxTxFee %s)",
175 "New fee rate (%s) is lower than the minimum fee rate (%s) to get into the mempool -- " 176 "the totalFee value should be at least %s or the settxfee value should be at least %s to add transaction",
186 CAmount nDelta = new_fee - old_fee;
190 if (poutput->
nValue < nDelta) {
191 errors.push_back(
"Change output is too small to bump the fee");
196 poutput->
nValue -= nDelta;
199 new_fee += poutput->
nValue;
200 mtx.
vout.erase(mtx.
vout.begin() + nOutput);
205 for (
auto& input : mtx.
vin) {
206 if (input.nSequence < 0xfffffffe) input.nSequence = 0xfffffffe;
222 if (!errors.empty()) {
225 auto it = txid.
IsNull() ? wallet->mapWallet.end() : wallet->mapWallet.find(txid);
226 if (it == wallet->mapWallet.end()) {
227 errors.push_back(
"Invalid or non-wallet transaction id");
233 Result result = PreconditionChecks(wallet, oldWtx, errors);
251 bumped_txid = tx->GetHash();
264 errors.push_back(
"Created new bumpfee transaction but could not mark the original transaction as replaced");
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)
Compute the virtual transaction size (weight reinterpreted as bytes).
CAmount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control, const CTxMemPool &pool, const CBlockPolicyEstimator &estimator, FeeCalculation *feeCalc)
Estimate the minimum fee considering user set parameters and the required fee.
Result CreateTransaction(const CWallet *wallet, const uint256 &txid, const CCoinControl &coin_control, CAmount total_fee, std::vector< std::string > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction.
const CWalletTx * GetWalletTx(const uint256 &hash) const
std::map< std::string, std::string > mapValue_t
const uint256 & GetHash() const
CAmount maxTxFee
Absolute maximum transaction fee (in satoshis) used by wallet and mempool (rejects high fee in sendra...
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
bool CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector< std::pair< std::string, std::string >> orderForm, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
Call after CreateTransaction unless you want to abort.
bool MarkReplaced(const uint256 &originalHash, const uint256 &newHash)
Mark a transaction as replaced by another transaction (e.g., BIP 125).
std::shared_ptr< const CTransaction > CTransactionRef
bool IsChange(const CTxOut &txout) const
mapValue_t mapValue
Key/value map with information about the transaction.
int64_t CAmount
Amount in satoshis (Can be negative)
CBlockPolicyEstimator feeEstimator
bool SignTransaction(CWallet *wallet, CMutableTransaction &mtx)
Sign the new transaction,.
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
bool SignTransaction(CMutableTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
An output of a transaction.
std::string ToString() const
CCriticalSection cs_wallet
std::vector< CTxOut > vout
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
CAmount GetDustThreshold(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
boost::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
A transaction with a bunch of additional info that only the owner cares about.
bool TransactionCanBeBumped(const CWallet *wallet, const uint256 &txid)
Return whether transaction can be bumped.
Capture information about block/transaction validation.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
std::string FormatStateMessage(const CValidationState &state)
Convert CValidationState to a human-readable message for logging.
A key allocated from the key pool.
Result CommitTransaction(CWallet *wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< std::string > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
CFeeRate GetDiscardRate(const CWallet &wallet, const CBlockPolicyEstimator &estimator)
Return the maximum feerate for discarding change.
bool SignalsOptInRBF(const CTransaction &tx)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Fee rate in satoshis per kilobyte: CAmount / kB.
std::unique_ptr< CConnman > g_connman
A mutable version of CTransaction.
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
CFeeRate incrementalRelayFee
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
std::vector< std::pair< std::string, std::string > > vOrderForm
CAmount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.