Skip to content

Commit

Permalink
upgrade to latest Api + fix Error Type
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Jun 19, 2021
1 parent dcb4487 commit 4fbbdde
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Sources/ApiParser/CodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class CodeGenerator {
}

private func generateStruct(_ swiftStruct: SDKSwiftStruct) -> String {
var swiftStruct = swiftStruct
if swiftStruct.name == "\(libPrefix)ClientError" {
swiftStruct.parents.append("Error")
}
var result: String = "\(swiftStruct.accessType) struct \(swiftStruct.name): \(swiftStruct.parents.joined(separator: ", ")) {\n"
for property in swiftStruct.properties {
if let summary: String = property.summary { result.append("\(tab)/// \(checkComment(summary))\n") }
Expand Down
2 changes: 1 addition & 1 deletion Sources/TonClientSwift/Client/ClientTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum TSDKAppRequestResultEnumTypes: String, Codable {
case Ok = "Ok"
}

public struct TSDKClientError: Codable {
public struct TSDKClientError: Codable, Error {
public var code: UInt32
public var message: String
public var data: AnyJSONType
Expand Down
19 changes: 14 additions & 5 deletions Sources/TonClientSwift/Crypto/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public final class TSDKCryptoModule {
self.binding = binding
}

/// Performs prime factorization – decomposition of a composite number into a product of smaller prime integers (factors). See [https://en.wikipedia.org/wiki/Integer_factorization]
/// Integer factorization
/// Performs prime factorization – decomposition of a composite numberinto a product of smaller prime integers (factors).
/// See [https://en.wikipedia.org/wiki/Integer_factorization]
public func factorize(_ payload: TSDKParamsOfFactorize, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfFactorize, TSDKClientError, TSDKDefault>) -> Void
) {
let method: String = "factorize"
Expand All @@ -18,7 +20,9 @@ public final class TSDKCryptoModule {
})
}

/// Performs modular exponentiation for big integers (`base`^`exponent` mod `modulus`). See [https://en.wikipedia.org/wiki/Modular_exponentiation]
/// Modular exponentiation
/// Performs modular exponentiation for big integers (`base`^`exponent` mod `modulus`).
/// See [https://en.wikipedia.org/wiki/Modular_exponentiation]
public func modular_power(_ payload: TSDKParamsOfModularPower, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfModularPower, TSDKClientError, TSDKDefault>) -> Void
) {
let method: String = "modular_power"
Expand Down Expand Up @@ -117,7 +121,9 @@ public final class TSDKCryptoModule {
})
}

/// Derives key from `password` and `key` using `scrypt` algorithm. See [https://en.wikipedia.org/wiki/Scrypt].
/// Perform `scrypt` encryption
/// Derives key from `password` and `key` using `scrypt` algorithm.
/// See [https://en.wikipedia.org/wiki/Scrypt].
/// # Arguments- `log_n` - The log2 of the Scrypt parameter `N`- `r` - The Scrypt parameter `r`- `p` - The Scrypt parameter `p`# Conditions- `log_n` must be less than `64`- `r` must be greater than `0` and less than or equal to `4294967295`- `p` must be greater than `0` and less than `4294967295`# Recommended values sufficient for most use-cases- `log_n = 15` (`n = 32768`)- `r = 8`- `p = 1`
public func scrypt(_ payload: TSDKParamsOfScrypt, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfScrypt, TSDKClientError, TSDKDefault>) -> Void
) {
Expand Down Expand Up @@ -265,6 +271,7 @@ public final class TSDKCryptoModule {
})
}

/// Generates a random mnemonic
/// Generates a random mnemonic from the specified dictionary and word count
public func mnemonic_from_random(_ payload: TSDKParamsOfMnemonicFromRandom, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfMnemonicFromRandom, TSDKClientError, TSDKDefault>) -> Void
) {
Expand All @@ -287,7 +294,8 @@ public final class TSDKCryptoModule {
})
}

/// The phrase supplied will be checked for word length and validated according to the checksum specified in BIP0039.
/// Validates a mnemonic phrase
/// The phrase supplied will be checked for word length and validated according to the checksumspecified in BIP0039.
public func mnemonic_verify(_ payload: TSDKParamsOfMnemonicVerify, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfMnemonicVerify, TSDKClientError, TSDKDefault>) -> Void
) {
let method: String = "mnemonic_verify"
Expand All @@ -298,7 +306,8 @@ public final class TSDKCryptoModule {
})
}

/// Validates the seed phrase, generates master key and then derives the key pair from the master key and the specified path
/// Derives a key pair for signing from the seed phrase
/// Validates the seed phrase, generates master key and then derivesthe key pair from the master key and the specified path
public func mnemonic_derive_sign_keys(_ payload: TSDKParamsOfMnemonicDeriveSignKeys, _ handler: @escaping (TSDKBindingResponse<TSDKKeyPair, TSDKClientError, TSDKDefault>) -> Void
) {
let method: String = "mnemonic_derive_sign_keys"
Expand Down
7 changes: 6 additions & 1 deletion Sources/TonClientSwift/Net/NetTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,15 @@ public struct TSDKParamsOfQueryTransactionTree: Codable {
public var in_msg: String
/// List of contract ABIs that will be used to decode message bodies. Library will try to decode each returned message body using any ABI from the registry.
public var abi_registry: [TSDKAbi]?
/// Timeout used to limit waiting time for the missing messages and transaction.
/// If some of the following messages and transactions are missing yetThe maximum waiting time is regulated by this option.
/// Default value is 60000 (1 min).
public var timeout: UInt32?

public init(in_msg: String, abi_registry: [TSDKAbi]? = nil) {
public init(in_msg: String, abi_registry: [TSDKAbi]? = nil, timeout: UInt32? = nil) {
self.in_msg = in_msg
self.abi_registry = abi_registry
self.timeout = timeout
}
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/TonClientSwift/Processing/ProcessingTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public struct TSDKParamsOfWaitForTransaction: Codable {
/// Flag that enables/disables intermediate events
public var send_events: Bool
/// The list of endpoints to which the message was sent.
/// You must provide the same value as the `send_message` has returned.
/// Use this field to get more informative errors.
/// Provide the same value as the `send_message` has returned.
/// If the message was not delivered (expired), SDK will log the endpoint URLs, used for its sending.
public var sending_endpoints: [String]?

public init(abi: TSDKAbi? = nil, message: String, shard_block_id: String, send_events: Bool, sending_endpoints: [String]? = nil) {
Expand Down
6 changes: 6 additions & 0 deletions api_generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

git pull --ff-only
swift build -c release
curl https://raw.githubusercontent.com/tonlabs/TON-SDK/master/tools/api.json > api.json
./.build/x86_64-apple-macosx/release/ApiParser ./api.json

0 comments on commit 4fbbdde

Please sign in to comment.