Add default trait implementation for TxIn

This commit is contained in:
Chris Coverdale 2019-11-17 16:41:14 +00:00
parent c93a70487f
commit 0586ed94c4
1 changed files with 21 additions and 0 deletions

View File

@ -204,6 +204,17 @@ pub struct TxIn {
} }
serde_struct_impl!(TxIn, previous_output, script_sig, sequence, witness); serde_struct_impl!(TxIn, previous_output, script_sig, sequence, witness);
impl Default for TxIn {
fn default() -> TxIn {
TxIn {
previous_output: OutPoint::default(),
script_sig: Script::new(),
sequence: u32::max_value(),
witness: Vec::new(),
}
}
}
/// A transaction output, which defines new coins to be created from old ones. /// A transaction output, which defines new coins to be created from old ones.
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub struct TxOut { pub struct TxOut {
@ -662,6 +673,16 @@ mod tests {
assert!(txin.is_ok()); assert!(txin.is_ok());
} }
#[test]
fn test_txin_default() {
let txin = TxIn::default();
assert_eq!(txin.previous_output, OutPoint::default());
assert_eq!(txin.script_sig, Script::new());
assert_eq!(txin.sequence, 0xFFFFFFFF);
assert_eq!(txin.previous_output, OutPoint::default());
assert_eq!(txin.witness.len(), 0 as usize);
}
#[test] #[test]
fn test_is_coinbase () { fn test_is_coinbase () {
use network::constants::Network; use network::constants::Network;