Skip to content

Commit

Permalink
up 1.23
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Oct 16, 2021
1 parent bcfc714 commit 12e7aee
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 9 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.22.0-orange)](https://github.com/tonlabs/TON-SDK)
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.23.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
22 changes: 22 additions & 0 deletions Sources/TonClientSwift/Abi/Abi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,26 @@ public final class TSDKAbiModule {
}
}

/// Updates initial account data with initial values for the contract's static variables and owner's public key. This operation is applicable only for initial account data (before deploy). If the contract is already deployed, its data doesn't contain this data section any more.
public func update_initial_data(_ payload: TSDKParamsOfUpdateInitialData, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfUpdateInitialData, TSDKClientError>) throws -> Void
) {
let method: String = "update_initial_data"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfUpdateInitialData, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

/// Decodes initial values of a contract's static variables and owner's public key from account initial data This operation is applicable only for initial account data (before deploy). If the contract is already deployed, its data doesn't contain this data section any more.
public func decode_initial_data(_ payload: TSDKParamsOfDecodeInitialData, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfDecodeInitialData, TSDKClientError>) throws -> Void
) {
let method: String = "decode_initial_data"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfDecodeInitialData, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

}
58 changes: 58 additions & 0 deletions Sources/TonClientSwift/Abi/AbiTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum TSDKAbiErrorCode: Int, Codable {
case InvalidAbi = 311
case InvalidFunctionId = 312
case InvalidData = 313
case EncodeInitialDataFailed = 314
}

public enum TSDKAbiEnumTypes: String, Codable {
Expand Down Expand Up @@ -554,3 +555,60 @@ public struct TSDKResultOfDecodeData: Codable {
}
}

public struct TSDKParamsOfUpdateInitialData: Codable {
/// Contract ABI
public var abi: TSDKAbi?
/// Data BOC or BOC handle
public var data: String
/// List of initial values for contract's static variables.
/// `abi` parameter should be provided to set initial data
public var initial_data: AnyValue?
/// Initial account owner's public key to set into account data
public var initial_pubkey: String?
/// Cache type to put the result. The BOC itself returned if no cache type provided.
public var boc_cache: TSDKBocCacheType?

public init(abi: TSDKAbi? = nil, data: String, initial_data: AnyValue? = nil, initial_pubkey: String? = nil, boc_cache: TSDKBocCacheType? = nil) {
self.abi = abi
self.data = data
self.initial_data = initial_data
self.initial_pubkey = initial_pubkey
self.boc_cache = boc_cache
}
}

public struct TSDKResultOfUpdateInitialData: Codable {
/// Updated data BOC or BOC handle
public var data: String

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

public struct TSDKParamsOfDecodeInitialData: Codable {
/// Contract ABI.
/// Initial data is decoded if this parameter is provided
public var abi: TSDKAbi?
/// Data BOC or BOC handle
public var data: String

public init(abi: TSDKAbi? = nil, data: String) {
self.abi = abi
self.data = data
}
}

public struct TSDKResultOfDecodeInitialData: Codable {
/// List of initial values of contract's public variables.
/// Initial data is decoded if `abi` input parameter is provided
public var initial_data: AnyValue?
/// Initial account owner's public key
public var initial_pubkey: String

public init(initial_data: AnyValue? = nil, initial_pubkey: String) {
self.initial_data = initial_data
self.initial_pubkey = initial_pubkey
}
}

56 changes: 56 additions & 0 deletions Sources/TonClientSwift/Boc/Boc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,60 @@ public final class TSDKBocModule {
}
}

/// Returns the contract code's salt if it is present.
public func get_code_salt(_ payload: TSDKParamsOfGetCodeSalt, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfGetCodeSalt, TSDKClientError>) throws -> Void
) {
let method: String = "get_code_salt"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfGetCodeSalt, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

/// Sets new salt to contract code.
/// Returns the new contract code with salt.
public func set_code_salt(_ payload: TSDKParamsOfSetCodeSalt, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfSetCodeSalt, TSDKClientError>) throws -> Void
) {
let method: String = "set_code_salt"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfSetCodeSalt, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

/// Decodes tvc into code, data, libraries and special options.
public func decode_tvc(_ payload: TSDKParamsOfDecodeTvc, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfDecodeTvc, TSDKClientError>) throws -> Void
) {
let method: String = "decode_tvc"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfDecodeTvc, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

/// Encodes tvc from code, data, libraries ans special options (see input params)
public func encode_tvc(_ payload: TSDKParamsOfEncodeTvc, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeTvc, TSDKClientError>) throws -> Void
) {
let method: String = "encode_tvc"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfEncodeTvc, 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
) {
let method: String = "get_compiler_version"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfGetCompilerVersion, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

}
144 changes: 143 additions & 1 deletion Sources/TonClientSwift/Boc/BocTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public struct TSDKResultOfGetBocHash: Codable {
}

public struct TSDKParamsOfGetCodeFromTvc: Codable {
/// Contract TVC image encoded as base64
/// Contract TVC image or image BOC handle
public var tvc: String

public init(tvc: String) {
Expand Down Expand Up @@ -214,3 +214,145 @@ public struct TSDKResultOfEncodeBoc: Codable {
}
}

public struct TSDKParamsOfGetCodeSalt: Codable {
/// Contract code BOC encoded as base64 or code BOC handle
public var code: String
/// Cache type to put the result. The BOC itself returned if no cache type provided.
public var boc_cache: TSDKBocCacheType?

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

public struct TSDKResultOfGetCodeSalt: Codable {
/// Contract code salt if present.
/// BOC encoded as base64 or BOC handle
public var salt: String?

public init(salt: String? = nil) {
self.salt = salt
}
}

public struct TSDKParamsOfSetCodeSalt: Codable {
/// Contract code BOC encoded as base64 or code BOC handle
public var code: String
/// Code salt to set.
/// BOC encoded as base64 or BOC handle
public var salt: String
/// Cache type to put the result. The BOC itself returned if no cache type provided.
public var boc_cache: TSDKBocCacheType?

public init(code: String, salt: String, boc_cache: TSDKBocCacheType? = nil) {
self.code = code
self.salt = salt
self.boc_cache = boc_cache
}
}

public struct TSDKResultOfSetCodeSalt: Codable {
/// Contract code with salt set.
/// BOC encoded as base64 or BOC handle
public var code: String

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

public struct TSDKParamsOfDecodeTvc: Codable {
/// Contract TVC image BOC encoded as base64 or BOC handle
public var tvc: String
/// Cache type to put the result. The BOC itself returned if no cache type provided.
public var boc_cache: TSDKBocCacheType?

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

public struct TSDKResultOfDecodeTvc: Codable {
/// Contract code BOC encoded as base64 or BOC handle
public var code: String?
/// Contract data BOC encoded as base64 or BOC handle
public var data: String?
/// Contract library BOC encoded as base64 or BOC handle
public var library: String?
/// `special.tick` field.
/// Specifies the contract ability to handle tick transactions
public var tick: Bool?
/// `special.tock` field.
/// Specifies the contract ability to handle tock transactions
public var tock: Bool?
/// Is present and non-zero only in instances of large smart contracts
public var split_depth: UInt32?

public init(code: String? = nil, data: String? = nil, library: String? = nil, tick: Bool? = nil, tock: Bool? = nil, split_depth: UInt32? = nil) {
self.code = code
self.data = data
self.library = library
self.tick = tick
self.tock = tock
self.split_depth = split_depth
}
}

public struct TSDKParamsOfEncodeTvc: Codable {
/// Contract code BOC encoded as base64 or BOC handle
public var code: String?
/// Contract data BOC encoded as base64 or BOC handle
public var data: String?
/// Contract library BOC encoded as base64 or BOC handle
public var library: String?
/// `special.tick` field.
/// Specifies the contract ability to handle tick transactions
public var tick: Bool?
/// `special.tock` field.
/// Specifies the contract ability to handle tock transactions
public var tock: Bool?
/// Is present and non-zero only in instances of large smart contracts
public var split_depth: UInt32?
/// Cache type to put the result. The BOC itself returned if no cache type provided.
public var boc_cache: TSDKBocCacheType?

public init(code: String? = nil, data: String? = nil, library: String? = nil, tick: Bool? = nil, tock: Bool? = nil, split_depth: UInt32? = nil, boc_cache: TSDKBocCacheType? = nil) {
self.code = code
self.data = data
self.library = library
self.tick = tick
self.tock = tock
self.split_depth = split_depth
self.boc_cache = boc_cache
}
}

public struct TSDKResultOfEncodeTvc: Codable {
/// Contract TVC image BOC encoded as base64 or BOC handle of boc_cache parameter was specified
public var tvc: String

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

public struct TSDKParamsOfGetCompilerVersion: Codable {
/// Contract code BOC encoded as base64 or code BOC handle
public var code: String

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

public struct TSDKResultOfGetCompilerVersion: Codable {
/// Compiler version, for example 'sol 0.49.0'
public var version: String?

public init(version: String? = nil) {
self.version = version
}
}

25 changes: 18 additions & 7 deletions Sources/TonClientSwift/Net/Net.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,25 @@ public final class TSDKNetModule {
}
}

/// Returns transactions tree for specific message.
/// Performs recursive retrieval of the transactions tree produced by the specific message:
/// Returns a tree of transactions triggered by a specific message.
/// Performs recursive retrieval of a transactions tree produced by a specific message:
/// in_msg -> dst_transaction -> out_messages -> dst_transaction -> ...
/// All retrieved messages and transactions will be includedinto `result.messages` and `result.transactions` respectively.
/// The retrieval process will stop when the retrieved transaction count is more than 50.
/// It is guaranteed that each message in `result.messages` has the corresponding transactionin the `result.transactions`.
/// But there are no guaranties that all messages from transactions `out_msgs` arepresented in `result.messages`.
/// So the application have to continue retrieval for missing messages if it requires.
/// If the chain of transactions execution is in progress while the function is running,it will wait for the next transactions to appear until the full tree or more than 50 transactionsare received.
/// All the retrieved messages and transactions are includedinto `result.messages` and `result.transactions` respectively.
/// Function reads transactions layer by layer, by pages of 20 transactions.
/// The retrieval prosess goes like this:
/// Let's assume we have an infinite chain of transactions and each transaction generates 5 messages.
/// 1. Retrieve 1st message (input parameter) and corresponding transaction - put it into result.
/// It is the first level of the tree of transactions - its root.
/// Retrieve 5 out message ids from the transaction for next steps.
/// 2. Retrieve 5 messages and corresponding transactions on the 2nd layer. Put them into result.
/// Retrieve 5*5 out message ids from these transactions for next steps3. Retrieve 20 (size of the page) messages and transactions (3rd layer) and 20*5=100 message ids (4th layer).
/// 4. Retrieve the last 5 messages and 5 transactions on the 3rd layer + 15 messages and transactions (of 100) from the 4th layer+ 25 message ids of the 4th layer + 75 message ids of the 5th layer.
/// 5. Retrieve 20 more messages and 20 more transactions of the 4th layer + 100 more message ids of the 5th layer.
/// 6. Now we have 1+5+20+20+20 = 66 transactions, which is more than 50. Function exits with the tree of1m->1t->5m->5t->25m->25t->35m->35t. If we see any message ids in the last transactions out_msgs, which don't havecorresponding messages in the function result, it means that the full tree was not received and we need to continue iteration.
/// To summarize, it is guaranteed that each message in `result.messages` has the corresponding transactionin the `result.transactions`.
/// But there is no guarantee that all messages from transactions `out_msgs` arepresented in `result.messages`.
/// So the application has to continue retrieval for missing messages if it requires.
public func query_transaction_tree(_ payload: TSDKParamsOfQueryTransactionTree, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfQueryTransactionTree, TSDKClientError>) throws -> Void
) {
let method: String = "query_transaction_tree"
Expand Down

0 comments on commit 12e7aee

Please sign in to comment.