Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Ricky Saechao <[email protected]>
  • Loading branch information
RickyLB committed Mar 21, 2024
1 parent 998cb72 commit 6fe9383
Show file tree
Hide file tree
Showing 54 changed files with 405 additions and 385 deletions.
55 changes: 29 additions & 26 deletions Examples/TokenUpdateNfts/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ internal enum Program {
let client = try Client.forName(env.networkName)

client.setOperator(env.operatorAccountId, env.operatorKey)

let metadataKey = PrivateKey.generateEd25519()
let nftCount = 4
let initialMetadataList = [Data(Array(repeating: [9,1,6], count: (nftCount / [9,1,6].count) + 1).flatMap { $0 }.prefix(nftCount))]
let updatedMetadata = Data([3,4])
let initialMetadataList = [
Data(Array(repeating: [9, 1, 6], count: (nftCount / [9, 1, 6].count) + 1).flatMap { $0 }.prefix(nftCount))
]
let updatedMetadata = Data([3, 4])

// Create Token with metadata key included
let tokenCreateTxReceipt = try await TokenCreateTransaction()
Expand All @@ -47,7 +49,7 @@ internal enum Program {
.expirationTime(.now + .minutes(5))
.execute(testEnv.client)
.getReceipt(testEnv.client)

let tokenId = try XCTUnwrap(tokenCreateTxReceipt.tokenId)

// Mint Token
Expand All @@ -56,9 +58,9 @@ internal enum Program {
.tokenId(tokenId)
.execute(testEnv.client)
.getReceipt(testEnv.client)

let serials = try XCTUnwrap(tokenMintTxReceipt.serials)

print("Metadata after mint= \(try await getMetadataList(testEnv.client, tokenId, serials))")

// Apply new serials & metadata Nft token
Expand All @@ -69,35 +71,37 @@ internal enum Program {
.sign(metadataKey)
.execute(testEnv.client)
.getReceipt(testEnv.client)

let updatedSerials = try XCTUnwrap(updatedNftTxReceipt.serials)

print("Metadata after mint= \(try await getMetadataList(testEnv.client, tokenId, updatedSerials))")
}
}

func getMetadataList(_ client: Client, _ tokenId: TokenId, _ serials: [UInt64]) async throws -> [Data] {
// Use TaskGroup to handle concurrent fetches
let metadataList: [Data] = try await withThrowingTaskGroup(of: Data.self, body: { group in
var results = [Data]()

// Iterate over serials, launching a new task for each
for serial in serials {
group.addTask {
let nftId = NftId(tokenId: tokenId, serial: UInt64(serial))
// Execute the query and return the result
// This assumes an async `execute` function that returns metadata or throws an error
return try await TokenNftInfoQuery().nftId(nftId).execute(client).metadata
let metadataList: [Data] = try await withThrowingTaskGroup(
of: Data.self,
body: { group in
var results = [Data]()

// Iterate over serials, launching a new task for each
for serial in serials {
group.addTask {
let nftId = NftId(tokenId: tokenId, serial: UInt64(serial))
// Execute the query and return the result
// This assumes an async `execute` function that returns metadata or throws an error
return try await TokenNftInfoQuery().nftId(nftId).execute(client).metadata
}
}
}

// Collect results from all tasks
for try await result in group {
results.append(result)
}
// Collect results from all tasks
for try await result in group {
results.append(result)
}

return results
})
return results
})

return metadataList
}
Expand All @@ -120,4 +124,3 @@ extension Environment {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}

18 changes: 9 additions & 9 deletions Sources/Hedera/Status.swift
Original file line number Diff line number Diff line change
Expand Up @@ -933,20 +933,20 @@ public enum Status: Equatable {

/// An alias that is assigned to an account or contract cannot be assigned to another account or contract.
case aliasAlreadyAssigned // = 332

/// A provided metadata key was invalid. Verification includes, for example, checking the size of Ed25519 and ECDSA(secp256k1)
/// public keys.
case invalidMetadataKey // = 333
case invalidMetadataKey // = 333

///Metadata key is not set on token
case tokenHasNoMetadataKey // = 334
case tokenHasNoMetadataKey // = 334

/// Token Metadata is not provided
case missingTokenMetadata // = 335
case missingTokenMetadata // = 335

/// NFT serial numbers are missing in the TokenUpdateNftsTransactionBody
case missingSerialNumbers // = 336
case missingSerialNumbers // = 336

/// swift-format-ignore: AlwaysUseLowerCamelCase
case UNRECOGNIZED(Int32)

Expand Down
Loading

0 comments on commit 6fe9383

Please sign in to comment.