Skip to content

Commit c885c1c

Browse files
committed
refactor: change Environment variables for examples
Signed-off-by: Ricky Saechao <ricky@launchbadge.com>
1 parent 97d09f2 commit c885c1c

File tree

44 files changed

+218
-904
lines changed

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

+218
-904
lines changed

Examples/AccountAlias/main.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0
22
import Hiero
3-
import SwiftDotenv
3+
import HieroExampleUtilities
44

55
@main
66
internal enum Program {
77
internal static func main() async throws {
8-
let env = try Dotenv.load()
8+
let env = try Environment.load()
99
let client = try Client.forName(env.networkName)
1010

1111
client.setOperator(env.operatorAccountId, env.operatorKey)
@@ -84,22 +84,3 @@ internal enum Program {
8484
print("Example complete!")
8585
}
8686
}
87-
88-
extension Environment {
89-
/// Account ID for the operator to use in this example.
90-
internal var operatorAccountId: AccountId {
91-
AccountId(self["OPERATOR_ID"]!.stringValue)!
92-
}
93-
94-
/// Private key for the operator to use in this example.
95-
internal var operatorKey: PrivateKey {
96-
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
97-
}
98-
99-
/// The name of the hedera network this example should be ran against.
100-
///
101-
/// Testnet by default.
102-
internal var networkName: String {
103-
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
104-
}
105-
}

Examples/AccountAllowance/main.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
import Hiero
4-
import SwiftDotenv
4+
import HieroExampleUtilities
55

66
private struct Account {
77
internal let key: PrivateKey
@@ -183,7 +183,7 @@ private func cleanUp(
183183
@main
184184
internal enum Program {
185185
internal static func main() async throws {
186-
let env = try Dotenv.load()
186+
let env = try Environment.load()
187187
let client = try Client.forName(env.networkName)
188188

189189
client.setOperator(env.operatorAccountId, env.operatorKey)
@@ -193,22 +193,3 @@ internal enum Program {
193193
try await cleanUp(client, env.operatorAccountId, accounts)
194194
}
195195
}
196-
197-
extension Environment {
198-
/// Account ID for the operator to use in this example.
199-
internal var operatorAccountId: AccountId {
200-
AccountId(self["OPERATOR_ID"]!.stringValue)!
201-
}
202-
203-
/// Private key for the operator to use in this example.
204-
internal var operatorKey: PrivateKey {
205-
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
206-
}
207-
208-
/// The name of the hedera network this example should be ran against.
209-
///
210-
/// Testnet by default.
211-
internal var networkName: String {
212-
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
213-
}
214-
}

Examples/AddNftAllowance/main.swift

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
import Foundation
2020
import Hiero
21-
import SwiftDotenv
21+
import HieroExampleUtilities
2222

2323
@main
2424
internal enum Program {
2525
internal static func main() async throws {
26-
let env = try Dotenv.load()
26+
let env = try Environment.load()
2727
let client = try Client.forName(env.networkName)
2828

2929
client.setOperator(env.operatorAccountId, env.operatorKey)
@@ -123,8 +123,8 @@ internal enum Program {
123123
// Step 6: Transfer NFT using approved allowance
124124
let transferReceipt = try await TransferTransaction()
125125
.approvedNftTransfer(NftId(tokenId: nftTokenId, serial: 1), env.operatorAccountId, receiverAccountId)
126-
.freezeWith(client)
127126
.transactionId(TransactionId.generateFrom(spenderAccountId))
127+
.freezeWith(client)
128128
.sign(spenderKey)
129129
.execute(client)
130130
.getReceipt(client)
@@ -155,20 +155,3 @@ internal enum Program {
155155
// Implement cleanup steps...
156156
}
157157
}
158-
159-
extension Environment {
160-
/// Account ID for the operator to use in this example.
161-
internal var operatorAccountId: AccountId {
162-
AccountId(self["OPERATOR_ID"]!.stringValue)!
163-
}
164-
165-
/// Private key for the operator to use in this example.
166-
internal var operatorKey: PrivateKey {
167-
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
168-
}
169-
170-
/// The name of the Hiero network this example should run against.
171-
internal var networkName: String {
172-
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
173-
}
174-
}

Examples/ConsensusPubSub/main.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
import Hiero
4-
import SwiftDotenv
4+
import HieroExampleUtilities
55

66
@main
77
internal enum Program {
88
internal static func main() async throws {
9-
let env = try Dotenv.load()
9+
let env = try Environment.load()
1010
let client = try Client.forName(env.networkName)
1111

1212
client.setOperator(env.operatorAccountId, env.operatorKey)
@@ -55,22 +55,3 @@ internal enum Program {
5555
}
5656
}
5757
}
58-
59-
extension Environment {
60-
/// Account ID for the operator to use in this example.
61-
internal var operatorAccountId: AccountId {
62-
AccountId(self["OPERATOR_ID"]!.stringValue)!
63-
}
64-
65-
/// Private key for the operator to use in this example.
66-
internal var operatorKey: PrivateKey {
67-
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
68-
}
69-
70-
/// The name of the hedera network this example should be ran against.
71-
///
72-
/// Testnet by default.
73-
internal var networkName: String {
74-
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
75-
}
76-
}

Examples/ConsensusPubSubChunked/main.swift

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import Foundation
44
import Hiero
55
import HieroExampleUtilities
6-
import SwiftDotenv
76

87
@main
98
internal enum Program {
109
internal static func main() async throws {
11-
12-
let env = try Dotenv.load()
10+
let env = try Environment.load()
1311
let client = try Client.forName(env.networkName)
1412

1513
client.setOperator(env.operatorAccountId, env.operatorKey)
@@ -50,14 +48,16 @@ internal enum Program {
5048

5149
// now pretend we sent those bytes across the network
5250
// parse them into a transaction so we can sign as the submit key
53-
let deserializedTransaction = try Transaction.fromBytes(transactionBytes) as! TopicMessageSubmitTransaction
54-
51+
let deserializedTransaction = try Transaction.fromBytes(transactionBytes)
52+
guard let topicMessageSubmitTransaction = deserializedTransaction as? TopicMessageSubmitTransaction else {
53+
fatalError("Expected TopicMessageSubmitTransaction")
54+
}
5555
// sign with that submit key
56-
deserializedTransaction.sign(submitKey)
56+
topicMessageSubmitTransaction.sign(submitKey)
5757

5858
// now actually submit the transaction
5959
// get the receipt to ensure there were no errors
60-
_ = try await deserializedTransaction.execute(client).getReceipt(client)
60+
_ = try await topicMessageSubmitTransaction.execute(client).getReceipt(client)
6161

6262
print("Finished sending the message, press ctrl+c to exit once it's recieved")
6363
}
@@ -74,22 +74,3 @@ internal enum Program {
7474
}
7575
}
7676
}
77-
78-
extension Environment {
79-
/// Account ID for the operator to use in this example.
80-
internal var operatorAccountId: AccountId {
81-
AccountId(self["OPERATOR_ID"]!.stringValue)!
82-
}
83-
84-
/// Private key for the operator to use in this example.
85-
internal var operatorKey: PrivateKey {
86-
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
87-
}
88-
89-
/// The name of the hedera network this example should be ran against.
90-
///
91-
/// Testnet by default.
92-
internal var networkName: String {
93-
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
94-
}
95-
}

Examples/ConsensusPubSubWithSubmitKey/main.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
import Hiero
4-
import SwiftDotenv
4+
import HieroExampleUtilities
55

66
@main
77
internal enum Program {
88
internal static func main() async throws {
9-
let env = try Dotenv.load()
9+
let env = try Environment.load()
1010
let client = try Client.forName(env.networkName)
1111

1212
client.setOperator(env.operatorAccountId, env.operatorKey)
@@ -61,22 +61,3 @@ internal enum Program {
6161
}
6262
}
6363
}
64-
65-
extension Environment {
66-
/// Account ID for the operator to use in this example.
67-
internal var operatorAccountId: AccountId {
68-
AccountId(self["OPERATOR_ID"]!.stringValue)!
69-
}
70-
71-
/// Private key for the operator to use in this example.
72-
internal var operatorKey: PrivateKey {
73-
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
74-
}
75-
76-
/// The name of the hedera network this example should be ran against.
77-
///
78-
/// Testnet by default.
79-
internal var networkName: String {
80-
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
81-
}
82-
}

Examples/CreateAccount/main.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
import Hiero
4-
import SwiftDotenv
4+
import HieroExampleUtilities
55

66
@main
77
internal enum Program {
88
internal static func main() async throws {
9-
let env = try Dotenv.load()
9+
let env = try Environment.load()
1010
let client = try Client.forName(env.networkName)
1111

1212
client.setOperator(env.operatorAccountId, env.operatorKey)
@@ -27,22 +27,3 @@ internal enum Program {
2727
print("account address = \(newAccountId)")
2828
}
2929
}
30-
31-
extension Environment {
32-
/// Account ID for the operator to use in this example.
33-
internal var operatorAccountId: AccountId {
34-
AccountId(self["OPERATOR_ID"]!.stringValue)!
35-
}
36-
37-
/// Private key for the operator to use in this example.
38-
internal var operatorKey: PrivateKey {
39-
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
40-
}
41-
42-
/// The name of the hedera network this example should be ran against.
43-
///
44-
/// Testnet by default.
45-
internal var networkName: String {
46-
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
47-
}
48-
}

Examples/CreateAccountThresholdKey/main.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
import Hiero
4-
import SwiftDotenv
4+
import HieroExampleUtilities
55

66
@main
77
internal enum Program {
88
internal static func main() async throws {
9-
let env = try Dotenv.load()
9+
let env = try Environment.load()
1010
let client = try Client.forName(env.networkName)
1111

1212
client.setOperator(env.operatorAccountId, env.operatorKey)
@@ -63,22 +63,3 @@ internal enum Program {
6363
print("account balance after transfer: \(balanceAfter)")
6464
}
6565
}
66-
67-
extension Environment {
68-
/// Account ID for the operator to use in this example.
69-
internal var operatorAccountId: AccountId {
70-
AccountId(self["OPERATOR_ID"]!.stringValue)!
71-
}
72-
73-
/// Private key for the operator to use in this example.
74-
internal var operatorKey: PrivateKey {
75-
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
76-
}
77-
78-
/// The name of the hedera network this example should be ran against.
79-
///
80-
/// Testnet by default.
81-
internal var networkName: String {
82-
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
83-
}
84-
}

Examples/CreateAccountWithAlias/main.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020

2121
import Foundation
2222
import Hiero
23-
import SwiftDotenv
23+
import HieroExampleUtilities
2424

2525
@main
2626
internal enum Program {
2727
internal static func main() async throws {
2828
print("Starting Example")
29-
let env = try Dotenv.load()
29+
let env = try Environment.load()
3030
let client = try Client.forName(env.networkName)
3131

3232
client.setOperator(env.operatorAccountId, env.operatorKey)
@@ -145,22 +145,3 @@ internal enum Program {
145145
return true
146146
}
147147
}
148-
149-
extension Environment {
150-
/// Account ID for the operator to use in this example.
151-
internal var operatorAccountId: AccountId {
152-
AccountId(self["OPERATOR_ID"]!.stringValue)!
153-
}
154-
155-
/// Private key for the operator to use in this example.
156-
internal var operatorKey: PrivateKey {
157-
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
158-
}
159-
160-
/// The name of the hedera network this example should be ran against.
161-
///
162-
/// Testnet by default.
163-
internal var networkName: String {
164-
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
165-
}
166-
}

0 commit comments

Comments
 (0)