@@ -22,17 +22,20 @@ use bitcoin::hashes::Hash;
2222use bitcoin:: secp256k1:: PublicKey ;
2323pub use bitcoin:: { Address , BlockHash , FeeRate , Network , OutPoint , ScriptBuf , Txid } ;
2424pub use lightning:: chain:: channelmonitor:: BalanceSource ;
25+ use lightning:: events:: PaidBolt12Invoice as LdkPaidBolt12Invoice ;
2526pub use lightning:: events:: { ClosureReason , PaymentFailureReason } ;
2627use lightning:: ln:: channelmanager:: PaymentId ;
28+ use lightning:: ln:: msgs:: DecodeError ;
2729pub use lightning:: ln:: types:: ChannelId ;
2830use lightning:: offers:: invoice:: Bolt12Invoice as LdkBolt12Invoice ;
2931pub use lightning:: offers:: offer:: OfferId ;
3032use lightning:: offers:: offer:: { Amount as LdkAmount , Offer as LdkOffer } ;
3133use lightning:: offers:: refund:: Refund as LdkRefund ;
34+ use lightning:: offers:: static_invoice:: StaticInvoice as LdkStaticInvoice ;
3235use lightning:: onion_message:: dns_resolution:: HumanReadableName as LdkHumanReadableName ;
3336pub use lightning:: routing:: gossip:: { NodeAlias , NodeId , RoutingFees } ;
3437pub use lightning:: routing:: router:: RouteParametersConfig ;
35- use lightning:: util:: ser:: Writeable ;
38+ use lightning:: util:: ser:: { Readable , Writeable , Writer } ;
3639use lightning_invoice:: { Bolt11Invoice as LdkBolt11Invoice , Bolt11InvoiceDescriptionRef } ;
3740pub use lightning_invoice:: { Description , SignedRawBolt11Invoice } ;
3841pub use lightning_liquidity:: lsps0:: ser:: LSPSDateTime ;
@@ -775,6 +778,100 @@ impl AsRef<LdkBolt12Invoice> for Bolt12Invoice {
775778 }
776779}
777780
781+ /// A static invoice used for async payments.
782+ ///
783+ /// Static invoices are a special type of BOLT12 invoice where proof of payment is not possible,
784+ /// as the payment hash is not derived from a preimage known only to the recipient.
785+ #[ derive( Debug , Clone , PartialEq , Eq , uniffi:: Object ) ]
786+ pub struct StaticInvoice {
787+ pub ( crate ) inner : LdkStaticInvoice ,
788+ }
789+
790+ #[ uniffi:: export]
791+ impl StaticInvoice {
792+ /// The amount for a successful payment of the invoice, if specified.
793+ pub fn amount ( & self ) -> Option < OfferAmount > {
794+ self . inner . amount ( ) . map ( |amount| amount. into ( ) )
795+ }
796+ }
797+
798+ impl From < LdkStaticInvoice > for StaticInvoice {
799+ fn from ( invoice : LdkStaticInvoice ) -> Self {
800+ StaticInvoice { inner : invoice }
801+ }
802+ }
803+
804+ impl Deref for StaticInvoice {
805+ type Target = LdkStaticInvoice ;
806+ fn deref ( & self ) -> & Self :: Target {
807+ & self . inner
808+ }
809+ }
810+
811+ impl AsRef < LdkStaticInvoice > for StaticInvoice {
812+ fn as_ref ( & self ) -> & LdkStaticInvoice {
813+ self . deref ( )
814+ }
815+ }
816+
817+ /// The BOLT12 invoice that was paid, surfaced in [`Event::PaymentSuccessful`].
818+ ///
819+ /// [`Event::PaymentSuccessful`]: crate::Event::PaymentSuccessful
820+ ///
821+ /// Note: The variant names intentionally differ from their contained types to avoid
822+ /// name collisions in Kotlin codegen, where sealed class inner classes would shadow
823+ /// top-level types of the same name.
824+ #[ derive( Debug , Clone , PartialEq , Eq , uniffi:: Enum ) ]
825+ pub enum PaidBolt12Invoice {
826+ /// The BOLT12 invoice, allowing the user to perform proof of payment.
827+ Bolt12 ( Arc < Bolt12Invoice > ) ,
828+ /// The static invoice, used in async payments, where the user cannot perform proof of
829+ /// payment.
830+ Static ( Arc < StaticInvoice > ) ,
831+ }
832+
833+ impl From < LdkPaidBolt12Invoice > for PaidBolt12Invoice {
834+ fn from ( ldk : LdkPaidBolt12Invoice ) -> Self {
835+ match ldk {
836+ LdkPaidBolt12Invoice :: Bolt12Invoice ( invoice) => {
837+ PaidBolt12Invoice :: Bolt12 ( Arc :: new ( Bolt12Invoice :: from ( invoice) ) )
838+ } ,
839+ LdkPaidBolt12Invoice :: StaticInvoice ( invoice) => {
840+ PaidBolt12Invoice :: Static ( Arc :: new ( StaticInvoice :: from ( invoice) ) )
841+ } ,
842+ }
843+ }
844+ }
845+
846+ impl From < PaidBolt12Invoice > for LdkPaidBolt12Invoice {
847+ fn from ( wrapper : PaidBolt12Invoice ) -> Self {
848+ match wrapper {
849+ PaidBolt12Invoice :: Bolt12 ( invoice) => {
850+ LdkPaidBolt12Invoice :: Bolt12Invoice ( invoice. inner . clone ( ) )
851+ } ,
852+ PaidBolt12Invoice :: Static ( invoice) => {
853+ LdkPaidBolt12Invoice :: StaticInvoice ( invoice. inner . clone ( ) )
854+ } ,
855+ }
856+ }
857+ }
858+
859+ impl Writeable for PaidBolt12Invoice {
860+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , lightning:: io:: Error > {
861+ // We clone `self` to convert it into the LDK native type for serialization.
862+ // This only runs during event persistence, so the overhead is acceptable.
863+ let ldk_type: LdkPaidBolt12Invoice = self . clone ( ) . into ( ) ;
864+ ldk_type. write ( w)
865+ }
866+ }
867+
868+ impl Readable for PaidBolt12Invoice {
869+ fn read < R : lightning:: io:: Read > ( r : & mut R ) -> Result < Self , DecodeError > {
870+ let ldk_type = LdkPaidBolt12Invoice :: read ( r) ?;
871+ Ok ( ldk_type. into ( ) )
872+ }
873+ }
874+
778875uniffi:: custom_type!( OfferId , String , {
779876 remote,
780877 try_lift: |val| {
0 commit comments