@@ -12,8 +12,9 @@ use std::time::Duration;
1212
1313use bitcoin:: secp256k1:: PublicKey ;
1414use bitcoin:: Network ;
15+ use lightning:: ln:: channelmanager:: { OptionalBolt11PaymentParams , OptionalOfferPaymentParams } ;
1516use lightning:: ln:: msgs:: SocketAddress ;
16- use lightning:: ln:: outbound_payment:: Retry ;
17+ use lightning:: ln:: outbound_payment:: { RecipientCustomTlvs , Retry } ;
1718use lightning:: routing:: gossip:: NodeAlias ;
1819use lightning:: routing:: router:: RouteParametersConfig ;
1920use lightning:: util:: config:: {
@@ -684,6 +685,136 @@ impl From<PaymentRetryStrategy> for Retry {
684685 }
685686}
686687
688+ /// Represents options which allow to override the default sending parameters for BOLT11 payments
689+ /// on a per-payment basis.
690+ ///
691+ /// These can be used to override the parameters set in [`Config::route_parameters`] and
692+ /// [`Config::payment_retry_strategy`].
693+ ///
694+ /// See [`OptionalBolt11PaymentParams`] for the underlying LDK type.
695+ #[ derive( Clone , Debug , Default ) ]
696+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
697+ pub struct Bolt11SendingParameters {
698+ /// Configuration options for payment routing and pathfinding.
699+ ///
700+ /// Setting the [`RouteParametersConfig`] provides flexibility to customize how payments are
701+ /// routed, including setting limits on routing fees, CLTV expiry, and channel utilization.
702+ ///
703+ /// If set, these will override the node-wide parameters configured via
704+ /// [`Config::route_parameters`] for this payment.
705+ pub route_parameters : Option < RouteParametersConfig > ,
706+ /// The strategy used when retrying failed payments.
707+ ///
708+ /// If set, this will override the node-wide retry strategy configured via
709+ /// [`Config::payment_retry_strategy`] for this payment.
710+ pub retry_strategy : Option < PaymentRetryStrategy > ,
711+ /// A set of custom TLVs to include in the onion message to the recipient.
712+ ///
713+ /// Each TLV is a `(type, value)` pair where the type number must be >= 2^16 (i.e., in the
714+ /// custom range) and unique. Invalid TLV types will be ignored.
715+ pub custom_tlvs : Option < Vec < CustomTlv > > ,
716+ /// If the payment being made from this node is part of a larger MPP payment from multiple
717+ /// nodes (i.e., because a single payment is being made from multiple wallets), you can specify
718+ /// the total amount being paid here.
719+ ///
720+ /// If set, it must be at least the amount of the invoice. Further, if set, the amount sent
721+ /// from this node may be lower than the invoice amount (as the payment from this node may be
722+ /// a small part of the total).
723+ pub declared_total_mpp_value_msat_override : Option < u64 > ,
724+ }
725+
726+ /// Represents options which allow to override the default sending parameters for BOLT12 payments
727+ /// on a per-payment basis.
728+ ///
729+ /// These can be used to override the parameters set in [`Config::route_parameters`] and
730+ /// [`Config::payment_retry_strategy`].
731+ ///
732+ /// See [`OptionalOfferPaymentParams`] for the underlying LDK type.
733+ #[ derive( Clone , Debug , Default ) ]
734+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
735+ pub struct Bolt12SendingParameters {
736+ /// Configuration options for payment routing and pathfinding.
737+ ///
738+ /// Setting the [`RouteParametersConfig`] provides flexibility to customize how payments are
739+ /// routed, including setting limits on routing fees, CLTV expiry, and channel utilization.
740+ ///
741+ /// If set, these will override the node-wide parameters configured via
742+ /// [`Config::route_parameters`] for this payment.
743+ pub route_parameters : Option < RouteParametersConfig > ,
744+ /// The strategy used when retrying failed payments.
745+ ///
746+ /// If set, this will override the node-wide retry strategy configured via
747+ /// [`Config::payment_retry_strategy`] for this payment.
748+ pub retry_strategy : Option < PaymentRetryStrategy > ,
749+ }
750+
751+ /// A custom TLV entry that can be included in the onion message to the recipient.
752+ ///
753+ /// TLV type numbers must be unique and >= 2^16 (in the custom range).
754+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
755+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
756+ pub struct CustomTlv {
757+ /// The type number for this TLV. Must be >= 2^16.
758+ pub tlv_type : u64 ,
759+ /// The serialized value for this TLV.
760+ pub value : Vec < u8 > ,
761+ }
762+
763+ impl Bolt11SendingParameters {
764+ pub ( crate ) fn into_ldk_params (
765+ params : Option < Self > , config : & Config ,
766+ ) -> OptionalBolt11PaymentParams {
767+ if let Some ( params) = params {
768+ let route_params_config =
769+ params. route_parameters . or ( config. route_parameters ) . unwrap_or_default ( ) ;
770+ let retry_strategy = params
771+ . retry_strategy
772+ . map ( Into :: into)
773+ . unwrap_or_else ( || config. payment_retry_strategy . into ( ) ) ;
774+ let custom_tlvs = params
775+ . custom_tlvs
776+ . map ( |tlvs| tlvs. into_iter ( ) . map ( |t| ( t. tlv_type , t. value ) ) . collect ( ) )
777+ . and_then ( |tlvs| RecipientCustomTlvs :: new ( tlvs) . ok ( ) )
778+ . unwrap_or_else ( || RecipientCustomTlvs :: new ( vec ! [ ] ) . unwrap ( ) ) ;
779+ OptionalBolt11PaymentParams {
780+ route_params_config,
781+ retry_strategy,
782+ custom_tlvs,
783+ declared_total_mpp_value_msat_override : params
784+ . declared_total_mpp_value_msat_override ,
785+ }
786+ } else {
787+ OptionalBolt11PaymentParams {
788+ route_params_config : config. route_parameters . unwrap_or_default ( ) ,
789+ retry_strategy : config. payment_retry_strategy . into ( ) ,
790+ ..Default :: default ( )
791+ }
792+ }
793+ }
794+ }
795+
796+ impl Bolt12SendingParameters {
797+ pub ( crate ) fn into_ldk_params (
798+ params : Option < Self > , payer_note : Option < String > , config : & Config ,
799+ ) -> OptionalOfferPaymentParams {
800+ if let Some ( params) = params {
801+ let route_params_config =
802+ params. route_parameters . or ( config. route_parameters ) . unwrap_or_default ( ) ;
803+ let retry_strategy = params
804+ . retry_strategy
805+ . map ( Into :: into)
806+ . unwrap_or_else ( || config. payment_retry_strategy . into ( ) ) ;
807+ OptionalOfferPaymentParams { payer_note, route_params_config, retry_strategy }
808+ } else {
809+ OptionalOfferPaymentParams {
810+ payer_note,
811+ route_params_config : config. route_parameters . unwrap_or_default ( ) ,
812+ retry_strategy : config. payment_retry_strategy . into ( ) ,
813+ }
814+ }
815+ }
816+ }
817+
687818#[ cfg( test) ]
688819mod tests {
689820 use std:: str:: FromStr ;
0 commit comments