X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Futil%2Ftransaction_utils.rs;h=33072f605ad87e25e41bd938e60e507501427162;hb=70d06b46106a49d1434ac168175859278db92620;hp=9ad0b82436ef6e4cb22e3b81ab79355b3c90f716;hpb=da09c4d7f31739f24b52c0bb6a70f9ec59c81485;p=rust-lightning diff --git a/src/util/transaction_utils.rs b/src/util/transaction_utils.rs index 9ad0b824..33072f60 100644 --- a/src/util/transaction_utils.rs +++ b/src/util/transaction_utils.rs @@ -20,13 +20,13 @@ pub fn sort_outputs(outputs: &mut Vec<(TxOut, T)>) { pub fn sort_inputs(inputs: &mut Vec<(TxIn, T)>) { inputs.sort_unstable_by(|a, b| { - if a.0.prev_hash.into_le() < b.0.prev_hash.into_le() { - Ordering::Less - } else if b.0.prev_hash.into_le() < a.0.prev_hash.into_le() { + if a.0.previous_output.txid.into_le() < b.0.previous_output.txid.into_le() { + Ordering::Less + } else if b.0.previous_output.txid.into_le() < a.0.previous_output.txid.into_le() { Ordering::Greater - } else if a.0.prev_index < b.0.prev_index { + } else if a.0.previous_output.vout < b.0.previous_output.vout { Ordering::Less - } else if b.0.prev_index < a.0.prev_index { + } else if b.0.previous_output.vout < a.0.previous_output.vout { Ordering::Greater } else { Ordering::Equal @@ -39,12 +39,12 @@ mod tests { use super::*; use bitcoin::blockdata::script::{Script, Builder}; - use bitcoin::blockdata::transaction::TxOut; - use bitcoin::util::hash::Sha256dHash; + use bitcoin::blockdata::transaction::{TxOut, OutPoint}; + use bitcoin::util::hash::Sha256dHash; use hex::decode; - #[test] + #[test] fn sort_output_by_value() { let txout1 = TxOut { value: 100, @@ -67,7 +67,7 @@ mod tests { ); } - #[test] + #[test] fn sort_output_by_script_pubkey() { let txout1 = TxOut { value: 100, @@ -90,7 +90,7 @@ mod tests { ); } - #[test] + #[test] fn sort_output_by_bip_test() { let txout1 = TxOut { value: 100000000, @@ -136,7 +136,7 @@ mod tests { assert_eq!(outputs, expected); } - )* + )* } } @@ -161,8 +161,10 @@ mod tests { let expected_raw: Vec<(&str, u32)> = $value; let expected: Vec<(TxIn, &str)> = expected_raw.iter().map( |txin_raw| TxIn { - prev_hash: Sha256dHash::from_hex(txin_raw.0).unwrap(), - prev_index: txin_raw.1, + previous_output: OutPoint { + txid: Sha256dHash::from_hex(txin_raw.0).unwrap(), + vout: txin_raw.1, + }, script_sig: Script::new(), sequence: 0, witness: vec![]