@@ -47,6 +47,7 @@ use crate::{
4747 AccountId ,
4848 ArcSwapOption ,
4949 Error ,
50+ Hbar ,
5051 LedgerId ,
5152 NodeAddressBook ,
5253 PrivateKey ,
@@ -86,6 +87,7 @@ struct ClientBuilder {
8687 network : ManagedNetwork ,
8788 operator : Option < Operator > ,
8889 max_transaction_fee : Option < NonZeroU64 > ,
90+ max_query_payment : Option < NonZeroU64 > ,
8991 ledger_id : Option < LedgerId > ,
9092 auto_validate_checksums : bool ,
9193 regenerate_transaction_ids : bool ,
@@ -100,6 +102,7 @@ impl ClientBuilder {
100102 network,
101103 operator : None ,
102104 max_transaction_fee : None ,
105+ max_query_payment : None ,
103106 ledger_id : None ,
104107 auto_validate_checksums : false ,
105108 regenerate_transaction_ids : true ,
@@ -121,6 +124,7 @@ impl ClientBuilder {
121124 network,
122125 operator,
123126 max_transaction_fee,
127+ max_query_payment,
124128 ledger_id,
125129 auto_validate_checksums,
126130 regenerate_transaction_ids,
@@ -143,6 +147,9 @@ impl ClientBuilder {
143147 max_transaction_fee_tinybar : AtomicU64 :: new (
144148 max_transaction_fee. map ( NonZeroU64 :: get) . unwrap_or ( 0 ) ,
145149 ) ,
150+ max_query_payment_tinybar : AtomicU64 :: new (
151+ max_query_payment. map ( NonZeroU64 :: get) . unwrap_or ( 0 ) ,
152+ ) ,
146153 ledger_id : ArcSwapOption :: new ( ledger_id. map ( Arc :: new) ) ,
147154 auto_validate_checksums : AtomicBool :: new ( auto_validate_checksums) ,
148155 regenerate_transaction_ids : AtomicBool :: new ( regenerate_transaction_ids) ,
@@ -156,6 +163,7 @@ struct ClientInner {
156163 network : ManagedNetwork ,
157164 operator : ArcSwapOption < Operator > ,
158165 max_transaction_fee_tinybar : AtomicU64 ,
166+ max_query_payment_tinybar : AtomicU64 ,
159167 ledger_id : ArcSwapOption < LedgerId > ,
160168 auto_validate_checksums : AtomicBool ,
161169 regenerate_transaction_ids : AtomicBool ,
@@ -410,9 +418,38 @@ impl Client {
410418 & self . 0 . network . mirror
411419 }
412420
421+ /// Sets the maximum transaction fee to be used when no explicit max transaction fee is set.
422+ ///
423+ /// Note: Setting `amount` to zero is "unlimited"
424+ /// # Panics
425+ /// - if amount is negative
426+ pub fn set_default_max_transaction_fee ( & self , amount : Hbar ) {
427+ assert ! ( amount >= Hbar :: ZERO ) ;
428+ self . 0 . max_transaction_fee_tinybar . store ( amount. to_tinybars ( ) as u64 , Ordering :: Relaxed )
429+ }
430+
413431 /// Gets the maximum transaction fee the paying account is willing to pay.
414- pub ( crate ) fn max_transaction_fee ( & self ) -> & AtomicU64 {
415- & self . 0 . max_transaction_fee_tinybar
432+ pub fn default_max_transaction_fee ( & self ) -> Option < Hbar > {
433+ let val = self . 0 . max_transaction_fee_tinybar . load ( Ordering :: Relaxed ) ;
434+
435+ ( val > 0 ) . then ( || Hbar :: from_tinybars ( val as i64 ) )
436+ }
437+
438+ /// Gets the maximum query fee the paying account is willing to pay.
439+ pub fn default_max_query_payment ( & self ) -> Option < Hbar > {
440+ let val = self . 0 . max_query_payment_tinybar . load ( Ordering :: Relaxed ) ;
441+
442+ ( val > 0 ) . then ( || Hbar :: from_tinybars ( val as i64 ) )
443+ }
444+
445+ /// Sets the maximum query payment to be used when no explicit max query payment is set.
446+ ///
447+ /// Note: Setting `amount` to zero is "unlimited"
448+ /// # Panics
449+ /// - if amount is negative
450+ pub fn set_default_max_query_payment ( & self , amount : Hbar ) {
451+ assert ! ( amount >= Hbar :: ZERO ) ;
452+ self . 0 . max_query_payment_tinybar . store ( amount. to_tinybars ( ) as u64 , Ordering :: Relaxed ) ;
416453 }
417454
418455 /// Returns the maximum amount of time that will be spent on a request.
0 commit comments