@@ -29,50 +29,6 @@ use std::sync::Arc;
2929use tokio:: runtime:: Runtime ;
3030use tokio:: sync:: watch;
3131
32- impl From < PaymentStatus > for TxStatus {
33- fn from ( o : PaymentStatus ) -> TxStatus {
34- match o {
35- PaymentStatus :: Pending => TxStatus :: Pending ,
36- PaymentStatus :: Succeeded => TxStatus :: Completed ,
37- PaymentStatus :: Failed => TxStatus :: Failed ,
38- }
39- }
40- }
41-
42- impl From < & PaymentDetails > for PaymentType {
43- fn from ( d : & PaymentDetails ) -> PaymentType {
44- match ( & d. kind , d. direction == PaymentDirection :: Outbound ) {
45- (
46- PaymentKind :: Bolt11 { preimage, .. } | PaymentKind :: Bolt11Jit { preimage, .. } ,
47- true ,
48- ) => {
49- if d. status == PaymentStatus :: Succeeded {
50- debug_assert ! ( preimage. is_some( ) ) ;
51- }
52- PaymentType :: OutgoingLightningBolt11 { payment_preimage : * preimage }
53- } ,
54- ( PaymentKind :: Bolt12Offer { preimage, .. } , true ) => {
55- PaymentType :: OutgoingLightningBolt12 { payment_preimage : * preimage }
56- } ,
57- (
58- PaymentKind :: Bolt12Refund { preimage, .. }
59- | PaymentKind :: Spontaneous { preimage, .. } ,
60- true ,
61- ) => {
62- debug_assert ! ( false ) ;
63- PaymentType :: OutgoingLightningBolt12 { payment_preimage : * preimage }
64- } ,
65- ( PaymentKind :: Onchain { txid, .. } , true ) => {
66- PaymentType :: OutgoingOnChain { txid : Some ( * txid) }
67- } ,
68- ( PaymentKind :: Onchain { txid, .. } , false ) => {
69- PaymentType :: IncomingOnChain { txid : Some ( * txid) }
70- } ,
71- ( _, false ) => PaymentType :: IncomingLightning { } ,
72- }
73- }
74- }
75-
7632#[ derive( Debug , Clone , Copy ) ]
7733pub ( crate ) struct LightningWalletBalance {
7834 pub ( crate ) lightning : Amount ,
@@ -91,6 +47,8 @@ pub(crate) struct LightningWallet {
9147 pub ( crate ) inner : Arc < LightningWalletImpl > ,
9248}
9349
50+ const DEFAULT_INVOICE_EXPIRY_SECS : u32 = 86_400 ; // 24 hours
51+
9452impl LightningWallet {
9553 pub ( super ) async fn init < E > (
9654 runtime : Arc < Runtime > , config : WalletConfig < E > , store : Arc < dyn KVStore + Sync + Send > ,
@@ -240,24 +198,32 @@ impl LightningWallet {
240198 let desc = Bolt11InvoiceDescription :: Direct ( Description :: empty ( ) ) ;
241199 if let Some ( amt) = amount {
242200 if self . estimate_receivable_balance ( ) >= amt {
243- self . inner . ldk_node . bolt11_payment ( ) . receive ( amt. milli_sats ( ) , & desc, 86400 )
201+ self . inner . ldk_node . bolt11_payment ( ) . receive (
202+ amt. milli_sats ( ) ,
203+ & desc,
204+ DEFAULT_INVOICE_EXPIRY_SECS ,
205+ )
244206 } else {
245207 self . inner . ldk_node . bolt11_payment ( ) . receive_via_jit_channel (
246208 amt. milli_sats ( ) ,
247209 & desc,
248- 86400 ,
210+ DEFAULT_INVOICE_EXPIRY_SECS ,
249211 None ,
250212 )
251213 }
252- } else if self . estimate_receivable_balance ( )
214+ } else if self . estimate_receivable_balance ( ) // if we can receive at least 100k sats, don't use JIT
253215 >= Amount :: from_sats ( 100_000 ) . expect ( "valid amount" )
254216 {
255- self . inner . ldk_node . bolt11_payment ( ) . receive_variable_amount ( & desc, 86400 )
256- } else {
257217 self . inner
258218 . ldk_node
259219 . bolt11_payment ( )
260- . receive_variable_amount_via_jit_channel ( & desc, 86400 , None )
220+ . receive_variable_amount ( & desc, DEFAULT_INVOICE_EXPIRY_SECS )
221+ } else {
222+ self . inner . ldk_node . bolt11_payment ( ) . receive_variable_amount_via_jit_channel (
223+ & desc,
224+ DEFAULT_INVOICE_EXPIRY_SECS ,
225+ None ,
226+ )
261227 }
262228 }
263229
@@ -450,3 +416,47 @@ impl graduated_rebalancer::LightningWallet for LightningWallet {
450416 }
451417 }
452418}
419+
420+ impl From < PaymentStatus > for TxStatus {
421+ fn from ( o : PaymentStatus ) -> TxStatus {
422+ match o {
423+ PaymentStatus :: Pending => TxStatus :: Pending ,
424+ PaymentStatus :: Succeeded => TxStatus :: Completed ,
425+ PaymentStatus :: Failed => TxStatus :: Failed ,
426+ }
427+ }
428+ }
429+
430+ impl From < & PaymentDetails > for PaymentType {
431+ fn from ( d : & PaymentDetails ) -> PaymentType {
432+ match ( & d. kind , d. direction == PaymentDirection :: Outbound ) {
433+ (
434+ PaymentKind :: Bolt11 { preimage, .. } | PaymentKind :: Bolt11Jit { preimage, .. } ,
435+ true ,
436+ ) => {
437+ if d. status == PaymentStatus :: Succeeded {
438+ debug_assert ! ( preimage. is_some( ) ) ;
439+ }
440+ PaymentType :: OutgoingLightningBolt11 { payment_preimage : * preimage }
441+ } ,
442+ ( PaymentKind :: Bolt12Offer { preimage, .. } , true ) => {
443+ PaymentType :: OutgoingLightningBolt12 { payment_preimage : * preimage }
444+ } ,
445+ (
446+ PaymentKind :: Bolt12Refund { preimage, .. }
447+ | PaymentKind :: Spontaneous { preimage, .. } ,
448+ true ,
449+ ) => {
450+ debug_assert ! ( false ) ;
451+ PaymentType :: OutgoingLightningBolt12 { payment_preimage : * preimage }
452+ } ,
453+ ( PaymentKind :: Onchain { txid, .. } , true ) => {
454+ PaymentType :: OutgoingOnChain { txid : Some ( * txid) }
455+ } ,
456+ ( PaymentKind :: Onchain { txid, .. } , false ) => {
457+ PaymentType :: IncomingOnChain { txid : Some ( * txid) }
458+ } ,
459+ ( _, false ) => PaymentType :: IncomingLightning { } ,
460+ }
461+ }
462+ }
0 commit comments