Skip to content

Commit 0fefcbb

Browse files
committed
wallet: Explicitly preserve transaction locktime in CreateTransaction
We provide the preset nLockTime to CCoinControl so that CreateTransactionInternal can be aware of it and set it in the produced transaction.
1 parent 4d335bb commit 0fefcbb

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/wallet/coincontrol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class CCoinControl
9191
int m_max_depth = DEFAULT_MAX_DEPTH;
9292
//! SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs
9393
FlatSigningProvider m_external_provider;
94+
//! Locktime
95+
std::optional<uint32_t> m_locktime;
9496

9597
CCoinControl();
9698

src/wallet/spend.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,11 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
11601160
}
11611161
txNew.vin.emplace_back(coin->outpoint, CScript(), sequence.value_or(default_sequence));
11621162
}
1163+
if (coin_control.m_locktime) {
1164+
txNew.nLockTime = coin_control.m_locktime.value();
1165+
// If we have a locktime set, we can't use anti-fee-sniping
1166+
use_anti_fee_sniping = false;
1167+
}
11631168
if (use_anti_fee_sniping) {
11641169
DiscourageFeeSniping(txNew, rng_fast, wallet.chain(), wallet.GetLastBlockHash(), wallet.GetLastBlockHeight());
11651170
}
@@ -1341,6 +1346,9 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
13411346
vecSend.push_back(recipient);
13421347
}
13431348

1349+
// Set the user desired locktime
1350+
coinControl.m_locktime = tx.nLockTime;
1351+
13441352
// Acquire the locks to prevent races to the new locked unspents between the
13451353
// CreateTransaction call and LockCoin calls (when lockUnspents is true).
13461354
LOCK(wallet.cs_wallet);

0 commit comments

Comments
 (0)