@@ -39,7 +39,7 @@ impl_writeable_tlv_based!(PaymentDetails, {
3939} ) ;
4040
4141/// Represents the direction of a payment.
42- #[ derive( Clone , Debug , PartialEq , Eq ) ]
42+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
4343pub enum PaymentDirection {
4444 /// The payment is inbound.
4545 Inbound ,
@@ -53,7 +53,7 @@ impl_writeable_tlv_based_enum!(PaymentDirection,
5353) ;
5454
5555/// Represents the current status of a payment.
56- #[ derive( Clone , Debug , PartialEq , Eq ) ]
56+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
5757pub enum PaymentStatus {
5858 /// The payment is still pending.
5959 Pending ,
@@ -69,6 +69,29 @@ impl_writeable_tlv_based_enum!(PaymentStatus,
6969 ( 2 , Failed ) => { } ;
7070) ;
7171
72+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
73+ pub ( crate ) struct PaymentDetailsUpdate {
74+ pub hash : PaymentHash ,
75+ pub preimage : Option < Option < PaymentPreimage > > ,
76+ pub secret : Option < Option < PaymentSecret > > ,
77+ pub amount_msat : Option < Option < u64 > > ,
78+ pub direction : Option < PaymentDirection > ,
79+ pub status : Option < PaymentStatus > ,
80+ }
81+
82+ impl PaymentDetailsUpdate {
83+ pub fn new ( hash : PaymentHash ) -> Self {
84+ Self {
85+ hash,
86+ preimage : None ,
87+ secret : None ,
88+ amount_msat : None ,
89+ direction : None ,
90+ status : None ,
91+ }
92+ }
93+ }
94+
7295pub ( crate ) struct PaymentStore < K : Deref + Clone , L : Deref >
7396where
7497 K :: Target : KVStore ,
@@ -122,32 +145,28 @@ where
122145 self . payments . lock ( ) . unwrap ( ) . contains_key ( hash)
123146 }
124147
125- pub ( crate ) fn update (
126- & self , hash : & PaymentHash , update_preimage : Option < Option < PaymentPreimage > > ,
127- update_secret : Option < Option < PaymentSecret > > , update_amount_msat : Option < Option < u64 > > ,
128- update_status : Option < PaymentStatus > ,
129- ) -> Result < bool , Error > {
148+ pub ( crate ) fn update ( & self , update : & PaymentDetailsUpdate ) -> Result < bool , Error > {
130149 let mut updated = false ;
131150 let mut locked_payments = self . payments . lock ( ) . unwrap ( ) ;
132151
133- if let Some ( payment) = locked_payments. get_mut ( hash) {
134- if let Some ( preimage_opt) = update_preimage {
152+ if let Some ( payment) = locked_payments. get_mut ( & update . hash ) {
153+ if let Some ( preimage_opt) = update . preimage {
135154 payment. preimage = preimage_opt;
136155 }
137156
138- if let Some ( secret_opt) = update_secret {
157+ if let Some ( secret_opt) = update . secret {
139158 payment. secret = secret_opt;
140159 }
141160
142- if let Some ( amount_opt) = update_amount_msat {
161+ if let Some ( amount_opt) = update . amount_msat {
143162 payment. amount_msat = amount_opt;
144163 }
145164
146- if let Some ( status) = update_status {
165+ if let Some ( status) = update . status {
147166 payment. status = status;
148167 }
149168
150- self . write_info_and_commit ( hash, payment) ?;
169+ self . write_info_and_commit ( & update . hash , payment) ?;
151170 updated = true ;
152171 }
153172
@@ -237,10 +256,9 @@ mod tests {
237256 assert_eq ! ( Ok ( true ) , payment_store. insert( payment) ) ;
238257 assert ! ( store. get_and_clear_did_persist( ) ) ;
239258
240- assert_eq ! (
241- Ok ( true ) ,
242- payment_store. update( & hash, None , None , None , Some ( PaymentStatus :: Succeeded ) )
243- ) ;
259+ let mut update = PaymentDetailsUpdate :: new ( hash) ;
260+ update. status = Some ( PaymentStatus :: Succeeded ) ;
261+ assert_eq ! ( Ok ( true ) , payment_store. update( & update) ) ;
244262 assert ! ( store. get_and_clear_did_persist( ) ) ;
245263
246264 assert_eq ! ( PaymentStatus :: Succeeded , payment_store. get( & hash) . unwrap( ) . status) ;
0 commit comments