Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Document everything (to a certain degree) #75

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.build/
.vscode/launch.json
.env
14 changes: 14 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ disabled_rules:
- line_length
# not a very useful lint honestly.
- cyclomatic_complexity
# it's basically exclusively used for `unreachable`
- force_try
# This triggers a lot because of functions that simply cannot be smaller.
- function_body_length
# see above.
- closure_body_length
# And this triggers a lot because of the above two.
- type_body_length
# likewise here
- file_length
# Identifier names should make sense,
# and renaming stuff isn't always the right decision.
- identifier_name

opt_in_rules:
# deprecated & will be removed
Expand Down Expand Up @@ -51,6 +64,7 @@ opt_in_rules:
# - extension_access_modifier
- fallthrough
- fatal_error_message
- missing_docs

analyzer_rules:
- capture_variable
Expand Down
15 changes: 10 additions & 5 deletions Examples/CreateAccount/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Hedera
import SwiftDotenv

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand All @@ -47,15 +47,20 @@ public enum Program {
}

extension Environment {
public var operatorAccountId: AccountId {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
}

public var operatorKey: PrivateKey {
/// Private key for the operator to use in this example.
internal var operatorKey: PrivateKey {
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
}

public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}
15 changes: 10 additions & 5 deletions Examples/CreateFile/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Hedera
import SwiftDotenv

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand All @@ -48,15 +48,20 @@ public enum Program {
}

extension Environment {
public var operatorAccountId: AccountId {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
}

public var operatorKey: PrivateKey {
/// Private key for the operator to use in this example.
internal var operatorKey: PrivateKey {
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
}

public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}
16 changes: 11 additions & 5 deletions Examples/CreateTopic/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Hedera
import SwiftDotenv

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand All @@ -46,16 +46,22 @@ public enum Program {
print("sequence number = \(sendReceipt.topicSequenceNumber)")
}
}

extension Environment {
public var operatorAccountId: AccountId {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
}

public var operatorKey: PrivateKey {
/// Private key for the operator to use in this example.
internal var operatorKey: PrivateKey {
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
}

public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}
11 changes: 8 additions & 3 deletions Examples/DeleteAccount/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Hedera
import SwiftDotenv

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand All @@ -39,15 +39,20 @@ public enum Program {
}

extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
internal var operatorKey: PrivateKey {
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
}

public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}
15 changes: 10 additions & 5 deletions Examples/DeleteFile/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Hedera
import SwiftDotenv

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand Down Expand Up @@ -52,15 +52,20 @@ public enum Program {
}

extension Environment {
public var operatorAccountId: AccountId {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
}

public var operatorKey: PrivateKey {
/// Private key for the operator to use in this example.
internal var operatorKey: PrivateKey {
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
}

public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}
11 changes: 8 additions & 3 deletions Examples/FileAppendChunked/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ private let bigContents = """
"""

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand Down Expand Up @@ -88,15 +88,20 @@ public enum Program {
}

extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
internal var operatorKey: PrivateKey {
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
}

public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}
4 changes: 2 additions & 2 deletions Examples/GenerateKey/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Foundation
import Hedera

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
// Generate a Ed25519 key
// This is the current recommended default for Hedera

Expand Down
4 changes: 2 additions & 2 deletions Examples/GenerateKeyWithMnemonic/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Foundation
import Hedera

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
do {
let mnemonic = Mnemonic.generate24()
let privateKey = try mnemonic.toPrivateKey()
Expand Down
9 changes: 6 additions & 3 deletions Examples/GetAccountBalance/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Hedera
import SwiftDotenv

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand All @@ -38,7 +38,10 @@ public enum Program {
}

extension Environment {
public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}
11 changes: 8 additions & 3 deletions Examples/GetAccountInfo/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Hedera
import SwiftDotenv

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand All @@ -40,15 +40,20 @@ public enum Program {
}

extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
internal var operatorKey: PrivateKey {
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
}

public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}
9 changes: 6 additions & 3 deletions Examples/GetAddressBook/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import Hedera
import SwiftDotenv

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand All @@ -39,7 +39,10 @@ public enum Program {
}

extension Environment {
public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}
}
20 changes: 13 additions & 7 deletions Examples/GetExchangeRates/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Hedera
import SwiftDotenv

@main
public enum Program {
public static func main() async throws {
internal enum Program {
internal static func main() async throws {
let env = try Dotenv.load()
let client = try Client.forName(env.networkName)

Expand All @@ -50,21 +50,27 @@ public enum Program {
}

extension Environment {
public var operatorAccountId: AccountId {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
}

public var operatorKey: PrivateKey {
/// Private key for the operator to use in this example.
internal var operatorKey: PrivateKey {
PrivateKey(self["OPERATOR_KEY"]!.stringValue)!
}

public var networkName: String {
/// The name of the hedera network this example should be ran against.
///
/// Testnet by default.
internal var networkName: String {
self["HEDERA_NETWORK"]?.stringValue ?? "testnet"
}

/// The file ID for the exchange rates file.
///
/// By default this is `FileId.exchangeRates`.
public var exchangeRatesFile: FileId {
// we really do want to abort if the value is invalid
// swiftlint:disable:next force_try
try! (self["HEDERA_EXCHANGE_RATES_FILE"]?.stringValue).map(FileId.fromString) ?? FileId.exchangeRates
}
}
Loading