diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 0b51b984b..274aeada4 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -127,10 +127,6 @@ impl OutPoint { pub fn is_null(&self) -> bool { *self == OutPoint::null() } } -impl Default for OutPoint { - fn default() -> Self { OutPoint::null() } -} - impl fmt::Display for OutPoint { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}:{}", self.txid, self.vout) @@ -249,6 +245,14 @@ pub struct TxIn { } impl TxIn { + /// An empty transaction input with the previous output as for a coinbase transaction. + pub const EMPTY_COINBASE: TxIn = TxIn { + previous_output: OutPoint::COINBASE_PREVOUT, + script_sig: ScriptBuf::new(), + sequence: Sequence::MAX, + witness: Witness::new(), + }; + /// Returns the input base weight. /// /// Base weight excludes the witness and script. @@ -313,17 +317,6 @@ impl TxIn { pub fn total_size(&self) -> usize { self.base_size() + self.witness.size() } } -impl Default for TxIn { - fn default() -> TxIn { - TxIn { - previous_output: OutPoint::default(), - script_sig: ScriptBuf::new(), - sequence: Sequence::MAX, - witness: Witness::default(), - } - } -} - /// Bitcoin transaction output. /// /// Defines new coins to be created as a result of the transaction, @@ -1540,16 +1533,6 @@ mod tests { assert!(txin.is_ok()); } - #[test] - fn txin_default() { - let txin = TxIn::default(); - assert_eq!(txin.previous_output, OutPoint::default()); - assert_eq!(txin.script_sig, ScriptBuf::new()); - assert_eq!(txin.sequence, Sequence::from_consensus(0xFFFFFFFF)); - assert_eq!(txin.previous_output, OutPoint::default()); - assert_eq!(txin.witness.len(), 0); - } - #[test] fn is_coinbase() { use crate::constants; @@ -2251,7 +2234,7 @@ mod tests { #[test] fn outpoint_format() { - let outpoint = OutPoint::default(); + let outpoint = OutPoint::COINBASE_PREVOUT; let debug = "OutPoint { txid: 0000000000000000000000000000000000000000000000000000000000000000, vout: 4294967295 }"; assert_eq!(debug, format!("{:?}", &outpoint)); diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs index 4992df30c..ab0ac6287 100644 --- a/bitcoin/src/crypto/sighash.rs +++ b/bitcoin/src/crypto/sighash.rs @@ -1487,7 +1487,7 @@ mod tests { let tx = Transaction { version: transaction::Version::ONE, lock_time: absolute::LockTime::ZERO, - input: vec![TxIn::default(), TxIn::default()], + input: vec![TxIn::EMPTY_COINBASE, TxIn::EMPTY_COINBASE], output: vec![TxOut::NULL], }; let script = ScriptBuf::new(); @@ -1676,7 +1676,7 @@ mod tests { let dumb_tx = Transaction { version: transaction::Version::TWO, lock_time: absolute::LockTime::ZERO, - input: vec![TxIn::default()], + input: vec![TxIn::EMPTY_COINBASE], output: vec![], }; let mut c = SighashCache::new(&dumb_tx); diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs index 08ea1e8ad..08830e4f5 100644 --- a/bitcoin/src/psbt/mod.rs +++ b/bitcoin/src/psbt/mod.rs @@ -2155,7 +2155,7 @@ mod tests { vout: 0, }, sequence: Sequence::ENABLE_LOCKTIME_NO_RBF, - ..Default::default() + ..TxIn::EMPTY_COINBASE } ], output: vec![ @@ -2186,7 +2186,7 @@ mod tests { vout: 1, }, sequence: Sequence::MAX, - ..Default::default() + ..TxIn::EMPTY_COINBASE }, TxIn { previous_output: OutPoint { @@ -2194,7 +2194,7 @@ mod tests { vout: 1, }, sequence: Sequence::MAX, - ..Default::default() + ..TxIn::EMPTY_COINBASE } ], output: vec![ @@ -2258,7 +2258,7 @@ mod tests { let unsigned_tx = Transaction { version: transaction::Version::TWO, lock_time: absolute::LockTime::ZERO, - input: vec![TxIn::default(), TxIn::default()], + input: vec![TxIn::EMPTY_COINBASE, TxIn::EMPTY_COINBASE], output: vec![TxOut::NULL], }; let mut psbt = Psbt::from_unsigned_tx(unsigned_tx).unwrap();