Skip to content

Commit

Permalink
Merge pull request #3 from nerzh/rethrows
Browse files Browse the repository at this point in the history
add rethrows
  • Loading branch information
nerzh authored Sep 4, 2021
2 parents 2901291 + 39bbfb3 commit 931c4d3
Show file tree
Hide file tree
Showing 22 changed files with 541 additions and 481 deletions.
31 changes: 31 additions & 0 deletions ApiParser/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version:5.4
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ApiParser",
platforms: [
.macOS(SupportedPlatform.MacOSVersion.v10_12)
],
products: [
.executable(name: "ApiParser", targets: ["ApiParser"])
],
dependencies: [
.package(name: "SwiftRegularExpression", url: "https://github.com/nerzh/swift-regular-expression.git", .upToNextMajor(from: "0.2.4")),
.package(name: "swift-argument-parser", url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.4.3")),
.package(name: "FileUtils", url: "https://github.com/nerzh/SwiftFileUtils", .upToNextMinor(from: "1.3.0")),
],
targets: [
.executableTarget(
name: "ApiParser",
dependencies: [
.product(name: "SwiftRegularExpression", package: "SwiftRegularExpression"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "FileUtils", package: "FileUtils"),
]),
],
swiftLanguageVersions: [
SwiftVersion.v5
]
)
10 changes: 10 additions & 0 deletions ApiParser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Api Parser For Ton Swift Client [Swift Free Ton SDK](https://github.com/nerzh/ton-client-swift)

### Update SDK

```bash
cd ton-client-swift
```
```bash
bash api_generate.sh
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CodeGenerator {

func generate() {
for module in swiftApi.modules {
let moduleClassFolder: String = "./Sources/TonClientSwift/\(module.name.capitalized)"
let moduleClassFolder: String = "./../Sources/TonClientSwift/\(module.name.capitalized)"
let moduleClassFilePath: String = "\(moduleClassFolder)/\(module.name.capitalized).swift"
var newModuleClass: String = ""
if module.name == "client" {
Expand Down Expand Up @@ -105,14 +105,14 @@ class CodeGenerator {
return result
}

// public func factorize(_ payload: TSDKParamsOfFactorize,
// _ handler: @escaping (TSDKBindingResponse<TSDKResultOfFactorize, TSDKClientError, TSDKDefault>) -> Void
// ) {
// let method: String = "factorize"
// binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
// var response: TSDKBindingResponse<TSDKResultOfFactorize, TSDKClientError, TSDKDefault> = .init()
// public func decode_message_body(_ payload: TSDKParamsOfDecodeMessageBody,
// _ handler: @escaping (TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError, TSDKDefault>) throws -> Void
// ) throws {
// let method: String = "decode_message_body"
// try binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
// var response: TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError, TSDKDefault> = .init()
// response.update(requestId, params, responseType, finished)
// handler(response)
// try handler(response)
// })
// }
private func generateFunction(_ swiftFunction: SDKSwiftFunction) -> String {
Expand All @@ -124,18 +124,27 @@ class CodeGenerator {
result.append("_ \(parameter.name): \(parameter.type), ")
}
let resultType: String = swiftFunction.willReturn.type == "Void" ? "\(libPrefix)NoneResult" : swiftFunction.willReturn.type
result.append("_ handler: @escaping (TSDKBindingResponse<\(resultType), \(libPrefix)ClientError, \(libPrefix)Default>) -> Void\n\(tab)) {\n")
result.append("_ handler: @escaping (TSDKBindingResponse<\(resultType), \(libPrefix)ClientError, \(libPrefix)Default>) throws -> Void\n\(tab)) {\n")
let methodName: String = swiftFunction.name == "initialize" ? "init" : swiftFunction.name
result.append("\(tab)\(tab)let method: String = \"\(methodName)\"\n")
// result.append("\(tab)\(tab)do {\n")
if swiftFunction.params.isEmpty {
result.append("\(tab)\(tab)binding.requestLibraryAsync(methodName(module, method), \"\", { (requestId, params, responseType, finished) in\n")
result.append("\(tab)\(tab)binding.requestLibraryAsync(methodName(module, method), \"\") { (requestId, params, responseType, finished) in\n")
} else {
result.append("\(tab)\(tab)binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in\n")
result.append("\(tab)\(tab)binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in\n")
}
result.append("\(tab)\(tab)\(tab)var response: TSDKBindingResponse<\(resultType), \(libPrefix)ClientError, \(libPrefix)Default> = .init()\n")
result.append("\(tab)\(tab)\(tab)response.update(requestId, params, responseType, finished)\n")
result.append("\(tab)\(tab)\(tab)handler(response)\n")
result.append("\(tab)\(tab)})\n")
// result.append("\(tab)\(tab)\(tab)do {\n")
result.append("\(tab)\(tab)\(tab)try handler(response)\n")
// result.append("\(tab)\(tab)\(tab)} catch {\n")
// result.append("\(tab)\(tab)\(tab)\(tab)response = TSDKBindingResponse(result: nil, error: TSDKClientError(code: 0, message: error.localizedDescription, data: [:].toAnyValue()), customResponse: nil, finished: false, requestId: response.requestId, currentResponse: response.currentResponse)\n")
// result.append("\(tab)\(tab)\(tab)\(tab)\(tab)try? handler(response)\n")
// result.append("\(tab)\(tab)\(tab)}\n")
result.append("\(tab)\(tab)}\n")
// result.append("\(tab)\(tab)} catch {\n")
// result.append("\(tab)\(tab)\(tab)try? handler(TSDKBindingResponse(result: nil, error: TSDKClientError(code: 0, message: error.localizedDescription, data: [:].toAnyValue()), customResponse: nil, finished: false, requestId: 0, currentResponse: nil))\n")
// result.append("\(tab)\(tab)}\n")
result.append("\(tab)}\n\n")

return result
Expand Down Expand Up @@ -167,9 +176,9 @@ class CodeGenerator {
result.append("\(tab)public var \(module.name): \(libPrefix)\(module.name.capitalized)Module\n")
}
result.append("\n")
result.append("\(tab)public init(config: \(libPrefix)ClientConfig) {\n")
result.append("\(tab)public init(config: \(libPrefix)ClientConfig) throws {\n")
result.append("\(tab)\(tab)self.config = config\n")
result.append("\(tab)\(tab)self.binding = \(libPrefix)BindingModule(config: config)\n")
result.append("\(tab)\(tab)self.binding = try \(libPrefix)BindingModule(config: config)\n")
for module in modules {
if module.name == "client" { continue }
result.append("\(tab)\(tab)self.\(module.name) = \(libPrefix)\(module.name.capitalized)Module(binding: binding)\n")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ let package = Package(
],
products: [
.library(name: "TonClientSwift", targets: ["TonClientSwift"]),
.executable(name: "ApiParser", targets: ["ApiParser"])
],
dependencies: [
.package(name: "SwiftRegularExpression", url: "https://github.com/nerzh/swift-regular-expression.git", .upToNextMajor(from: "0.2.4")),
.package(name: "swift-argument-parser", url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.4.3")),
.package(name: "FileUtils", url: "https://github.com/nerzh/SwiftFileUtils", .upToNextMinor(from: "1.3.0")),
.package(name: "BigInt", url: "https://github.com/attaswift/BigInt", .exact("5.2.1")),
],
Expand All @@ -28,13 +26,6 @@ let package = Package(
.product(name: "SwiftRegularExpression", package: "SwiftRegularExpression"),
.product(name: "BigInt", package: "BigInt"),
]),
.executableTarget(
name: "ApiParser",
dependencies: [
.product(name: "SwiftRegularExpression", package: "SwiftRegularExpression"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "FileUtils", package: "FileUtils"),
]),
.testTarget(
name: "TonClientSwiftTests",
dependencies: [
Expand Down
72 changes: 36 additions & 36 deletions Sources/TonClientSwift/Abi/Abi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ public final class TSDKAbiModule {
}

/// Encodes message body according to ABI function call.
public func encode_message_body(_ payload: TSDKParamsOfEncodeMessageBody, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeMessageBody, TSDKClientError, TSDKDefault>) -> Void
public func encode_message_body(_ payload: TSDKParamsOfEncodeMessageBody, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeMessageBody, TSDKClientError, TSDKDefault>) throws -> Void
) {
let method: String = "encode_message_body"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfEncodeMessageBody, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
try handler(response)
}
}

public func attach_signature_to_message_body(_ payload: TSDKParamsOfAttachSignatureToMessageBody, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfAttachSignatureToMessageBody, TSDKClientError, TSDKDefault>) -> Void
public func attach_signature_to_message_body(_ payload: TSDKParamsOfAttachSignatureToMessageBody, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfAttachSignatureToMessageBody, TSDKClientError, TSDKDefault>) throws -> Void
) {
let method: String = "attach_signature_to_message_body"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfAttachSignatureToMessageBody, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
try handler(response)
}
}

/// Encodes an ABI-compatible message
Expand All @@ -45,14 +45,14 @@ public final class TSDKAbiModule {
/// 1. Public key from deploy set.
/// 2. Public key, specified in TVM file.
/// 3. Public key, provided by signer.
public func encode_message(_ payload: TSDKParamsOfEncodeMessage, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeMessage, TSDKClientError, TSDKDefault>) -> Void
public func encode_message(_ payload: TSDKParamsOfEncodeMessage, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeMessage, TSDKClientError, TSDKDefault>) throws -> Void
) {
let method: String = "encode_message"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfEncodeMessage, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
try handler(response)
}
}

/// Encodes an internal ABI-compatible message
Expand All @@ -64,72 +64,72 @@ public final class TSDKAbiModule {
/// Public key resolving priority:
/// 1. Public key from deploy set.
/// 2. Public key, specified in TVM file.
public func encode_internal_message(_ payload: TSDKParamsOfEncodeInternalMessage, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeInternalMessage, TSDKClientError, TSDKDefault>) -> Void
public func encode_internal_message(_ payload: TSDKParamsOfEncodeInternalMessage, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeInternalMessage, TSDKClientError, TSDKDefault>) throws -> Void
) {
let method: String = "encode_internal_message"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfEncodeInternalMessage, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
try handler(response)
}
}

/// Combines `hex`-encoded `signature` with `base64`-encoded `unsigned_message`. Returns signed message encoded in `base64`.
public func attach_signature(_ payload: TSDKParamsOfAttachSignature, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfAttachSignature, TSDKClientError, TSDKDefault>) -> Void
public func attach_signature(_ payload: TSDKParamsOfAttachSignature, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfAttachSignature, TSDKClientError, TSDKDefault>) throws -> Void
) {
let method: String = "attach_signature"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfAttachSignature, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
try handler(response)
}
}

/// Decodes message body using provided message BOC and ABI.
public func decode_message(_ payload: TSDKParamsOfDecodeMessage, _ handler: @escaping (TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError, TSDKDefault>) -> Void
public func decode_message(_ payload: TSDKParamsOfDecodeMessage, _ handler: @escaping (TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError, TSDKDefault>) throws -> Void
) {
let method: String = "decode_message"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
try handler(response)
}
}

/// Decodes message body using provided body BOC and ABI.
public func decode_message_body(_ payload: TSDKParamsOfDecodeMessageBody, _ handler: @escaping (TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError, TSDKDefault>) -> Void
public func decode_message_body(_ payload: TSDKParamsOfDecodeMessageBody, _ handler: @escaping (TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError, TSDKDefault>) throws -> Void
) {
let method: String = "decode_message_body"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
try handler(response)
}
}

/// Creates account state BOC
/// Creates account state provided with one of these sets of data :
/// 1. BOC of code, BOC of data, BOC of library2. TVC (string in `base64`), keys, init params
public func encode_account(_ payload: TSDKParamsOfEncodeAccount, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeAccount, TSDKClientError, TSDKDefault>) -> Void
public func encode_account(_ payload: TSDKParamsOfEncodeAccount, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeAccount, TSDKClientError, TSDKDefault>) throws -> Void
) {
let method: String = "encode_account"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfEncodeAccount, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
try handler(response)
}
}

/// Decodes account data using provided data BOC and ABI.
/// Note: this feature requires ABI 2.1 or higher.
public func decode_account_data(_ payload: TSDKParamsOfDecodeAccountData, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfDecodeData, TSDKClientError, TSDKDefault>) -> Void
public func decode_account_data(_ payload: TSDKParamsOfDecodeAccountData, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfDecodeData, TSDKClientError, TSDKDefault>) throws -> Void
) {
let method: String = "decode_account_data"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfDecodeData, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
try handler(response)
}
}

}
Loading

0 comments on commit 931c4d3

Please sign in to comment.