@@ -49,7 +49,7 @@ use routing::router::{Payee, Route, RouteHop, RoutePath, RouteParameters};
49
49
use ln:: msgs;
50
50
use ln:: msgs:: NetAddress ;
51
51
use ln:: onion_utils;
52
- use ln:: msgs:: { ChannelMessageHandler , DecodeError , LightningError , OptionalField } ;
52
+ use ln:: msgs:: { ChannelMessageHandler , DecodeError , LightningError , MAX_VALUE_MSAT , OptionalField } ;
53
53
use chain:: keysinterface:: { Sign , KeyMaterial , KeysInterface , KeysManager , InMemorySigner } ;
54
54
use util:: config:: UserConfig ;
55
55
use util:: events:: { EventHandler , EventsProvider , MessageSendEvent , MessageSendEventsProvider , ClosureReason } ;
@@ -4626,6 +4626,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4626
4626
fn set_payment_hash_secret_map ( & self , payment_hash : PaymentHash , payment_preimage : Option < PaymentPreimage > , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> Result < PaymentSecret , APIError > {
4627
4627
assert ! ( invoice_expiry_delta_secs <= 60 * 60 * 24 * 365 ) ; // Sadly bitcoin timestamps are u32s, so panic before 2106
4628
4628
4629
+ if min_value_msat. is_some ( ) && min_value_msat. unwrap ( ) > MAX_VALUE_MSAT {
4630
+ return Err ( APIError :: APIMisuseError { err : format ! ( "min_value_msat of {} greater than total 21 million bitcoin supply" , min_value_msat. unwrap( ) ) } ) ;
4631
+ }
4632
+
4629
4633
let payment_secret = PaymentSecret ( self . keys_manager . get_secure_random_bytes ( ) ) ;
4630
4634
4631
4635
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
@@ -4675,7 +4679,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4675
4679
/// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
4676
4680
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
4677
4681
// For details on the implementation of this method, see `verify_inbound_payment_data`.
4678
- pub fn create_inbound_payment ( & self , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> ( PaymentHash , PaymentSecret ) {
4682
+ pub fn create_inbound_payment ( & self , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> Result < ( PaymentHash , PaymentSecret ) , APIError > {
4683
+ if min_value_msat. is_some ( ) && min_value_msat. unwrap ( ) > MAX_VALUE_MSAT {
4684
+ return Err ( APIError :: APIMisuseError { err : format ! ( "min_value_msat of {} greater than total 21 million bitcoin supply" , min_value_msat. unwrap( ) ) } ) ;
4685
+ }
4686
+
4679
4687
let ( metadata_key, _, ldk_pmt_hash_key) = self . get_expanded_inbound_payment_key ( ) ;
4680
4688
let min_amt_msat_bytes: [ u8 ; 8 ] = match min_value_msat {
4681
4689
Some ( amt) => amt. to_be_bytes ( ) ,
@@ -4714,7 +4722,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4714
4722
}
4715
4723
4716
4724
let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage_bytes) . into_inner ( ) ) ;
4717
- ( payment_hash, PaymentSecret ( payment_secret_bytes) )
4725
+ Ok ( ( payment_hash, PaymentSecret ( payment_secret_bytes) ) )
4718
4726
}
4719
4727
4720
4728
/// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
@@ -4724,12 +4732,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4724
4732
/// This method will be deprecated in the next few versions.
4725
4733
///
4726
4734
/// [`create_inbound_payment`]: Self::create_inbound_payment
4727
- pub fn create_inbound_payment_legacy ( & self , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> ( PaymentHash , PaymentSecret ) {
4735
+ pub fn create_inbound_payment_legacy ( & self , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> Result < ( PaymentHash , PaymentSecret ) , APIError > {
4728
4736
let payment_preimage = PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ;
4729
4737
let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
4730
- ( payment_hash,
4731
- self . set_payment_hash_secret_map ( payment_hash, Some ( payment_preimage) , min_value_msat, invoice_expiry_delta_secs)
4732
- . expect ( "RNG Generated Duplicate PaymentHash" ) )
4738
+ let payment_secret = self . set_payment_hash_secret_map ( payment_hash, Some ( payment_preimage) , min_value_msat, invoice_expiry_delta_secs) ?;
4739
+ Ok ( ( payment_hash, payment_secret) )
4733
4740
}
4734
4741
4735
4742
/// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
@@ -4776,6 +4783,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4776
4783
/// [`PaymentReceived`]: events::Event::PaymentReceived
4777
4784
// For details on the implementation of this method, see `verify_inbound_payment_data`.
4778
4785
pub fn create_inbound_payment_for_hash ( & self , payment_hash : PaymentHash , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> Result < PaymentSecret , APIError > {
4786
+ if min_value_msat. is_some ( ) && min_value_msat. unwrap ( ) > MAX_VALUE_MSAT {
4787
+ return Err ( APIError :: APIMisuseError { err : format ! ( "min_value_msat of {} greater than total 21 million bitcoin supply" , min_value_msat. unwrap( ) ) } ) ;
4788
+ }
4789
+
4779
4790
let ( metadata_key, user_pmt_hash_key, _) = self . get_expanded_inbound_payment_key ( ) ;
4780
4791
let mut min_amt_msat_bytes: [ u8 ; 8 ] = match min_value_msat {
4781
4792
Some ( amt) => amt. to_be_bytes ( ) ,
0 commit comments