+ let mut payment_params = None;
+ read_tlv_fields!(reader, {
+ (1, payment_params, option),
+ });
+ Ok(Route { paths, payment_params })
+ }
+}
+
+/// Parameters needed to find a [`Route`].
+///
+/// Passed to [`find_route`] and also provided in [`Event::PaymentPathFailed`] for retrying a failed
+/// payment path.
+///
+/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
+#[derive(Clone, Debug)]
+pub struct RouteParameters {
+ /// The parameters of the failed payment path.
+ pub payment_params: PaymentParameters,
+
+ /// The amount in msats sent on the failed payment path.
+ pub final_value_msat: u64,
+
+ /// The CLTV on the final hop of the failed payment path.
+ pub final_cltv_expiry_delta: u32,
+}
+
+impl_writeable_tlv_based!(RouteParameters, {
+ (0, payment_params, required),
+ (2, final_value_msat, required),
+ (4, final_cltv_expiry_delta, required),
+});
+
+/// Maximum total CTLV difference we allow for a full payment path.
+pub const DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = 1008;
+
+/// The recipient of a payment.
+#[derive(Clone, Debug, Hash, PartialEq, Eq)]
+pub struct PaymentParameters {
+ /// The node id of the payee.
+ pub payee_pubkey: PublicKey,
+
+ /// Features supported by the payee.
+ ///
+ /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
+ /// does not contain any features.
+ ///
+ /// [`for_keysend`]: Self::for_keysend
+ pub features: Option<InvoiceFeatures>,
+
+ /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
+ pub route_hints: Vec<RouteHint>,
+
+ /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
+ pub expiry_time: Option<u64>,
+
+ /// The maximum total CLTV delta we accept for the route.
+ pub max_total_cltv_expiry_delta: u32,
+}
+
+impl_writeable_tlv_based!(PaymentParameters, {
+ (0, payee_pubkey, required),
+ (1, max_total_cltv_expiry_delta, (default_value, DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA)),
+ (2, features, option),
+ (4, route_hints, vec_type),
+ (6, expiry_time, option),
+});
+
+impl PaymentParameters {
+ /// Creates a payee with the node id of the given `pubkey`.
+ pub fn from_node_id(payee_pubkey: PublicKey) -> Self {
+ Self {
+ payee_pubkey,
+ features: None,
+ route_hints: vec![],
+ expiry_time: None,
+ max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA,
+ }
+ }
+
+ /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
+ pub fn for_keysend(payee_pubkey: PublicKey) -> Self {
+ Self::from_node_id(payee_pubkey).with_features(InvoiceFeatures::for_keysend())
+ }
+
+ /// Includes the payee's features.
+ ///
+ /// (C-not exported) since bindings don't support move semantics
+ pub fn with_features(self, features: InvoiceFeatures) -> Self {
+ Self { features: Some(features), ..self }
+ }
+
+ /// Includes hints for routing to the payee.
+ ///
+ /// (C-not exported) since bindings don't support move semantics
+ pub fn with_route_hints(self, route_hints: Vec<RouteHint>) -> Self {
+ Self { route_hints, ..self }
+ }
+
+ /// Includes a payment expiration in seconds relative to the UNIX epoch.
+ ///
+ /// (C-not exported) since bindings don't support move semantics
+ pub fn with_expiry_time(self, expiry_time: u64) -> Self {
+ Self { expiry_time: Some(expiry_time), ..self }
+ }
+
+ /// Includes a limit for the total CLTV expiry delta which is considered during routing
+ ///
+ /// (C-not exported) since bindings don't support move semantics
+ pub fn with_max_total_cltv_expiry_delta(self, max_total_cltv_expiry_delta: u32) -> Self {
+ Self { max_total_cltv_expiry_delta, ..self }