diff --git a/ApiParser/Sources/ApiParser/CodeGenerator.swift b/ApiParser/Sources/ApiParser/CodeGenerator.swift index 22c8d74..18d1df8 100644 --- a/ApiParser/Sources/ApiParser/CodeGenerator.swift +++ b/ApiParser/Sources/ApiParser/CodeGenerator.swift @@ -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 { diff --git a/README.md b/README.md index 3d419ce..91a64f0 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/Sources/TonClientSwift/Abi/Abi.swift b/Sources/TonClientSwift/Abi/Abi.swift index 782095c..904a62a 100644 --- a/Sources/TonClientSwift/Abi/Abi.swift +++ b/Sources/TonClientSwift/Abi/Abi.swift @@ -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) throws -> Void + ) { + let method: String = "encode_initial_data" + binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in + var response: TSDKBindingResponse = .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) throws -> Void ) { diff --git a/Sources/TonClientSwift/Abi/AbiTypes.swift b/Sources/TonClientSwift/Abi/AbiTypes.swift index e305847..b18d448 100644 --- a/Sources/TonClientSwift/Abi/AbiTypes.swift +++ b/Sources/TonClientSwift/Abi/AbiTypes.swift @@ -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 @@ -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 @@ -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 diff --git a/Sources/TonClientSwift/Debot/DebotTypes.swift b/Sources/TonClientSwift/Debot/DebotTypes.swift index 307ff3d..5b55510 100644 --- a/Sources/TonClientSwift/Debot/DebotTypes.swift +++ b/Sources/TonClientSwift/Debot/DebotTypes.swift @@ -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 { @@ -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 @@ -102,6 +105,7 @@ public struct TSDKDebotInfo: Codable { self.dabi = dabi self.icon = icon self.interfaces = interfaces + self.dabiVersion = dabiVersion } } diff --git a/Sources/TonClientSwift/Proofs/Proofs.swift b/Sources/TonClientSwift/Proofs/Proofs.swift index 50d3422..3551f7d 100644 --- a/Sources/TonClientSwift/Proofs/Proofs.swift +++ b/Sources/TonClientSwift/Proofs/Proofs.swift @@ -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) throws -> Void ) { @@ -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) throws -> Void + ) { + let method: String = "proof_message_data" + binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in + var response: TSDKBindingResponse = .init() + response.update(requestId, params, responseType, finished) + try handler(response) + } + } + } diff --git a/Sources/TonClientSwift/Proofs/ProofsTypes.swift b/Sources/TonClientSwift/Proofs/ProofsTypes.swift index 070b43d..4af02a8 100644 --- a/Sources/TonClientSwift/Proofs/ProofsTypes.swift +++ b/Sources/TonClientSwift/Proofs/ProofsTypes.swift @@ -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 + } +} + diff --git a/Sources/TonClientSwift/Tvm/TvmTypes.swift b/Sources/TonClientSwift/Tvm/TvmTypes.swift index 8493900..25909a2 100644 --- a/Sources/TonClientSwift/Tvm/TvmTypes.swift +++ b/Sources/TonClientSwift/Tvm/TvmTypes.swift @@ -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