Simplify HolderHTLCOutput constructor and track CLTV expiry
[rust-lightning] / lightning / src / chain / channelmonitor.rs
index de82681415d4edf11b2bd55993584c1787ab6c93..7fc512a5a1859429b265d2b7ffc967b92fec3f4b 100644 (file)
@@ -51,6 +51,7 @@ use util::ser::{Readable, ReadableArgs, MaybeReadable, Writer, Writeable, U48};
 use util::byte_utils;
 use util::events::Event;
 
+use prelude::*;
 use std::collections::{HashMap, HashSet};
 use core::{cmp, mem};
 use std::io::Error;
@@ -1785,14 +1786,17 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
 
                for &(ref htlc, _, _) in holder_tx.htlc_outputs.iter() {
                        if let Some(transaction_output_index) = htlc.transaction_output_index {
-                               let htlc_output = HolderHTLCOutput::build(if !htlc.offered {
-                                       if let Some(preimage) = self.payment_preimages.get(&htlc.payment_hash) {
-                                               Some(preimage.clone())
+                               let htlc_output = if htlc.offered {
+                                               HolderHTLCOutput::build_offered(htlc.amount_msat, htlc.cltv_expiry)
                                        } else {
-                                               // We can't build an HTLC-Success transaction without the preimage
-                                               continue;
-                                       }
-                               } else { None }, htlc.amount_msat);
+                                               let payment_preimage = if let Some(preimage) = self.payment_preimages.get(&htlc.payment_hash) {
+                                                       preimage.clone()
+                                               } else {
+                                                       // We can't build an HTLC-Success transaction without the preimage
+                                                       continue;
+                                               };
+                                               HolderHTLCOutput::build_accepted(payment_preimage, htlc.amount_msat)
+                                       };
                                let htlc_package = PackageTemplate::build_package(holder_tx.txid, transaction_output_index, PackageSolvingData::HolderHTLCOutput(htlc_output), height, false, height);
                                claim_requests.push(htlc_package);
                        }
@@ -2911,6 +2915,7 @@ mod tests {
        use bitcoin::secp256k1::Secp256k1;
        use std::sync::{Arc, Mutex};
        use chain::keysinterface::InMemorySigner;
+       use prelude::*;
 
        #[test]
        fn test_prune_preimages() {