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