@@ -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 } ;
@@ -4648,6 +4648,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4648
4648
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 > {
4649
4649
assert ! ( invoice_expiry_delta_secs <= 60 * 60 * 24 * 365 ) ; // Sadly bitcoin timestamps are u32s, so panic before 2106
4650
4650
4651
+ if min_value_msat. is_some ( ) && min_value_msat. unwrap ( ) > MAX_VALUE_MSAT {
4652
+ return Err ( APIError :: APIMisuseError { err : format ! ( "min_value_msat of {} greater than total 21 million bitcoin supply" , min_value_msat. unwrap( ) ) } ) ;
4653
+ }
4654
+
4651
4655
let payment_secret = PaymentSecret ( self . keys_manager . get_secure_random_bytes ( ) ) ;
4652
4656
4653
4657
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
@@ -4697,7 +4701,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4697
4701
/// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
4698
4702
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
4699
4703
// For details on the implementation of this method, see `verify_inbound_payment_data`.
4700
- pub fn create_inbound_payment ( & self , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> ( PaymentHash , PaymentSecret ) {
4704
+ pub fn create_inbound_payment ( & self , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> Result < ( PaymentHash , PaymentSecret ) , APIError > {
4705
+ if min_value_msat. is_some ( ) && min_value_msat. unwrap ( ) > MAX_VALUE_MSAT {
4706
+ return Err ( APIError :: APIMisuseError { err : format ! ( "min_value_msat of {} greater than total 21 million bitcoin supply" , min_value_msat. unwrap( ) ) } ) ;
4707
+ }
4708
+
4701
4709
let min_amt_msat_bytes: [ u8 ; 8 ] = match min_value_msat {
4702
4710
Some ( amt) => amt. to_be_bytes ( ) ,
4703
4711
None => [ 0 ; 8 ] ,
@@ -4735,7 +4743,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4735
4743
}
4736
4744
4737
4745
let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage_bytes) . into_inner ( ) ) ;
4738
- ( payment_hash, PaymentSecret ( payment_secret_bytes) )
4746
+ Ok ( ( payment_hash, PaymentSecret ( payment_secret_bytes) ) )
4739
4747
}
4740
4748
4741
4749
/// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
@@ -4745,12 +4753,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4745
4753
/// This method will be deprecated in the next few versions.
4746
4754
///
4747
4755
/// [`create_inbound_payment`]: Self::create_inbound_payment
4748
- pub fn create_inbound_payment_legacy ( & self , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> ( PaymentHash , PaymentSecret ) {
4756
+ pub fn create_inbound_payment_legacy ( & self , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> Result < ( PaymentHash , PaymentSecret ) , APIError > {
4749
4757
let payment_preimage = PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ;
4750
4758
let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
4751
- ( payment_hash,
4752
- self . set_payment_hash_secret_map ( payment_hash, Some ( payment_preimage) , min_value_msat, invoice_expiry_delta_secs)
4753
- . expect ( "RNG Generated Duplicate PaymentHash" ) )
4759
+ let payment_secret = self . set_payment_hash_secret_map ( payment_hash, Some ( payment_preimage) , min_value_msat, invoice_expiry_delta_secs) ?;
4760
+ Ok ( ( payment_hash, payment_secret) )
4754
4761
}
4755
4762
4756
4763
/// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
@@ -4797,6 +4804,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4797
4804
/// [`PaymentReceived`]: events::Event::PaymentReceived
4798
4805
// For details on the implementation of this method, see `verify_inbound_payment_data`.
4799
4806
pub fn create_inbound_payment_for_hash ( & self , payment_hash : PaymentHash , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ) -> Result < PaymentSecret , APIError > {
4807
+ if min_value_msat. is_some ( ) && min_value_msat. unwrap ( ) > MAX_VALUE_MSAT {
4808
+ return Err ( APIError :: APIMisuseError { err : format ! ( "min_value_msat of {} greater than total 21 million bitcoin supply" , min_value_msat. unwrap( ) ) } ) ;
4809
+ }
4810
+
4800
4811
let mut min_amt_msat_bytes: [ u8 ; 8 ] = match min_value_msat {
4801
4812
Some ( amt) => amt. to_be_bytes ( ) ,
4802
4813
None => [ 0 ; 8 ] ,
0 commit comments