diff --git a/src/protocol/contract.rs b/src/protocol/contract.rs index ed10def3..6785ef67 100644 --- a/src/protocol/contract.rs +++ b/src/protocol/contract.rs @@ -525,6 +525,8 @@ mod test { use core::panic; use std::str::FromStr; + const TEST_CURRENT_HEIGHT: u32 = 100; + fn read_pubkeys_from_contract_reedimscript( contract_script: &Script, ) -> Result<(PublicKey, PublicKey), &'static str> { @@ -681,7 +683,7 @@ mod test { value: Amount::from_sat(3000), }, ], - lock_time: LockTime::ZERO, + lock_time: LockTime::from_height(TEST_CURRENT_HEIGHT).unwrap(), version: Version::TWO, }; @@ -845,7 +847,7 @@ mod test { script_pubkey: funding_spk, value: Amount::from_sat(2000), }], - lock_time: LockTime::ZERO, + lock_time: LockTime::from_height(TEST_CURRENT_HEIGHT).unwrap(), version: Version::TWO, }; @@ -1254,7 +1256,7 @@ mod test { value: Amount::from_sat(3000), }, ], - lock_time: LockTime::ZERO, + lock_time: LockTime::from_height(TEST_CURRENT_HEIGHT).unwrap(), version: Version::TWO, }; diff --git a/src/wallet/direct_send.rs b/src/wallet/direct_send.rs index 392bdd61..6017c316 100644 --- a/src/wallet/direct_send.rs +++ b/src/wallet/direct_send.rs @@ -215,7 +215,8 @@ impl Wallet { } // Set the Anti-Fee-Snipping locktime - let lock_time = LockTime::from_height(self.rpc.get_block_count().unwrap() as u32).unwrap(); + let current_height = self.rpc.get_block_count()?; + let lock_time = LockTime::from_height(current_height as u32)?; let mut tx = Transaction { input: tx_inputs, diff --git a/src/wallet/fidelity.rs b/src/wallet/fidelity.rs index 91417a1e..52d47bb4 100644 --- a/src/wallet/fidelity.rs +++ b/src/wallet/fidelity.rs @@ -350,14 +350,16 @@ impl Wallet { script_pubkey: change_addrs, }); } + + // Set the Anti-Fee Snipping Locktime let current_height = self.rpc.get_block_count()?; - let anti_fee_snipping_locktime = LockTime::from_height(current_height as u32)?; + let lock_time = LockTime::from_height(current_height as u32)?; let mut tx = Transaction { input: tx_inputs, output: tx_outs, - lock_time: anti_fee_snipping_locktime, - version: Version::TWO, // anti-fee-snipping + lock_time, + version: Version::TWO, }; let mut input_info = selected_utxo diff --git a/src/wallet/funding.rs b/src/wallet/funding.rs index 12333a2f..9de814f0 100644 --- a/src/wallet/funding.rs +++ b/src/wallet/funding.rs @@ -171,10 +171,16 @@ impl Wallet { script_sig: ScriptBuf::new(), }) .collect::>(); + + // Set the Anti-Fee-Snipping locktime + let current_height = self.rpc.get_block_count()?; + + let lock_time = LockTime::from_height(current_height as u32)?; + let mut funding_tx = Transaction { input: tx_inputs, output: tx_outs, - lock_time: LockTime::ZERO, + lock_time, version: Version::TWO, }; let mut input_info = selected_utxo @@ -221,6 +227,10 @@ impl Wallet { let mut destinations_iter = destinations.iter(); let first_tx_input = utxos.next().unwrap(); + // Set the Anti-Fee-Snipping locktime + let current_height = self.rpc.get_block_count()?; + let lock_time = LockTime::from_height(current_height as u32)?; + for _ in 0..destinations.len() - 2 { let (txid, vout, value) = utxos.next().unwrap(); @@ -241,10 +251,11 @@ impl Wallet { script_pubkey: address.script_pubkey(), }); } + let mut funding_tx = Transaction { input: tx_inputs, output: tx_outs, - lock_time: LockTime::ZERO, + lock_time, version: Version::TWO, }; self.sign_transaction(&mut funding_tx, &mut input_info)?; @@ -289,10 +300,11 @@ impl Wallet { script_pubkey: address.script_pubkey(), }); } + let mut funding_tx = Transaction { input: tx_inputs, output: tx_outs, - lock_time: LockTime::ZERO, + lock_time, version: Version::TWO, }; let mut info = input_info.iter().cloned(); @@ -335,7 +347,7 @@ impl Wallet { let mut funding_tx = Transaction { input: tx_inputs, output: tx_outs, - lock_time: LockTime::ZERO, + lock_time, version: Version::TWO, }; let mut info = iter::once(self.get_utxo((first_txid, first_vout))?.unwrap()); @@ -405,10 +417,14 @@ impl Wallet { }) .collect::>(); + // Set the Anti-Fee-Snipping locktime + let current_height = self.rpc.get_block_count()?; + let lock_time = LockTime::from_height(current_height as u32)?; + let mut funding_tx = Transaction { input: tx_inputs, output: tx_outs, - lock_time: LockTime::ZERO, + lock_time, version: Version::TWO, }; diff --git a/src/wallet/swapcoin.rs b/src/wallet/swapcoin.rs index 1cd58b52..7e5107c7 100644 --- a/src/wallet/swapcoin.rs +++ b/src/wallet/swapcoin.rs @@ -671,6 +671,8 @@ mod tests { use super::*; use bitcoin::{NetworkKind, PrivateKey}; + const TEST_CURRENT_HEIGHT: u32 = 100; + #[test] fn test_apply_privkey_watchonly_swapcoin() { let secp = Secp256k1::new(); @@ -844,7 +846,7 @@ mod tests { let tx = Transaction { input: vec![input.clone()], output: vec![], - lock_time: LockTime::ZERO, + lock_time: LockTime::from_height(TEST_CURRENT_HEIGHT).unwrap(), version: Version::TWO, }; @@ -879,7 +881,7 @@ mod tests { }; // Intentionally failing to sign with incomplete swapcoin assert!(incoming_swapcoin - .sign_transaction_input(index, &tx, &mut input, &contract_redeemscript,) + .sign_transaction_input(index, &tx, &mut input, &contract_redeemscript) .is_err()); let sign = bitcoin::ecdsa::Signature { signature: secp256k1::ecdsa::Signature::from_compact(&[0; 64]).unwrap(), @@ -954,7 +956,7 @@ mod tests { incoming_swapcoin.contract_tx.output[0].value.to_sat() - miner_fee, ), }], - lock_time: LockTime::ZERO, + lock_time: LockTime::from_height(TEST_CURRENT_HEIGHT).unwrap(), version: Version::TWO, }; let index = 0; @@ -1034,7 +1036,7 @@ mod tests { incoming_swapcoin.contract_tx.output[0].value.to_sat() - miner_fee, ), }], - lock_time: LockTime::ZERO, + lock_time: LockTime::from_height(TEST_CURRENT_HEIGHT).unwrap(), version: Version::TWO, }; let index = 0;