Skip to content

Commit 2fad210

Browse files
authored
feat: add missing TCK endpoints (#493)
* WIP update Swift tck server Signed-off-by: Rob Walworth <[email protected]> * feat: add missing endpoints Signed-off-by: Rob Walworth <[email protected]> * refactor: formatting Signed-off-by: Rob Walworth <[email protected]> * refactor: please the linter Signed-off-by: Rob Walworth <[email protected]> * fix: workflows Signed-off-by: Rob Walworth <[email protected]> * fix: add include Signed-off-by: Rob Walworth <[email protected]> * fix: trying something Signed-off-by: Rob Walworth <[email protected]> * fix: tests Signed-off-by: Rob Walworth <[email protected]> * refactor: remove unnecessary imports and better organize Signed-off-by: Rob Walworth <[email protected]> --------- Signed-off-by: Rob Walworth <[email protected]>
1 parent ff260ad commit 2fad210

File tree

72 files changed

+3632
-1080
lines changed

Some content is hidden

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

72 files changed

+3632
-1080
lines changed

.github/workflows/swift-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
strategy:
3434
matrix:
3535
swift: ["5.9", "5.10"]
36-
os: [macos-13, macos-latest]
36+
os: [macos-13, macos-14]
3737

3838
runs-on: ${{ matrix.os }}
3939
steps:
@@ -65,7 +65,7 @@ jobs:
6565
strategy:
6666
matrix:
6767
swift: ["5.9", "5.10"]
68-
os: [macos-13, macos-latest]
68+
os: [macos-13, macos-14]
6969

7070
needs: [build]
7171
runs-on: ${{ matrix.os }}

Examples/TransferCrypto/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ internal enum Program {
1313
client.setOperator(env.operatorAccountId, env.operatorKey)
1414

1515
let transactionResponse = try await TransferTransaction()
16-
.hbarTransfer("0.0.1001", 20)
17-
.hbarTransfer("0.0.6189", -20)
16+
.hbarTransfer(AccountId.fromString("0.0.1001"), 20)
17+
.hbarTransfer(AccountId.fromString("0.0.6189"), -20)
1818
.execute(client)
1919

2020
// either of these values can be used to lookup transactions in an explorer such as

Sources/Hiero/Account/AccountAllowanceApproveTransaction.swift

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,18 @@ public final class AccountAllowanceApproveTransaction: Transaction {
9191
public func approveTokenNftAllowance(
9292
_ nftId: NftId,
9393
_ ownerAccountId: AccountId,
94-
_ spenderAccountId: AccountId
94+
_ spenderAccountId: AccountId,
95+
_ delegatingSpenderAccountId: AccountId? = nil
9596
) -> Self {
96-
ensureNotFrozen()
97-
98-
if var allowance = nftAllowances.first(where: { (allowance) in
99-
allowance.tokenId == nftId.tokenId && allowance.spenderAccountId == spenderAccountId
100-
&& allowance.ownerAccountId == ownerAccountId && allowance.approvedForAll == nil
101-
}) {
102-
allowance.serials.append(nftId.serial)
103-
} else {
104-
nftAllowances.append(
105-
TokenNftAllowance(
106-
tokenId: nftId.tokenId,
107-
ownerAccountId: ownerAccountId,
108-
spenderAccountId: spenderAccountId,
109-
serials: [nftId.serial],
110-
approvedForAll: nil,
111-
delegatingSpenderAccountId: nil
112-
))
113-
}
97+
nftAllowances.append(
98+
TokenNftAllowance(
99+
tokenId: nftId.tokenId,
100+
ownerAccountId: ownerAccountId,
101+
spenderAccountId: spenderAccountId,
102+
serials: [nftId.serial],
103+
approvedForAll: nil,
104+
delegatingSpenderAccountId: delegatingSpenderAccountId
105+
))
114106

115107
return self
116108
}
@@ -136,6 +128,27 @@ public final class AccountAllowanceApproveTransaction: Transaction {
136128
return self
137129
}
138130

131+
/// Delete the NFT allowance on all serial numbers (present and future).
132+
@discardableResult
133+
public func deleteTokenNftAllowanceAllSerials(
134+
_ tokenId: TokenId,
135+
_ ownerAccountId: AccountId,
136+
_ spenderAccountId: AccountId
137+
) -> Self {
138+
139+
nftAllowances.append(
140+
TokenNftAllowance(
141+
tokenId: tokenId,
142+
ownerAccountId: ownerAccountId,
143+
spenderAccountId: spenderAccountId,
144+
serials: [],
145+
approvedForAll: false,
146+
delegatingSpenderAccountId: nil
147+
))
148+
149+
return self
150+
}
151+
139152
public func getNftApprovals() -> [TokenNftAllowance] {
140153
self.nftAllowances
141154
}

Sources/Hiero/ChunkedTransaction.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ public class ChunkedTransaction: Transaction {
127127
.executeAll(client, timeoutPerChunk: timeoutPerChunk)
128128
}
129129

130-
precondition(self.data.count < self.maxMessageSize, "todo: throw an actual error here")
130+
if self.data.count > self.maxMessageSize {
131+
throw HError.illegalState("transaction requires \(self.data.count) but only has \(self.maxMessageSize)")
132+
}
131133

132134
var responses: [Response] = []
133135

Sources/Hiero/File/FileCreateTransaction.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public final class FileCreateTransaction: Transaction {
1515
fileMemo = data.memo
1616
keys = try .fromProtobuf(data.keys)
1717
contents = data.contents
18-
expirationTime = data.hasExpirationTime ? .fromProtobuf(data.expirationTime) : nil
18+
expirationTime = data.hasExpirationTime ? .fromProtobuf(data.expirationTime) : .now + .days(90)
1919

2020
// hedera doesn't have these currently.
2121
autoRenewPeriod = nil
@@ -115,7 +115,7 @@ public final class FileCreateTransaction: Transaction {
115115
}
116116

117117
/// The time at which this file should expire.
118-
public var expirationTime: Timestamp? = .now + .days(90) {
118+
public var expirationTime: Timestamp = .now + .days(90) {
119119
willSet {
120120
ensureNotFrozen(fieldName: "expirationTime")
121121
}
@@ -158,7 +158,7 @@ extension FileCreateTransaction: ToProtobuf {
158158
proto.keys = keys.toProtobuf()
159159
proto.contents = contents
160160

161-
expirationTime?.toProtobufInto(&proto.expirationTime)
161+
expirationTime.toProtobufInto(&proto.expirationTime)
162162
}
163163
}
164164
}

Sources/Hiero/HError.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public struct HError: Error, CustomStringConvertible {
2929
case cannotCreateChecksum
3030
case freezeUnsetNodeAccountIds
3131
case uninitialized
32+
case illegalState
3233
}
3334

3435
public let description: String
@@ -104,6 +105,10 @@ public struct HError: Error, CustomStringConvertible {
104105
internal static func unitialized(_ description: String) -> Self {
105106
Self(kind: .uninitialized, description: description)
106107
}
108+
109+
internal static func illegalState(_ description: String) -> Self {
110+
Self(kind: .illegalState, description: description)
111+
}
107112
}
108113

109114
extension HError: LocalizedError {

Sources/Hiero/Token/AbstractTokenTransferTransaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public class AbstractTokenTransferTransaction: Transaction {
144144
public func approvedTokenTransferWithDecimals(
145145
_ tokenId: TokenId, _ accountId: AccountId, _ amount: Int64, _ expectedDecimals: UInt32
146146
) -> Self {
147-
doTokenTransferWithDecimals(tokenId, accountId, amount, false, expectedDecimals)
147+
doTokenTransferWithDecimals(tokenId, accountId, amount, true, expectedDecimals)
148148
}
149149

150150
/// Add a non-approved nft transfer to the transaction.

Sources/Hiero/Token/TokenAllowance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension TokenAllowance: TryProtobufCodable {
3030
proto.tokenID = tokenId.toProtobuf()
3131
proto.owner = ownerAccountId.toProtobuf()
3232
proto.spender = spenderAccountId.toProtobuf()
33-
proto.amount = Int64(amount)
33+
proto.amount = Int64(truncatingIfNeeded: amount)
3434
}
3535
}
3636
}

Sources/Hiero/TransferTransaction.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public final class TransferTransaction: AbstractTokenTransferTransaction {
4242
doHbarTransfer(accountId, amount.toTinybars(), false)
4343
}
4444

45+
/// Add a non-approved hbar transfer to the transaction.
46+
@discardableResult
47+
public func hbarTransfer(_ evmAddress: EvmAddress, _ amount: Hbar) -> Self {
48+
doHbarTransfer(AccountId.fromEvmAddress(evmAddress), amount.toTinybars(), false)
49+
}
50+
4551
/// Add an approved hbar transfer to the transaction.
4652
@discardableResult
4753
public func approvedHbarTransfer(_ accountId: AccountId, _ amount: Hbar) -> Self {
@@ -53,6 +59,18 @@ public final class TransferTransaction: AbstractTokenTransferTransaction {
5359
_ amount: Int64,
5460
_ approved: Bool
5561
) -> Self {
62+
for (index, transfer) in transfers.enumerated()
63+
where transfer.accountId == accountId && transfer.isApproval == approved {
64+
let newTinybars = transfer.amount + amount
65+
if newTinybars == 0 {
66+
transfers.remove(at: index)
67+
} else {
68+
transfers[index].amount = newTinybars
69+
}
70+
71+
return self
72+
}
73+
5674
transfers.append(Transfer(accountId: accountId, amount: amount, isApproval: approved))
5775

5876
return self

Sources/Hiero/Version.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// SPDX-License-Identifier: Apache-2.0
22
public enum VersionInfo {
3-
public static let version = "v0.40.0-12-gd45ff38"
3+
public static let version = "v0.42.0-dev"
44
}

0 commit comments

Comments
 (0)