Merge pull request #341 from ccdle12/txin-impl-default

Add default trait implementation for TxIn
This commit is contained in:
Andrew Poelstra 2019-12-06 21:21:49 +00:00 committed by GitHub
commit 65cb18d583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -203,6 +203,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 {
@ -659,6 +670,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;