Skip to content

Commit 6500d03

Browse files
authored
HIP-904: Allow autoMaxTokenAssociation to accept -1 & TokenReject
1 parent 0a31d43 commit 6500d03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2590
-477
lines changed

Sources/Hedera/Account/AccountBalance.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import Foundation
2222
import HederaProtobufs
2323

24-
private struct TokenBalance {
24+
private struct TokenBalance: Sendable {
2525
fileprivate let id: TokenId
2626
fileprivate let balance: UInt64
2727
fileprivate let decimals: UInt32
@@ -67,11 +67,10 @@ public struct AccountBalance: Sendable {
6767
/// Token balances for the referenced account.
6868
///
6969
/// This access is *`O(n)`*.
70-
@available(*, deprecated, message: "use a mirror query")
7170
public var tokenBalances: [TokenId: UInt64] { tokenBalancesInner }
7271

7372
// hack to work around deprecated warning
74-
private var tokenDecimalsInner: [TokenId: UInt32] {
73+
public var tokenDecimalsInner: [TokenId: UInt32] {
7574
Dictionary(uniqueKeysWithValues: tokensInner.map { ($0.id, $0.decimals) })
7675
}
7776

Sources/Hedera/Account/AccountCreateTransaction.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class AccountCreateTransaction: Transaction {
3232
autoRenewPeriod: Duration? = .days(90),
3333
autoRenewAccountId: AccountId? = nil,
3434
accountMemo: String = "",
35-
maxAutomaticTokenAssociations: UInt32 = 0,
35+
maxAutomaticTokenAssociations: Int32 = 0,
3636
alias: EvmAddress? = nil,
3737
stakedAccountId: AccountId? = nil,
3838
stakedNodeId: UInt64? = nil,
@@ -59,7 +59,7 @@ public final class AccountCreateTransaction: Transaction {
5959
self.receiverSignatureRequired = data.receiverSigRequired
6060
self.autoRenewPeriod = data.hasAutoRenewPeriod ? .fromProtobuf(data.autoRenewPeriod) : nil
6161
self.accountMemo = data.memo
62-
self.maxAutomaticTokenAssociations = UInt32(data.maxAutomaticTokenAssociations)
62+
self.maxAutomaticTokenAssociations = data.maxAutomaticTokenAssociations
6363

6464
if let id = data.stakedID {
6565
switch id {
@@ -175,15 +175,15 @@ public final class AccountCreateTransaction: Transaction {
175175
}
176176

177177
/// The maximum number of tokens that an Account can be implicitly associated with.
178-
public var maxAutomaticTokenAssociations: UInt32 {
178+
public var maxAutomaticTokenAssociations: Int32 {
179179
willSet {
180180
ensureNotFrozen()
181181
}
182182
}
183183

184184
/// Sets the maximum number of tokens that an Account can be implicitly associated with.
185185
@discardableResult
186-
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: UInt32) -> Self {
186+
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: Int32) -> Self {
187187
self.maxAutomaticTokenAssociations = maxAutomaticTokenAssociations
188188

189189
return self
@@ -288,7 +288,7 @@ extension AccountCreateTransaction: ToProtobuf {
288288
autoRenewPeriod?.toProtobufInto(&proto.autoRenewPeriod)
289289
// autoRenewAccountId?.toProtobufInto(&proto.autoRenewAccount)
290290
proto.memo = accountMemo
291-
proto.maxAutomaticTokenAssociations = Int32(maxAutomaticTokenAssociations)
291+
proto.maxAutomaticTokenAssociations = maxAutomaticTokenAssociations
292292

293293
if let alias = alias {
294294
proto.alias = alias.data

Sources/Hedera/Account/AccountInfo.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct AccountInfo: Sendable {
4444
autoRenewPeriod: Duration?,
4545
accountMemo: String,
4646
ownedNfts: UInt64,
47-
maxAutomaticTokenAssociations: UInt32,
47+
maxAutomaticTokenAssociations: Int32,
4848
aliasKey: PublicKey?,
4949
ethereumNonce: UInt64,
5050
ledgerId: LedgerId,
@@ -140,7 +140,7 @@ public struct AccountInfo: Sendable {
140140
public let ownedNfts: UInt64
141141

142142
/// The maximum number of tokens that an Account can be implicitly associated with.
143-
public let maxAutomaticTokenAssociations: UInt32
143+
public let maxAutomaticTokenAssociations: Int32
144144

145145
/// The public key which aliases to this account.
146146
public let aliasKey: PublicKey?
@@ -193,7 +193,7 @@ extension AccountInfo: TryProtobufCodable {
193193
autoRenewPeriod: .fromProtobuf(autoRenewPeriod),
194194
accountMemo: proto.memo,
195195
ownedNfts: UInt64(proto.ownedNfts),
196-
maxAutomaticTokenAssociations: UInt32(proto.maxAutomaticTokenAssociations),
196+
maxAutomaticTokenAssociations: proto.maxAutomaticTokenAssociations,
197197
aliasKey: try .fromAliasBytes(proto.alias),
198198
ethereumNonce: UInt64(proto.ethereumNonce),
199199
ledgerId: .fromBytes(proto.ledgerID),
@@ -217,7 +217,7 @@ extension AccountInfo: TryProtobufCodable {
217217
autoRenewPeriod?.toProtobufInto(&proto.autoRenewPeriod)
218218
proto.memo = accountMemo
219219
proto.ownedNfts = Int64(ownedNfts)
220-
proto.maxAutomaticTokenAssociations = Int32(maxAutomaticTokenAssociations)
220+
proto.maxAutomaticTokenAssociations = maxAutomaticTokenAssociations
221221
proto.alias = aliasKey?.toProtobufBytes() ?? Data()
222222
proto.ethereumNonce = Int64(ethereumNonce)
223223
proto.ledgerID = ledgerId.bytes

Sources/Hedera/Account/AccountUpdateTransaction.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public final class AccountUpdateTransaction: Transaction {
7373
self.accountMemo = data.hasMemo ? data.memo.value : nil
7474
self.maxAutomaticTokenAssociations =
7575
data.hasMaxAutomaticTokenAssociations
76-
? UInt32(data.maxAutomaticTokenAssociations.value) : nil
76+
? data.maxAutomaticTokenAssociations.value : nil
7777
self.stakedAccountId = stakedAccountId
7878
self.stakedNodeId = stakedNodeId
7979
self.declineStakingReward = data.hasDeclineReward ? data.declineReward.value : nil
@@ -227,15 +227,15 @@ public final class AccountUpdateTransaction: Transaction {
227227
}
228228

229229
/// The maximum number of tokens that an Account can be implicitly associated with.
230-
public var maxAutomaticTokenAssociations: UInt32? {
230+
public var maxAutomaticTokenAssociations: Int32? {
231231
willSet {
232232
ensureNotFrozen()
233233
}
234234
}
235235

236236
/// Sets the maximum number of tokens that an Account can be implicitly associated with.
237237
@discardableResult
238-
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: UInt32) -> Self {
238+
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: Int32) -> Self {
239239
self.maxAutomaticTokenAssociations = maxAutomaticTokenAssociations
240240

241241
return self
@@ -350,7 +350,7 @@ extension AccountUpdateTransaction: ToProtobuf {
350350

351351
if let maxAutomaticTokenAssociations = maxAutomaticTokenAssociations {
352352
proto.maxAutomaticTokenAssociations = Google_Protobuf_Int32Value(
353-
Int32(maxAutomaticTokenAssociations))
353+
maxAutomaticTokenAssociations)
354354
}
355355

356356
if let stakedAccountId = stakedAccountId {

Sources/Hedera/AnyTransaction.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ internal enum ServicesTransactionDataList {
5151
case tokenMint([Proto_TokenMintTransactionBody])
5252
case tokenPause([Proto_TokenPauseTransactionBody])
5353
case tokenRevokeKyc([Proto_TokenRevokeKycTransactionBody])
54+
case tokenReject([Proto_TokenRejectTransactionBody])
5455
case tokenUnfreeze([Proto_TokenUnfreezeAccountTransactionBody])
5556
case tokenUnpause([Proto_TokenUnpauseTransactionBody])
5657
case tokenUpdate([Proto_TokenUpdateTransactionBody])
@@ -235,6 +236,10 @@ internal enum ServicesTransactionDataList {
235236
array.append(data)
236237
self = .tokenUpdateNfts(array)
237238

239+
case (.tokenReject(var array), .tokenReject(let data)):
240+
array.append(data)
241+
self = .tokenReject(array)
242+
238243
default:
239244
throw HError.fromProtobuf("mismatched transaction types")
240245
}
@@ -302,6 +307,7 @@ extension ServicesTransactionDataList: TryFromProtobuf {
302307
case .nodeDelete: throw HError.fromProtobuf("Unsupported transaction `NodeDeleteTransaction`")
303308
case .nodeCreate: throw HError.fromProtobuf("Unsupported transaction `NodeCreateTransaction`")
304309
case .nodeUpdate: throw HError.fromProtobuf("Unsupported transaction `NodeUpdateTransaction`")
310+
case .tokenReject(let data): value = .tokenReject([data])
305311
}
306312

307313
for transaction in iter {

Sources/Hedera/Contract/ContractCreateFlow.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public final class ContractCreateFlow {
5252
constructorParameters: Data = Data(),
5353
gas: UInt64 = 0,
5454
initialBalance: Hbar = .zero,
55-
maxAutomaticTokenAssociations: UInt32 = 0,
55+
maxAutomaticTokenAssociations: Int32 = 0,
5656
declineStakingReward: Bool = false,
5757
adminKey: Key? = nil,
5858
autoRenewAccountId: AccountId? = nil,
@@ -79,7 +79,7 @@ public final class ContractCreateFlow {
7979
fileprivate var constructorParameters: Data
8080
fileprivate var gas: UInt64
8181
fileprivate var initialBalance: Hbar
82-
fileprivate var maxAutomaticTokenAssociations: UInt32
82+
fileprivate var maxAutomaticTokenAssociations: Int32
8383
fileprivate var declineStakingReward: Bool
8484
fileprivate var adminKey: Key?
8585
// fileprivate var proxyAccountId: AccountId?
@@ -220,7 +220,7 @@ public final class ContractCreateFlow {
220220
}
221221

222222
/// The maximum number of tokens that the contract can be automatically associated with.
223-
public var maxAutomaticTokenAssociations: UInt32 {
223+
public var maxAutomaticTokenAssociations: Int32 {
224224
get { contractCreateData.maxAutomaticTokenAssociations }
225225
set(value) { contractCreateData.maxAutomaticTokenAssociations = value }
226226
}
@@ -229,7 +229,7 @@ public final class ContractCreateFlow {
229229
///
230230
/// - Returns: `self`
231231
@discardableResult
232-
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: UInt32) -> Self {
232+
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: Int32) -> Self {
233233
self.maxAutomaticTokenAssociations = maxAutomaticTokenAssociations
234234

235235
return self

Sources/Hedera/Contract/ContractCreateTransaction.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public final class ContractCreateTransaction: Transaction {
5656
autoRenewPeriod: Duration? = .days(90),
5757
constructorParameters: Data? = nil,
5858
contractMemo: String = "",
59-
maxAutomaticTokenAssociations: UInt32 = 0,
59+
maxAutomaticTokenAssociations: Int32 = 0,
6060
autoRenewAccountId: AccountId? = nil,
6161
stakedAccountId: AccountId? = nil,
6262
stakedNodeId: UInt64? = nil,
@@ -117,7 +117,7 @@ public final class ContractCreateTransaction: Transaction {
117117
self.autoRenewPeriod = .fromProtobuf(data.autoRenewPeriod)
118118
self.constructorParameters = !data.constructorParameters.isEmpty ? data.constructorParameters : nil
119119
self.contractMemo = data.memo
120-
self.maxAutomaticTokenAssociations = UInt32(data.maxAutomaticTokenAssociations)
120+
self.maxAutomaticTokenAssociations = data.maxAutomaticTokenAssociations
121121
self.autoRenewAccountId = data.hasAutoRenewAccountID ? try .fromProtobuf(data.autoRenewAccountID) : nil
122122
self.stakedAccountId = stakedAccountId
123123
self.stakedNodeId = stakedNodeId
@@ -285,15 +285,15 @@ public final class ContractCreateTransaction: Transaction {
285285
}
286286

287287
/// The maximum number of tokens that this contract can be automatically associated with.
288-
public var maxAutomaticTokenAssociations: UInt32 {
288+
public var maxAutomaticTokenAssociations: Int32 {
289289
willSet {
290290
ensureNotFrozen()
291291
}
292292
}
293293

294294
/// Sets the maximum number of tokens that this contract can be automatically associated with.
295295
@discardableResult
296-
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: UInt32) -> Self {
296+
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: Int32) -> Self {
297297
self.maxAutomaticTokenAssociations = maxAutomaticTokenAssociations
298298

299299
return self

Sources/Hedera/Contract/ContractInfo.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public struct ContractInfo {
5959
public let autoRenewAccountId: AccountId?
6060

6161
/// The maximum number of tokens that a contract can be implicitly associated with.
62-
public let maxAutomaticTokenAssociations: UInt32
62+
public let maxAutomaticTokenAssociations: Int32
6363

6464
/// Ledger ID for the network the response was returned from.
6565
public let ledgerId: LedgerId
@@ -103,7 +103,7 @@ extension ContractInfo: TryProtobufCodable {
103103
balance: .fromTinybars(Int64(proto.balance)),
104104
isDeleted: proto.deleted,
105105
autoRenewAccountId: try .fromProtobuf(autoRenewAccountId),
106-
maxAutomaticTokenAssociations: UInt32(proto.maxAutomaticTokenAssociations),
106+
maxAutomaticTokenAssociations: proto.maxAutomaticTokenAssociations,
107107
ledgerId: .fromBytes(proto.ledgerID),
108108
stakingInfo: try .fromProtobuf(proto.stakingInfo)
109109
)
@@ -122,7 +122,7 @@ extension ContractInfo: TryProtobufCodable {
122122
proto.balance = UInt64(balance.toTinybars())
123123
proto.deleted = isDeleted
124124
autoRenewAccountId?.toProtobufInto(&proto.autoRenewAccountID)
125-
proto.maxAutomaticTokenAssociations = Int32(maxAutomaticTokenAssociations)
125+
proto.maxAutomaticTokenAssociations = maxAutomaticTokenAssociations
126126
proto.ledgerID = ledgerId.bytes
127127
proto.stakingInfo = stakingInfo.toProtobuf()
128128
}

Sources/Hedera/Contract/ContractUpdateTransaction.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class ContractUpdateTransaction: Transaction {
3232
adminKey: Key? = nil,
3333
autoRenewPeriod: Duration? = nil,
3434
contractMemo: String? = nil,
35-
maxAutomaticTokenAssociations: UInt32? = nil,
35+
maxAutomaticTokenAssociations: Int32? = nil,
3636
autoRenewAccountId: AccountId? = nil,
3737
proxyAccountId: AccountId? = nil,
3838
stakedAccountId: AccountId? = nil,
@@ -87,7 +87,7 @@ public final class ContractUpdateTransaction: Transaction {
8787
self.autoRenewPeriod = data.hasAutoRenewPeriod ? .fromProtobuf(data.autoRenewPeriod) : nil
8888
self.contractMemo = memo
8989
self.maxAutomaticTokenAssociations =
90-
data.hasMaxAutomaticTokenAssociations ? UInt32(data.maxAutomaticTokenAssociations.value) : nil
90+
data.hasMaxAutomaticTokenAssociations ? data.maxAutomaticTokenAssociations.value : nil
9191
self.autoRenewAccountId = data.hasAutoRenewAccountID ? try .fromProtobuf(data.autoRenewAccountID) : nil
9292
self.proxyAccountId = data.hasProxyAccountID ? try .fromProtobuf(data.proxyAccountID) : nil
9393
self.stakedAccountId = stakedAccountId
@@ -180,15 +180,15 @@ public final class ContractUpdateTransaction: Transaction {
180180
}
181181

182182
/// The maximum number of tokens that this contract can be automatically associated with.
183-
public var maxAutomaticTokenAssociations: UInt32? {
183+
public var maxAutomaticTokenAssociations: Int32? {
184184
willSet {
185185
ensureNotFrozen()
186186
}
187187
}
188188

189189
/// Sets the maximum number of tokens that this contract can be automatically associated with.
190190
@discardableResult
191-
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: UInt32?) -> Self {
191+
public func maxAutomaticTokenAssociations(_ maxAutomaticTokenAssociations: Int32?) -> Self {
192192
self.maxAutomaticTokenAssociations = maxAutomaticTokenAssociations
193193

194194
return self

Sources/Hedera/FeeSchedule/RequestType.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ public enum RequestType {
256256
/// Delete a node
257257
case nodeDelete
258258

259-
/// Get the info for a node
260-
case nodeGetInfo
259+
/// Reject a Token
260+
case tokenReject
261261

262262
// this literally can't be smaller.
263263
// swiftlint:disable:next function_body_length
@@ -341,7 +341,7 @@ public enum RequestType {
341341
case .nodeCreate: self = .nodeCreate
342342
case .nodeDelete: self = .nodeDelete
343343
case .nodeUpdate: self = .nodeUpdate
344-
case .nodeGetInfo: self = .nodeGetInfo
344+
case .tokenReject: self = .tokenReject
345345

346346
case .UNRECOGNIZED(let code):
347347
throw HError.fromProtobuf("unrecognized RequestType: `\(code)`")
@@ -427,7 +427,7 @@ public enum RequestType {
427427
case .nodeCreate: return .nodeCreate
428428
case .nodeUpdate: return .nodeUpdate
429429
case .nodeDelete: return .nodeDelete
430-
case .nodeGetInfo: return .nodeGetInfo
430+
case .tokenReject: return .tokenReject
431431
}
432432
}
433433
}

0 commit comments

Comments
 (0)