@@ -34,6 +34,7 @@ public final class Client: Sendable {
34
34
private let networkUpdateTask : NetworkUpdateTask
35
35
private let regenerateTransactionIdInner : ManagedAtomic < Bool >
36
36
private let maxTransactionFeeInner : ManagedAtomic < Int64 >
37
+ private let maxQueryPaymentInner : ManagedAtomic < Int64 >
37
38
private let networkUpdatePeriodInner : NIOLockedValueBox < UInt64 ? >
38
39
private let backoffInner : NIOLockedValueBox < Backoff >
39
40
@@ -50,6 +51,7 @@ public final class Client: Sendable {
50
51
self . autoValidateChecksumsInner = . init( false )
51
52
self . regenerateTransactionIdInner = . init( true )
52
53
self . maxTransactionFeeInner = . init( 0 )
54
+ self . maxQueryPaymentInner = . init( 0 )
53
55
self . networkUpdateTask = NetworkUpdateTask (
54
56
eventLoop: eventLoop,
55
57
managedNetwork: network,
@@ -80,6 +82,16 @@ public final class Client: Sendable {
80
82
return . fromTinybars( value)
81
83
}
82
84
85
+ internal var maxQueryPayment : Hbar ? {
86
+ let value = maxQueryPaymentInner. load ( ordering: . relaxed)
87
+
88
+ guard value != 0 else {
89
+ return nil
90
+ }
91
+
92
+ return . fromTinybars( value)
93
+ }
94
+
83
95
/// The maximum amount of time that will be spent on a request.
84
96
public var requestTimeout : TimeInterval ? {
85
97
get { backoff. requestTimeout }
@@ -214,6 +226,22 @@ public final class Client: Sendable {
214
226
return self
215
227
}
216
228
229
+ /// Sets the account that will, by default, be paying for transactions and queries built with
230
+ /// this client.
231
+ ///
232
+ /// The operator account ID is used to generate the default transaction ID for all transactions
233
+ /// executed with this client.
234
+ ///
235
+ /// The operator signer is used to sign all transactions executed by this client.
236
+ @discardableResult
237
+ public func setOperatorWith(
238
+ _ accountId: AccountId , _ publicKey: PublicKey , using signFunc: @Sendable @escaping ( Data ) -> Data
239
+ ) throws -> Self {
240
+ operatorInner. withLockedValue { $0 = . init( accountId: accountId, signer: Signer . init ( publicKey, signFunc) ) }
241
+
242
+ return self
243
+ }
244
+
217
245
public func ping( _ nodeAccountId: AccountId ) async throws {
218
246
try await PingQuery ( nodeAccountId: nodeAccountId) . execute ( self )
219
247
}
@@ -306,6 +334,46 @@ public final class Client: Sendable {
306
334
( self . operator? . accountId) . map { . generateFrom( $0) }
307
335
}
308
336
337
+ /// Sets the maximum transaction fee to be used when no explicit max transaction fee is set.
338
+ ///
339
+ /// Note: Setting the amount to zero is "unlimited".
340
+ /// # Panics
341
+ /// - if amount is negative
342
+ public func setDefaultMaxTransactionFee( _ amount: Hbar ) throws {
343
+ assert ( amount. toTinybars ( ) >= 0 , " Default max transaction fee cannot be set to a negative value. " )
344
+
345
+ self . maxTransactionFeeInner. store ( amount. toTinybars ( ) , ordering: . relaxed)
346
+ }
347
+
348
+ /// Gets the maximum transaction fee the paying account is willing to pay.
349
+ public func defaultMaxTransactionFee( ) throws -> Hbar ? {
350
+ let val = self . maxTransactionFeeInner. load ( ordering: . relaxed)
351
+
352
+ let amount = ( val > 0 ) ? Hbar . fromTinybars ( val) : nil
353
+
354
+ return amount
355
+ }
356
+
357
+ /// Sets the maximum query payment to be used when no explicit max query payment is set.
358
+ ///
359
+ /// Note: Setting the amount to zero is "unlimited".
360
+ /// # Panics
361
+ /// - if amount is negative
362
+ public func setDefaultMaxQueryPayment( _ amount: Hbar ) throws {
363
+ assert ( amount. toTinybars ( ) < 0 , " Default max query payment cannot be set to a negative value. " )
364
+
365
+ self . maxQueryPaymentInner. store ( amount. toTinybars ( ) , ordering: . relaxed)
366
+ }
367
+
368
+ /// Gets the maximum query payment the paying account is willing to pay.
369
+ public func defaultMaxQueryPayment( ) throws -> Hbar ? {
370
+ let val = self . maxQueryPaymentInner. load ( ordering: . relaxed)
371
+
372
+ let amount = ( val > 0 ) ? Hbar . fromTinybars ( val) : nil
373
+
374
+ return amount
375
+ }
376
+
309
377
internal var net : Network {
310
378
networkInner. primary. load ( ordering: . relaxed)
311
379
}
@@ -353,6 +421,16 @@ public final class Client: Sendable {
353
421
await self . networkUpdateTask. setUpdatePeriod ( nanoseconds)
354
422
self . networkUpdatePeriodInner. withLockedValue { $0 = nanoseconds }
355
423
}
424
+
425
+ /// Returns the Account ID for the operator.
426
+ public var operatorAccountId : AccountId ? {
427
+ operatorInner. withLockedValue { $0? . accountId }
428
+ }
429
+
430
+ /// Returns the Public Key for the operator.
431
+ public var operatorPublicKey : PublicKey ? {
432
+ operatorInner. withLockedValue { $0? . signer. publicKey }
433
+ }
356
434
}
357
435
358
436
extension Client {
0 commit comments