Skip to content

Commit

Permalink
up 1.30
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Feb 10, 2022
1 parent 3e60f07 commit 7b44792
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Swift Client for Free Ton SDK

[![SPM](https://img.shields.io/badge/swift-package%20manager-green)](https://swift.org/package-manager/)
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.28.1-orange)](https://github.com/tonlabs/TON-SDK)
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.30.0-orange)](https://github.com/tonlabs/TON-SDK)

Swift is a strongly typed language that has long been used not only for iOS development. Apple is actively promoting it to new platforms and today it can be used for almost any task. Thanks to this, this implementation provides the work of TonSDK on many platforms at once, including the native one for mobile phones. Let me remind you that swift can also be built for android.

Expand Down
11 changes: 11 additions & 0 deletions Sources/TonClientSwift/Abi/Abi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,15 @@ public final class TSDKAbiModule {
}
}

/// Encodes given parameters in JSON into a BOC using param types from ABI.
public func encode_boc(_ payload: TSDKParamsOfAbiEncodeBoc, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfAbiEncodeBoc, TSDKClientError>) throws -> Void
) {
let method: String = "encode_boc"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfAbiEncodeBoc, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

}
25 changes: 25 additions & 0 deletions Sources/TonClientSwift/Abi/AbiTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,28 @@ public struct TSDKResultOfDecodeBoc: Codable {
}
}

public struct TSDKParamsOfAbiEncodeBoc: Codable {
/// Parameters to encode into BOC
public var params: [TSDKAbiParam]
/// Parameters and values as a JSON structure
public var data: AnyValue
/// Cache type to put the result.
/// The BOC itself returned if no cache type provided
public var boc_cache: TSDKBocCacheType?

public init(params: [TSDKAbiParam], data: AnyValue, boc_cache: TSDKBocCacheType? = nil) {
self.params = params
self.data = data
self.boc_cache = boc_cache
}
}

public struct TSDKResultOfAbiEncodeBoc: Codable {
/// BOC encoded as base64
public var boc: String

public init(boc: String) {
self.boc = boc
}
}

14 changes: 13 additions & 1 deletion Sources/TonClientSwift/Boc/Boc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public final class TSDKBocModule {
}
}

/// Encodes bag of cells (BOC) with builder operations. This method provides the same functionality as Solidity TvmBuilder. Resulting BOC of this method can be passed into Solidity and C++ contracts as TvmCell type
/// Encodes bag of cells (BOC) with builder operations. This method provides the same functionality as Solidity TvmBuilder. Resulting BOC of this method can be passed into Solidity and C++ contracts as TvmCell type.
public func encode_boc(_ payload: TSDKParamsOfEncodeBoc, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeBoc, TSDKClientError>) throws -> Void
) {
let method: String = "encode_boc"
Expand Down Expand Up @@ -201,6 +201,18 @@ public final class TSDKBocModule {
}
}

/// Encodes a message
/// Allows to encode any external inbound message.
public func encode_external_in_message(_ payload: TSDKParamsOfEncodeExternalInMessage, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeExternalInMessage, TSDKClientError>) throws -> Void
) {
let method: String = "encode_external_in_message"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfEncodeExternalInMessage, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

/// Returns the compiler version used to compile the code.
public func get_compiler_version(_ payload: TSDKParamsOfGetCompilerVersion, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfGetCompilerVersion, TSDKClientError>) throws -> Void
) {
Expand Down
42 changes: 40 additions & 2 deletions Sources/TonClientSwift/Boc/BocTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum TSDKBuilderOpEnumTypes: String, Codable {
case BitString = "BitString"
case Cell = "Cell"
case CellBoc = "CellBoc"
case Address = "Address"
}

public struct TSDKBocCacheType: Codable {
Expand Down Expand Up @@ -196,17 +197,20 @@ public struct TSDKBuilderOp: Codable {
/// - `0x` prefixed hexadecimal string.
/// e.g `0x123`, `0X123`, `-0x123`.
public var value: AnyValue?
/// Nested cell builder
/// Nested cell builder.
public var builder: [TSDKBuilderOp]?
/// Nested cell BOC encoded with `base64` or BOC cache key.
public var boc: String?
/// Address in a common `workchain:account` or base64 format.
public var address: String?

public init(type: TSDKBuilderOpEnumTypes, size: UInt32? = nil, value: AnyValue? = nil, builder: [TSDKBuilderOp]? = nil, boc: String? = nil) {
public init(type: TSDKBuilderOpEnumTypes, size: UInt32? = nil, value: AnyValue? = nil, builder: [TSDKBuilderOp]? = nil, boc: String? = nil, address: String? = nil) {
self.type = type
self.size = size
self.value = value
self.builder = builder
self.boc = boc
self.address = address
}
}

Expand Down Expand Up @@ -371,6 +375,40 @@ public struct TSDKResultOfEncodeTvc: Codable {
}
}

public struct TSDKParamsOfEncodeExternalInMessage: Codable {
/// Source address.
public var src: String?
/// Destination address.
public var dst: String
/// Bag of cells with state init (used in deploy messages).
public var init: String?
/// Bag of cells with the message body encoded as base64.
public var body: String?
/// Cache type to put the result.
/// The BOC itself returned if no cache type provided
public var boc_cache: TSDKBocCacheType?

public init(src: String? = nil, dst: String, init: String? = nil, body: String? = nil, boc_cache: TSDKBocCacheType? = nil) {
self.src = src
self.dst = dst
self.init = init
self.body = body
self.boc_cache = boc_cache
}
}

public struct TSDKResultOfEncodeExternalInMessage: Codable {
/// Message BOC encoded with `base64`.
public var message: String
/// Message id.
public var message_id: String

public init(message: String, message_id: String) {
self.message = message
self.message_id = message_id
}
}

public struct TSDKParamsOfGetCompilerVersion: Codable {
/// Contract code BOC encoded as base64 or code BOC handle
public var code: String
Expand Down
26 changes: 25 additions & 1 deletion Sources/TonClientSwift/Net/Net.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public final class TSDKNetModule {
}
}

/// Creates a subscription
/// Creates a collection subscription
/// Triggers for each insert/update of data that satisfiesthe `filter` conditions.
/// The projection fields are limited to `result` fields.
/// The subscription is a persistent communication channel betweenclient and Free TON Network.
Expand Down Expand Up @@ -109,6 +109,30 @@ public final class TSDKNetModule {
}
}

/// Creates a subscription
/// The subscription is a persistent communication channel betweenclient and Everscale Network.
/// ### Important Notes on SubscriptionsUnfortunately sometimes the connection with the network brakes down.
/// In this situation the library attempts to reconnect to the network.
/// This reconnection sequence can take significant time.
/// All of this time the client is disconnected from the network.
/// Bad news is that all changes that happened whilethe client was disconnected are lost.
/// Good news is that the client report errors to the callback whenit loses and resumes connection.
/// So, if the lost changes are important to the application thenthe application must handle these error reports.
/// Library reports errors with `responseType` == 101and the error object passed via `params`.
/// When the library has successfully reconnectedthe application receives callback with`responseType` == 101 and `params.code` == 614 (NetworkModuleResumed).
/// Application can use several ways to handle this situation:
/// - If application monitors changes for the singleobject (for example specific account): applicationcan perform a query for this object and handle actual data as aregular data from the subscription.
/// - If application monitors sequence of some objects(for example transactions of the specific account): application mustrefresh all cached (or visible to user) lists where this sequences presents.
public func subscribe(_ payload: TSDKParamsOfSubscribe, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfSubscribeCollection, TSDKClientError>) throws -> Void
) {
let method: String = "subscribe"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfSubscribeCollection, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

/// Suspends network module to stop any network activity
public func suspend(_ handler: @escaping (TSDKBindingResponse<TSDKNoneResult, TSDKClientError>) throws -> Void
) {
Expand Down
13 changes: 13 additions & 0 deletions Sources/TonClientSwift/Net/NetTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ public struct TSDKParamsOfSubscribeCollection: Codable {
}
}

public struct TSDKParamsOfSubscribe: Codable {
/// GraphQL subscription text.
public var subscription: String
/// Variables used in subscription.
/// Must be a map with named values that can be used in query.
public var variables: AnyValue?

public init(subscription: String, variables: AnyValue? = nil) {
self.subscription = subscription
self.variables = variables
}
}

public struct TSDKParamsOfFindLastShardBlock: Codable {
/// Account address
public var address: String
Expand Down

0 comments on commit 7b44792

Please sign in to comment.