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);
}
pub(crate) struct HolderHTLCOutput {
preimage: Option<PaymentPreimage>,
amount: u64,
+ /// Defaults to 0 for HTLC-Success transactions, which have no expiry
+ cltv_expiry: u32,
}
impl HolderHTLCOutput {
- pub(crate) fn build(preimage: Option<PaymentPreimage>, amount: u64) -> Self {
+ pub(crate) fn build_offered(amount: u64, cltv_expiry: u32) -> Self {
HolderHTLCOutput {
- preimage,
- amount
+ preimage: None,
+ amount,
+ cltv_expiry,
+ }
+ }
+
+ pub(crate) fn build_accepted(preimage: PaymentPreimage, amount: u64) -> Self {
+ HolderHTLCOutput {
+ preimage: Some(preimage),
+ amount,
+ cltv_expiry: 0,
}
}
}
impl_writeable_tlv_based!(HolderHTLCOutput, {
(0, amount),
+ (2, cltv_expiry),
}, {
- (2, preimage),
+ (4, preimage),
}, {});
/// A struct to describe the channel output on the funding transaction.
() => {
{
let preimage = PaymentPreimage([2;32]);
- PackageSolvingData::HolderHTLCOutput(HolderHTLCOutput::build(Some(preimage), 0))
+ PackageSolvingData::HolderHTLCOutput(HolderHTLCOutput::build_accepted(preimage, 0))
}
}
}