Skip to content

Commit b8cf5ad

Browse files
authored
feat(TCK): Refactor TCK server into services and add token methods
1 parent eca73ab commit b8cf5ad

Some content is hidden

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

44 files changed

+2189
-588
lines changed

Sources/Hedera/Account/AccountCreateTransaction.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ extension AccountCreateTransaction: ToProtobuf {
285285
key?.toProtobufInto(&proto.key)
286286
proto.initialBalance = UInt64(truncatingIfNeeded: initialBalance.toTinybars())
287287
proto.receiverSigRequired = receiverSignatureRequired
288-
autoRenewPeriod?.toProtobufInto(&proto.autoRenewPeriod)
288+
(autoRenewPeriod ?? .days(90)).toProtobufInto(&proto.autoRenewPeriod)
289289
// autoRenewAccountId?.toProtobufInto(&proto.autoRenewAccount)
290290
proto.memo = accountMemo
291291
proto.maxAutomaticTokenAssociations = maxAutomaticTokenAssociations
@@ -294,14 +294,14 @@ extension AccountCreateTransaction: ToProtobuf {
294294
proto.alias = alias.data
295295
}
296296

297-
if let stakedNodeId = stakedNodeId {
298-
proto.stakedNodeID = Int64(truncatingIfNeeded: stakedNodeId)
299-
}
300-
301297
if let stakedAccountId = stakedAccountId {
302298
proto.stakedAccountID = stakedAccountId.toProtobuf()
303299
}
304300

301+
if let stakedNodeId = stakedNodeId {
302+
proto.stakedNodeID = Int64(truncatingIfNeeded: stakedNodeId)
303+
}
304+
305305
proto.declineReward = declineStakingReward
306306
}
307307
}

Sources/Hedera/Account/AccountUpdateTransaction.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ extension AccountUpdateTransaction: ToProtobuf {
360360
if let stakedNodeId = stakedNodeId {
361361
proto.stakedNodeID = Int64(bitPattern: stakedNodeId)
362362
}
363+
364+
if let declineStakingReward = declineStakingReward {
365+
proto.declineReward = Google_Protobuf_BoolValue(declineStakingReward)
366+
}
363367
}
364368
}
365369
}

Sources/Hedera/CustomFee.swift

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public struct FixedFee: CustomFee, Equatable, ValidateChecksums {
278278

279279
fileprivate func toFeeProtobuf() -> Proto_FixedFee {
280280
.with { proto in
281-
proto.amount = Int64(amount)
281+
proto.amount = Int64(truncatingIfNeeded: amount)
282282
if let denominatingTokenId = denominatingTokenId {
283283
proto.denominatingTokenID = denominatingTokenId.toProtobuf()
284284
}
@@ -315,6 +315,25 @@ public struct FractionalFee: CustomFee, Equatable, ValidateChecksums {
315315
self.allCollectorsAreExempt = allCollectorsAreExempt
316316
}
317317

318+
/// Create a new `CustomFixedFee`.
319+
public init(
320+
numerator: Int64 = 1,
321+
denominator: Int64 = 1,
322+
minimumAmount: UInt64 = 0,
323+
maximumAmount: UInt64 = 0,
324+
assessmentMethod: FeeAssessmentMethod = .exclusive,
325+
feeCollectorAccountId: AccountId? = nil,
326+
allCollectorsAreExempt: Bool = false
327+
) {
328+
self.numerator = numerator
329+
self.denominator = denominator
330+
self.minimumAmount = minimumAmount
331+
self.maximumAmount = maximumAmount
332+
self.assessmentMethod = assessmentMethod
333+
self.feeCollectorAccountId = feeCollectorAccountId
334+
self.allCollectorsAreExempt = allCollectorsAreExempt
335+
}
336+
318337
fileprivate init(
319338
fromFee proto: Proto_FractionalFee,
320339
feeCollectorAccountId: AccountId?,
@@ -425,9 +444,10 @@ public struct FractionalFee: CustomFee, Equatable, ValidateChecksums {
425444

426445
internal func toFeeProtobuf() -> Proto_FractionalFee {
427446
.with { proto in
428-
proto.fractionalAmount = amount.toProtobuf()
429-
proto.minimumAmount = Int64(minimumAmount)
430-
proto.maximumAmount = Int64(maximumAmount)
447+
proto.fractionalAmount.numerator = numerator
448+
proto.fractionalAmount.denominator = denominator
449+
proto.minimumAmount = Int64(truncatingIfNeeded: minimumAmount)
450+
proto.maximumAmount = Int64(truncatingIfNeeded: maximumAmount)
431451
proto.netOfTransfers = assessmentMethod == .exclusive
432452
}
433453
}
@@ -585,7 +605,8 @@ public struct RoyaltyFee: CustomFee, Equatable {
585605

586606
internal func toFeeProtobuf() -> Proto_RoyaltyFee {
587607
.with { proto in
588-
proto.exchangeValueFraction = self.exchangeValue.toProtobuf()
608+
proto.exchangeValueFraction.numerator = self.numerator
609+
proto.exchangeValueFraction.denominator = self.denominator
589610
if let fallbackFee = self.fallbackFee {
590611
proto.fallbackFee = fallbackFee.toFeeProtobuf()
591612
}

Sources/Hedera/Timestamp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct Timestamp: Sendable, Equatable, Hashable, CustomStringConvertible,
1616
public let seconds: UInt64
1717
public let subSecondNanos: UInt32
1818

19-
internal init(seconds: UInt64, subSecondNanos: UInt32) {
19+
public init(seconds: UInt64, subSecondNanos: UInt32) {
2020
self.seconds = seconds + UInt64(subSecondNanos) / nanosPerSecond
2121
self.subSecondNanos = subSecondNanos % UInt32(nanosPerSecond)
2222
}

Sources/Hedera/Token/TokenUpdateTransaction.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ extension TokenUpdateTransaction: ToProtobuf {
417417
if let metadata = metadata {
418418
proto.metadata = Google_Protobuf_BytesValue(metadata)
419419
}
420-
421420
}
422421
}
423422
}

Sources/HederaTCK/JSONHelper.swift

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)