@@ -32,6 +32,7 @@ pub struct PaymentInfo {
32
32
pub secret : Option < [ u8 ; 32 ] > ,
33
33
pub status : HTLCStatus ,
34
34
#[ serde( skip_serializing_if = "MillisatAmount::is_none" ) ]
35
+ #[ serde( default ) ]
35
36
pub amt_msat : MillisatAmount ,
36
37
#[ serde( skip_serializing_if = "Option::is_none" ) ]
37
38
pub fee_paid_msat : Option < u64 > ,
@@ -44,7 +45,7 @@ pub struct PaymentInfo {
44
45
pub last_update : u64 ,
45
46
}
46
47
47
- #[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
48
+ #[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash , Default ) ]
48
49
pub struct MillisatAmount ( pub Option < u64 > ) ;
49
50
50
51
impl MillisatAmount {
@@ -914,6 +915,7 @@ mod test {
914
915
use crate :: event:: { HTLCStatus , MillisatAmount , PaymentInfo } ;
915
916
use crate :: { utils, PrivacyLevel } ;
916
917
use bitcoin:: secp256k1:: PublicKey ;
918
+ use lightning_invoice:: Bolt11Invoice ;
917
919
use std:: str:: FromStr ;
918
920
919
921
use wasm_bindgen_test:: { wasm_bindgen_test as test, wasm_bindgen_test_configure} ;
@@ -947,4 +949,32 @@ mod test {
947
949
let deserialized: PaymentInfo = serde_json:: from_value ( serialized) . unwrap ( ) ;
948
950
assert_eq ! ( payment_info, deserialized) ;
949
951
}
952
+
953
+ #[ test]
954
+ fn test_payment_info_without_amount ( ) {
955
+ let pubkey = PublicKey :: from_str (
956
+ "02465ed5be53d04fde66c9418ff14a5f2267723810176c9212b722e542dc1afb1b" ,
957
+ )
958
+ . unwrap ( ) ;
959
+
960
+ let payment_info = PaymentInfo {
961
+ preimage : None ,
962
+ status : HTLCStatus :: Succeeded ,
963
+ privacy_level : PrivacyLevel :: Anonymous ,
964
+ amt_msat : MillisatAmount ( None ) ,
965
+ fee_paid_msat : None ,
966
+ bolt11 : Some ( Bolt11Invoice :: from_str ( "lntb1pnmghqhdqqnp4qty5slw3t6d6gt43tndkq6p6ut9ewrqrfq2nj67wnmk6dqzefweqcpp5fk6cxcwnjdrzw5zm9mzjuhfrwnee3feewmtycj5nk7klngava7gqsp5qajl23w8dluhxn90duny44ar0syrxqa4w3ap8635aat78lvdvfds9qyysgqcqzptxqyz5vqrzjqg7s0fwc76ky6umpgeuh7p7qm4l4jljw0uxa3uu5vrupjzjlpeny0apyqqqqqqqqsgqqqqlgqqqqlgqqjqr5p4cd64qa80ksthgdff908gxmjwvrwwmhnxnxlsrc0c2weuzcw3kthknu6cgalqdk0cnqsugvmcz9dvgr5l9rtphgm37ycg362s9sspwvxmj0" ) . unwrap ( ) ) ,
967
+ payee_pubkey : Some ( pubkey) ,
968
+ secret : None ,
969
+ last_update : utils:: now ( ) . as_secs ( ) ,
970
+ } ;
971
+
972
+ let serialized = serde_json:: to_string ( & payment_info) . unwrap ( ) ;
973
+ let deserialized: PaymentInfo = serde_json:: from_str ( & serialized) . unwrap ( ) ;
974
+ assert_eq ! ( payment_info, deserialized) ;
975
+
976
+ let serialized = serde_json:: to_value ( & payment_info) . unwrap ( ) ;
977
+ let deserialized: PaymentInfo = serde_json:: from_value ( serialized) . unwrap ( ) ;
978
+ assert_eq ! ( payment_info, deserialized) ;
979
+ }
950
980
}
0 commit comments