1010//
1111// Make sure to add any re-exported items that need to be used in uniffi below.
1212
13+ use std:: collections:: HashMap ;
1314use std:: convert:: TryInto ;
1415use std:: ops:: Deref ;
1516use std:: str:: FromStr ;
@@ -22,17 +23,20 @@ use bitcoin::hashes::Hash;
2223use bitcoin:: secp256k1:: PublicKey ;
2324pub use bitcoin:: { Address , BlockHash , FeeRate , Network , OutPoint , ScriptBuf , Txid } ;
2425pub use lightning:: chain:: channelmonitor:: BalanceSource ;
26+ use lightning:: events:: PaidBolt12Invoice as LdkPaidBolt12Invoice ;
2527pub use lightning:: events:: { ClosureReason , PaymentFailureReason } ;
2628use lightning:: ln:: channelmanager:: PaymentId ;
29+ use lightning:: ln:: msgs:: DecodeError ;
2730pub use lightning:: ln:: types:: ChannelId ;
2831use lightning:: offers:: invoice:: Bolt12Invoice as LdkBolt12Invoice ;
2932pub use lightning:: offers:: offer:: OfferId ;
3033use lightning:: offers:: offer:: { Amount as LdkAmount , Offer as LdkOffer } ;
3134use lightning:: offers:: refund:: Refund as LdkRefund ;
35+ use lightning:: offers:: static_invoice:: StaticInvoice as LdkStaticInvoice ;
3236use lightning:: onion_message:: dns_resolution:: HumanReadableName as LdkHumanReadableName ;
3337pub use lightning:: routing:: gossip:: { NodeAlias , NodeId , RoutingFees } ;
3438pub use lightning:: routing:: router:: RouteParametersConfig ;
35- use lightning:: util:: ser:: Writeable ;
39+ use lightning:: util:: ser:: { Readable , Writeable , Writer } ;
3640use lightning_invoice:: { Bolt11Invoice as LdkBolt11Invoice , Bolt11InvoiceDescriptionRef } ;
3741pub use lightning_invoice:: { Description , SignedRawBolt11Invoice } ;
3842pub use lightning_liquidity:: lsps0:: ser:: LSPSDateTime ;
@@ -41,10 +45,10 @@ pub use lightning_liquidity::lsps1::msgs::{
4145} ;
4246pub use lightning_types:: payment:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
4347pub use lightning_types:: string:: UntrustedString ;
44- use std :: collections :: HashMap ;
45-
46- use vss_client :: headers :: VssHeaderProvider as VssClientHeaderProvider ;
47- use vss_client :: headers :: VssHeaderProviderError as VssClientHeaderProviderError ;
48+ use vss_client :: headers :: {
49+ VssHeaderProvider as VssClientHeaderProvider ,
50+ VssHeaderProviderError as VssClientHeaderProviderError ,
51+ } ;
4852
4953/// Errors around providing headers for each VSS request.
5054#[ derive( Debug , uniffi:: Error ) ]
@@ -775,6 +779,95 @@ impl AsRef<LdkBolt12Invoice> for Bolt12Invoice {
775779 }
776780}
777781
782+ /// A static invoice used for async payments.
783+ ///
784+ /// Static invoices are a special type of BOLT12 invoice where proof of payment is not possible,
785+ /// as the payment hash is not derived from a preimage known only to the recipient.
786+ #[ derive( Debug , Clone , PartialEq , Eq , uniffi:: Object ) ]
787+ pub struct StaticInvoice {
788+ pub ( crate ) inner : LdkStaticInvoice ,
789+ }
790+
791+ #[ uniffi:: export]
792+ impl StaticInvoice {
793+ /// The amount for a successful payment of the invoice, if specified.
794+ pub fn amount ( & self ) -> Option < OfferAmount > {
795+ self . inner . amount ( ) . map ( |amount| amount. into ( ) )
796+ }
797+ }
798+
799+ impl From < LdkStaticInvoice > for StaticInvoice {
800+ fn from ( invoice : LdkStaticInvoice ) -> Self {
801+ StaticInvoice { inner : invoice }
802+ }
803+ }
804+
805+ impl Deref for StaticInvoice {
806+ type Target = LdkStaticInvoice ;
807+ fn deref ( & self ) -> & Self :: Target {
808+ & self . inner
809+ }
810+ }
811+
812+ impl AsRef < LdkStaticInvoice > for StaticInvoice {
813+ fn as_ref ( & self ) -> & LdkStaticInvoice {
814+ self . deref ( )
815+ }
816+ }
817+
818+ /// The BOLT12 invoice that was paid, surfaced in [`Event::PaymentSuccessful`].
819+ ///
820+ /// [`Event::PaymentSuccessful`]: crate::Event::PaymentSuccessful
821+ #[ derive( Debug , Clone , PartialEq , Eq , uniffi:: Enum ) ]
822+ pub enum PaidBolt12Invoice {
823+ /// The BOLT12 invoice, allowing the user to perform proof of payment.
824+ Bolt12 ( Arc < Bolt12Invoice > ) ,
825+ /// The static invoice, used in async payments, where the user cannot perform proof of
826+ /// payment.
827+ Static ( Arc < StaticInvoice > ) ,
828+ }
829+
830+ impl From < LdkPaidBolt12Invoice > for PaidBolt12Invoice {
831+ fn from ( ldk : LdkPaidBolt12Invoice ) -> Self {
832+ match ldk {
833+ LdkPaidBolt12Invoice :: Bolt12Invoice ( invoice) => {
834+ PaidBolt12Invoice :: Bolt12 ( Arc :: new ( Bolt12Invoice :: from ( invoice) ) )
835+ } ,
836+ LdkPaidBolt12Invoice :: StaticInvoice ( invoice) => {
837+ PaidBolt12Invoice :: Static ( Arc :: new ( StaticInvoice :: from ( invoice) ) )
838+ } ,
839+ }
840+ }
841+ }
842+
843+ impl From < PaidBolt12Invoice > for LdkPaidBolt12Invoice {
844+ fn from ( wrapper : PaidBolt12Invoice ) -> Self {
845+ match wrapper {
846+ PaidBolt12Invoice :: Bolt12 ( invoice) => {
847+ LdkPaidBolt12Invoice :: Bolt12Invoice ( invoice. inner . clone ( ) )
848+ } ,
849+ PaidBolt12Invoice :: Static ( invoice) => {
850+ LdkPaidBolt12Invoice :: StaticInvoice ( invoice. inner . clone ( ) )
851+ } ,
852+ }
853+ }
854+ }
855+
856+ impl Writeable for PaidBolt12Invoice {
857+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , lightning:: io:: Error > {
858+ // TODO: Find way to avoid cloning invoice data.
859+ let ldk_type: LdkPaidBolt12Invoice = self . clone ( ) . into ( ) ;
860+ ldk_type. write ( w)
861+ }
862+ }
863+
864+ impl Readable for PaidBolt12Invoice {
865+ fn read < R : lightning:: io:: Read > ( r : & mut R ) -> Result < Self , DecodeError > {
866+ let ldk_type = LdkPaidBolt12Invoice :: read ( r) ?;
867+ Ok ( ldk_type. into ( ) )
868+ }
869+ }
870+
778871uniffi:: custom_type!( OfferId , String , {
779872 remote,
780873 try_lift: |val| {
0 commit comments