Skip to content

Commit 7221a70

Browse files
committed
Expose the timelock of transaction packages
1 parent dd87fd3 commit 7221a70

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lightning/src/chain/package.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,17 @@ impl PackageSolvingData {
387387
_ => { panic!("API Error!"); }
388388
}
389389
}
390+
fn absolute_tx_timelock(&self, input_height: u32) -> u32 {
391+
let amt = match self {
392+
PackageSolvingData::RevokedOutput(_) => input_height + 1,
393+
PackageSolvingData::RevokedHTLCOutput(_) => input_height + 1,
394+
PackageSolvingData::CounterpartyOfferedHTLCOutput(ref outp) => input_height + 1,
395+
PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => std::cmp::max(outp.htlc.cltv_expiry, input_height + 1),
396+
PackageSolvingData::HolderHTLCOutput(ref outp) => std::cmp::max(outp.cltv_expiry, input_height + 1),
397+
PackageSolvingData::HolderFundingOutput(_) => input_height + 1,
398+
};
399+
amt
400+
}
390401
}
391402

392403
impl Writeable for PackageSolvingData {
@@ -598,6 +609,13 @@ impl PackageTemplate {
598609
}
599610
amounts
600611
}
612+
pub(crate) fn package_timelock(&self) -> u32 {
613+
let mut max_locktime = 0;
614+
for (_, outp) in self.inputs.iter() {
615+
max_locktime = std::cmp::max(max_locktime, outp.absolute_tx_timelock(self.height_original));
616+
}
617+
max_locktime
618+
}
601619
pub(crate) fn package_weight(&self, destination_script: &Script) -> usize {
602620
let mut inputs_weight = 0;
603621
let mut witnesses_weight = 2; // count segwit flags

0 commit comments

Comments
 (0)