writer.write_all(&delayed_payment_base_key[..])?;
writer.write_all(&payment_base_key[..])?;
writer.write_all(&shutdown_pubkey.serialize())?;
- if let Some(ref prev_latest_per_commitment_point) = *prev_latest_per_commitment_point {
- writer.write_all(&[1; 1])?;
- writer.write_all(&prev_latest_per_commitment_point.serialize())?;
- } else {
- writer.write_all(&[0; 1])?;
- }
- if let Some(ref latest_per_commitment_point) = *latest_per_commitment_point {
- writer.write_all(&[1; 1])?;
- writer.write_all(&latest_per_commitment_point.serialize())?;
- } else {
- writer.write_all(&[0; 1])?;
- }
+ prev_latest_per_commitment_point.write(writer)?;
+ latest_per_commitment_point.write(writer)?;
match funding_info {
&Some((ref outpoint, ref script)) => {
writer.write_all(&outpoint.txid[..])?;
debug_assert!(false, "Try to serialize a useless Local monitor !");
},
}
- write_option!(current_remote_commitment_txid);
- write_option!(prev_remote_commitment_txid);
+ current_remote_commitment_txid.write(writer)?;
+ prev_remote_commitment_txid.write(writer)?;
},
Storage::Watchtower { .. } => unimplemented!(),
}
writer.write_all(&byte_utils::be64_to_array($htlc_output.amount_msat))?;
writer.write_all(&byte_utils::be32_to_array($htlc_output.cltv_expiry))?;
writer.write_all(&$htlc_output.payment_hash.0[..])?;
- write_option!(&$htlc_output.transaction_output_index);
+ $htlc_output.transaction_output_index.write(writer)?;
}
}
assert_eq!(&outputs, &vec![(txout1_, "ignore"), (txout2_, "ignore")]);
}
+ #[test]
+ fn sort_output_tie_breaker_test() {
+ let txout1 = TxOut {
+ value: 100,
+ script_pubkey: Builder::new().push_int(1).push_int(2).into_script()
+ };
+ let txout1_ = txout1.clone();
+
+ let txout2 = txout1.clone();
+ let txout2_ = txout1.clone();
+
+ let mut outputs = vec![(txout1, 420), (txout2, 69)];
+ sort_outputs(&mut outputs, |a, b| { a.cmp(b) });
+
+ assert_eq!(
+ &outputs,
+ &vec![(txout2_, 69), (txout1_, 420)]
+ );
+ }
+
fn script_from_hex(hex_str: &str) -> Script {
Script::from(decode(hex_str).unwrap())
}