Skip to content

Commit

Permalink
version update
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Dec 8, 2021
1 parent 23da11e commit e9d28a0
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ApiParser/Sources/ApiParser/CodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CodeGenerator {
}

private func clearFile(content: String) -> String {
content.replace(#"\?+\s"#, "? ")
content.replace(#"\?+ "#, "? ").replace(#"\?+\n"#, "?\n")
}

private func generateAlias(_ swiftAlias: SDKSwiftTypeAlias) -> String {
Expand Down
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.25.0-orange)](https://github.com/tonlabs/TON-SDK)
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.26.1-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
12 changes: 12 additions & 0 deletions Sources/TonClientSwift/Abi/Abi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ public final class TSDKAbiModule {
}
}

/// Encodes initial account data with initial values for the contract's static variables and owner's public key into a data BOC that can be passed to `encode_tvc` function afterwards.
/// This function is analogue of `tvm.buildDataInit` function in Solidity.
public func encode_initial_data(_ payload: TSDKParamsOfEncodeInitialData, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeInitialData, TSDKClientError>) throws -> Void
) {
let method: String = "encode_initial_data"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfEncodeInitialData, 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
) {
Expand Down
40 changes: 34 additions & 6 deletions Sources/TonClientSwift/Abi/AbiTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ public struct TSDKStateInitSource: Codable {
public var data: String?
/// Library BOC.
/// Encoded in `base64`.
public var library: String??
public var library: String?
public var tvc: String?
public var public_key: String??
public var init_params: TSDKStateInitParams??
public var public_key: String?
public var init_params: TSDKStateInitParams?

public init(type: TSDKStateInitSourceEnumTypes, source: TSDKMessageSource? = nil, code: String? = nil, data: String? = nil, library: String?? = nil, tvc: String? = nil, public_key: String?? = nil, init_params: TSDKStateInitParams?? = nil) {
public init(type: TSDKStateInitSourceEnumTypes, source: TSDKMessageSource? = nil, code: String? = nil, data: String? = nil, library: String? = nil, tvc: String? = nil, public_key: String? = nil, init_params: TSDKStateInitParams? = nil) {
self.type = type
self.source = source
self.code = code
Expand All @@ -170,9 +170,9 @@ public struct TSDKStateInitParams: Codable {
public struct TSDKMessageSource: Codable {
public var type: TSDKMessageSourceEnumTypes
public var message: String?
public var abi: TSDKAbi??
public var abi: TSDKAbi?

public init(type: TSDKMessageSourceEnumTypes, message: String? = nil, abi: TSDKAbi?? = nil) {
public init(type: TSDKMessageSourceEnumTypes, message: String? = nil, abi: TSDKAbi? = nil) {
self.type = type
self.message = message
self.abi = abi
Expand Down Expand Up @@ -586,6 +586,34 @@ public struct TSDKResultOfUpdateInitialData: Codable {
}
}

public struct TSDKParamsOfEncodeInitialData: Codable {
/// Contract ABI
public var abi: TSDKAbi?
/// 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, initial_data: AnyValue? = nil, initial_pubkey: String? = nil, boc_cache: TSDKBocCacheType? = nil) {
self.abi = abi
self.initial_data = initial_data
self.initial_pubkey = initial_pubkey
self.boc_cache = boc_cache
}
}

public struct TSDKResultOfEncodeInitialData: 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
Expand Down
6 changes: 5 additions & 1 deletion Sources/TonClientSwift/Debot/DebotTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum TSDKDebotErrorCode: Int, Codable {
case DebotExternalCallFailed = 810
case DebotBrowserCallbackFailed = 811
case DebotOperationRejected = 812
case DebotNoCode = 813
}

public enum TSDKDebotActivityEnumTypes: String, Codable {
Expand Down Expand Up @@ -89,8 +90,10 @@ public struct TSDKDebotInfo: Codable {
public var icon: String?
/// Vector with IDs of DInterfaces used by DeBot.
public var interfaces: [String]
/// ABI version ("x.y") supported by DeBot
public var dabiVersion: String

public init(name: String? = nil, version: String? = nil, publisher: String? = nil, caption: String? = nil, author: String? = nil, support: String? = nil, hello: String? = nil, language: String? = nil, dabi: String? = nil, icon: String? = nil, interfaces: [String]) {
public init(name: String? = nil, version: String? = nil, publisher: String? = nil, caption: String? = nil, author: String? = nil, support: String? = nil, hello: String? = nil, language: String? = nil, dabi: String? = nil, icon: String? = nil, interfaces: [String], dabiVersion: String) {
self.name = name
self.version = version
self.publisher = publisher
Expand All @@ -102,6 +105,7 @@ public struct TSDKDebotInfo: Codable {
self.dabi = dabi
self.icon = icon
self.interfaces = interfaces
self.dabiVersion = dabiVersion
}
}

Expand Down
22 changes: 19 additions & 3 deletions Sources/TonClientSwift/Proofs/Proofs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ public final class TSDKProofsModule {
}

/// Proves that a given transaction's data, which is queried from TONOS API, can be trusted.
/// This function requests the corresponding block, checks block proofs, ensures that given transactionexists in the proven block and compares given data with the proven.
/// This function requests the corresponding block, checks block proofs, ensures that giventransaction exists in the proven block and compares given data with the proven.
/// If the given data differs from the proven, the exception will be thrown.
/// The input parameter is a single transaction's JSON object (see params description),which was queried from TONOS API using functions such as `net.query`, `net.query_collection`or `net.wait_for_collection`.
/// If transaction's BOC and/or `block_id` are not provided in the JSON, they will be queried fromTONOS API (in this case it is required to provide at least `id` of transaction).
/// If transaction's BOC and/or `block_id` are not provided in the JSON, they will be queried fromTONOS API.
/// Please note, that joins (like `account`, `in_message`, `out_messages`, etc. in `Transaction`entity) are separated entities and not supported, so function will throw an exception in a caseif JSON being checked has such entities in it.
/// If `cache_in_local_storage` in config is set to `true` (default), downloaded proofs andmaster-chain BOCs are saved into the persistent local storage (e.g. file system for nativeenvironments or browser's IndexedDB for the web); otherwise all the data is cached only inmemory in current client's context and will be lost after destruction of the client.
/// For more information about proofs checking, see description of `proof_block_data` function.
public func proof_transaction_data(_ payload: TSDKParamsOfProofTransactionData, _ handler: @escaping (TSDKBindingResponse<TSDKNoneResult, TSDKClientError>) throws -> Void
) {
Expand All @@ -51,4 +50,21 @@ public final class TSDKProofsModule {
}
}

/// Proves that a given message's data, which is queried from TONOS API, can be trusted.
/// This function first proves the corresponding transaction, ensures that the proven transactionrefers to the given message and compares given data with the proven.
/// If the given data differs from the proven, the exception will be thrown.
/// The input parameter is a single message's JSON object (see params description),which was queried from TONOS API using functions such as `net.query`, `net.query_collection`or `net.wait_for_collection`.
/// If message's BOC and/or non-null `src_transaction.id` or `dst_transaction.id` are not providedin the JSON, they will be queried from TONOS API.
/// Please note, that joins (like `block`, `dst_account`, `dst_transaction`, `src_account`,`src_transaction`, etc. in `Message` entity) are separated entities and not supported,so function will throw an exception in a case if JSON being checked has such entities in it.
/// For more information about proofs checking, see description of `proof_block_data` function.
public func proof_message_data(_ payload: TSDKParamsOfProofMessageData, _ handler: @escaping (TSDKBindingResponse<TSDKNoneResult, TSDKClientError>) throws -> Void
) {
let method: String = "proof_message_data"
binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKNoneResult, TSDKClientError> = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}

}
9 changes: 9 additions & 0 deletions Sources/TonClientSwift/Proofs/ProofsTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ public struct TSDKParamsOfProofTransactionData: Codable {
}
}

public struct TSDKParamsOfProofMessageData: Codable {
/// Single message's data as queried from DApp server, without modifications. The required fields are `id` and/or top-level `boc`, others are optional. In order to reduce network requests count, it is recommended to provide at least `boc` of message and non-null `src_transaction.id` or `dst_transaction.id`.
public var message: AnyValue

public init(message: AnyValue) {
self.message = message
}
}

4 changes: 2 additions & 2 deletions Sources/TonClientSwift/Tvm/TvmTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public struct TSDKAccountForExecutor: Codable {
public var boc: String?
/// Flag for running account with the unlimited balance.
/// Can be used to calculate transaction fees without balance check
public var unlimited_balance: Bool??
public var unlimited_balance: Bool?

public init(type: TSDKAccountForExecutorEnumTypes, boc: String? = nil, unlimited_balance: Bool?? = nil) {
public init(type: TSDKAccountForExecutorEnumTypes, boc: String? = nil, unlimited_balance: Bool? = nil) {
self.type = type
self.boc = boc
self.unlimited_balance = unlimited_balance
Expand Down

0 comments on commit e9d28a0

Please sign in to comment.