+/// The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
+/// their BOLT12 [`Invoice`].
+///
+/// [`Invoice`]: crate::offers::invoice::Invoice
+#[derive(Clone, Debug, Hash, PartialEq, Eq)]
+pub struct BlindedTail {
+ /// The hops of the [`BlindedPath`] provided by the recipient.
+ ///
+ /// [`BlindedPath`]: crate::blinded_path::BlindedPath
+ pub hops: Vec<BlindedHop>,
+ /// The blinding point of the [`BlindedPath`] provided by the recipient.
+ ///
+ /// [`BlindedPath`]: crate::blinded_path::BlindedPath
+ pub blinding_point: PublicKey,
+ /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
+ /// inferring the destination. May be 0.
+ pub excess_final_cltv_expiry_delta: u32,
+ /// The total amount paid on this [`Path`], excluding the fees.
+ pub final_value_msat: u64,
+}
+
+impl_writeable_tlv_based!(BlindedTail, {
+ (0, hops, vec_type),
+ (2, blinding_point, required),
+ (4, excess_final_cltv_expiry_delta, required),
+ (6, final_value_msat, required),
+});
+
+/// A path in a [`Route`] to the payment recipient. Must always be at least length one.
+/// If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
+#[derive(Clone, Debug, Hash, PartialEq, Eq)]
+pub struct Path {
+ /// The list of unblinded hops in this [`Path`]. Must be at least length one.
+ pub hops: Vec<RouteHop>,
+ /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
+ pub blinded_tail: Option<BlindedTail>,
+}
+
+impl Path {
+ /// Gets the fees for a given path, excluding any excess paid to the recipient.
+ pub fn fee_msat(&self) -> u64 {
+ match &self.blinded_tail {
+ Some(_) => self.hops.iter().map(|hop| hop.fee_msat).sum::<u64>(),
+ None => {
+ // Do not count last hop of each path since that's the full value of the payment
+ self.hops.split_last().map_or(0,
+ |(_, path_prefix)| path_prefix.iter().map(|hop| hop.fee_msat).sum())
+ }
+ }
+ }
+
+ /// Gets the total amount paid on this [`Path`], excluding the fees.
+ pub fn final_value_msat(&self) -> u64 {
+ match &self.blinded_tail {
+ Some(blinded_tail) => blinded_tail.final_value_msat,
+ None => self.hops.last().map_or(0, |hop| hop.fee_msat)
+ }
+ }
+
+ /// Gets the final hop's CLTV expiry delta.
+ pub fn final_cltv_expiry_delta(&self) -> Option<u32> {
+ match &self.blinded_tail {
+ Some(_) => None,
+ None => self.hops.last().map(|hop| hop.cltv_expiry_delta)
+ }
+ }
+}
+