From c5767f97e3a5eded2cbcad5095f16f9d790e9d90 Mon Sep 17 00:00:00 2001
From: nerzh
Date: Sun, 25 Jun 2023 12:29:59 +0200
Subject: [PATCH] up
---
README.md | 4 +-
.../EverscaleClientSwift/Abi/AbiTypes.swift | 15 +-
Sources/EverscaleClientSwift/Boc/Boc.swift | 67 ++++++---
.../EverscaleClientSwift/Boc/BocTypes.swift | 136 ++++++++++++------
.../Client/ClientTypes.swift | 2 +-
.../EverscaleClientSwift/Tvm/TvmTypes.swift | 1 +
6 files changed, 156 insertions(+), 69 deletions(-)
diff --git a/README.md b/README.md
index e9faed6..6a19b28 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,15 @@
# Swift Client for TVM SDK (toncoin, everscale, venom, gosh)
+
+-->
[![SPM](https://img.shields.io/badge/swift-package%20manager-green)](https://swift.org/package-manager/)
-[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.42.1-orange)](https://github.com/tonlabs/ever-sdk)
+[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.43.3-orange)](https://github.com/tonlabs/ever-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 TVM (toncoin, everscale, venom, gosh) SDK 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/EverscaleClientSwift/Abi/AbiTypes.swift b/Sources/EverscaleClientSwift/Abi/AbiTypes.swift
index f853625..5f1ab6b 100644
--- a/Sources/EverscaleClientSwift/Abi/AbiTypes.swift
+++ b/Sources/EverscaleClientSwift/Abi/AbiTypes.swift
@@ -70,7 +70,8 @@ public struct TSDKAbi: Codable {
}
public struct TSDKFunctionHeader: Codable {
- /// Message expiration time in seconds. If not specified - calculated automatically from message_expiration_timeout(), try_index and message_expiration_timeout_grow_factor() (if ABI includes `expire` header).
+ /// Message expiration timestamp (UNIX time) in seconds.
+ /// If not specified - calculated automatically from message_expiration_timeout(),try_index and message_expiration_timeout_grow_factor() (if ABI includes `expire` header).
public var expire: UInt32?
/// Message creation time in milliseconds.
/// If not specified, `now` is used (if ABI includes `time` header).
@@ -103,8 +104,12 @@ public struct TSDKCallSet: Codable {
}
public struct TSDKDeploySet: Codable {
- /// Content of TVC file encoded in `base64`.
- public var tvc: String
+ /// Content of TVC file encoded in `base64`. For compatibility reason this field can contain an encoded `StateInit`.
+ public var tvc: String?
+ /// Contract code BOC encoded with base64.
+ public var code: String?
+ /// State init BOC encoded with base64.
+ public var state_init: String?
/// Target workchain for destination address.
/// Default is `0`.
public var workchain_id: Int32?
@@ -117,8 +122,10 @@ public struct TSDKDeploySet: Codable {
/// 3. Public key, provided by Signer.
public var initial_pubkey: String?
- public init(tvc: String, workchain_id: Int32? = nil, initial_data: AnyValue? = nil, initial_pubkey: String? = nil) {
+ public init(tvc: String? = nil, code: String? = nil, state_init: String? = nil, workchain_id: Int32? = nil, initial_data: AnyValue? = nil, initial_pubkey: String? = nil) {
self.tvc = tvc
+ self.code = code
+ self.state_init = state_init
self.workchain_id = workchain_id
self.initial_data = initial_data
self.initial_pubkey = initial_pubkey
diff --git a/Sources/EverscaleClientSwift/Boc/Boc.swift b/Sources/EverscaleClientSwift/Boc/Boc.swift
index a34d099..32f9bc7 100644
--- a/Sources/EverscaleClientSwift/Boc/Boc.swift
+++ b/Sources/EverscaleClientSwift/Boc/Boc.swift
@@ -7,6 +7,41 @@ public final class TSDKBocModule {
self.binding = binding
}
+ /// Decodes tvc according to the tvc spec. Read more about tvc structure here https://github.com/tonlabs/ever-struct/blob/main/src/scheme/mod.rs#L30
+ public func decode_tvc(_ payload: TSDKParamsOfDecodeTvc, _ handler: @escaping (TSDKBindingResponse) throws -> Void
+ ) throws {
+ let method: String = "decode_tvc"
+ try 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 tvc according to the tvc spec. Read more about tvc structure here https://github.com/tonlabs/ever-struct/blob/main/src/scheme/mod.rs#L30
+ @available(iOS 13, *)
+ @available(macOS 12, *)
+ public func decode_tvc(_ payload: TSDKParamsOfDecodeTvc) async throws -> TSDKResultOfDecodeTvc {
+ try await withCheckedThrowingContinuation { continuation in
+ do {
+ let method: String = "decode_tvc"
+ try binding.requestLibraryAsyncAwait(methodName(module, method), payload) { (requestId, params, responseType, finished) in
+ var response: TSDKBindingResponse = .init()
+ response.update(requestId, params, responseType, finished)
+ if let error = response.error {
+ continuation.resume(throwing: error)
+ } else if let result = response.result {
+ continuation.resume(returning: result)
+ } else {
+ continuation.resume(throwing: TSDKClientError("Nothing for return"))
+ }
+ }
+ } catch {
+ continuation.resume(throwing: error)
+ }
+ }
+ }
+
/// Parses message boc into a JSON
/// JSON structure is compatible with GraphQL API message object
public func parse_message(_ payload: TSDKParamsOfParse, _ handler: @escaping (TSDKBindingResponse) throws -> Void
@@ -544,26 +579,26 @@ public final class TSDKBocModule {
}
}
- /// Decodes tvc into code, data, libraries and special options.
- public func decode_tvc(_ payload: TSDKParamsOfDecodeTvc, _ handler: @escaping (TSDKBindingResponse) throws -> Void
+ /// Decodes contract's initial state into code, data, libraries and special options.
+ public func decode_state_init(_ payload: TSDKParamsOfDecodeStateInit, _ handler: @escaping (TSDKBindingResponse) throws -> Void
) throws {
- let method: String = "decode_tvc"
+ let method: String = "decode_state_init"
try binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
- var response: TSDKBindingResponse = .init()
+ var response: TSDKBindingResponse = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}
- /// Decodes tvc into code, data, libraries and special options.
+ /// Decodes contract's initial state into code, data, libraries and special options.
@available(iOS 13, *)
@available(macOS 12, *)
- public func decode_tvc(_ payload: TSDKParamsOfDecodeTvc) async throws -> TSDKResultOfDecodeTvc {
+ public func decode_state_init(_ payload: TSDKParamsOfDecodeStateInit) async throws -> TSDKResultOfDecodeStateInit {
try await withCheckedThrowingContinuation { continuation in
do {
- let method: String = "decode_tvc"
+ let method: String = "decode_state_init"
try binding.requestLibraryAsyncAwait(methodName(module, method), payload) { (requestId, params, responseType, finished) in
- var response: TSDKBindingResponse = .init()
+ var response: TSDKBindingResponse = .init()
response.update(requestId, params, responseType, finished)
if let error = response.error {
continuation.resume(throwing: error)
@@ -579,26 +614,26 @@ public final class TSDKBocModule {
}
}
- /// Encodes tvc from code, data, libraries ans special options (see input params)
- public func encode_tvc(_ payload: TSDKParamsOfEncodeTvc, _ handler: @escaping (TSDKBindingResponse) throws -> Void
+ /// Encodes initial contract state from code, data, libraries ans special options (see input params)
+ public func encode_state_init(_ payload: TSDKParamsOfEncodeStateInit, _ handler: @escaping (TSDKBindingResponse) throws -> Void
) throws {
- let method: String = "encode_tvc"
+ let method: String = "encode_state_init"
try binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
- var response: TSDKBindingResponse = .init()
+ var response: TSDKBindingResponse = .init()
response.update(requestId, params, responseType, finished)
try handler(response)
}
}
- /// Encodes tvc from code, data, libraries ans special options (see input params)
+ /// Encodes initial contract state from code, data, libraries ans special options (see input params)
@available(iOS 13, *)
@available(macOS 12, *)
- public func encode_tvc(_ payload: TSDKParamsOfEncodeTvc) async throws -> TSDKResultOfEncodeTvc {
+ public func encode_state_init(_ payload: TSDKParamsOfEncodeStateInit) async throws -> TSDKResultOfEncodeStateInit {
try await withCheckedThrowingContinuation { continuation in
do {
- let method: String = "encode_tvc"
+ let method: String = "encode_state_init"
try binding.requestLibraryAsyncAwait(methodName(module, method), payload) { (requestId, params, responseType, finished) in
- var response: TSDKBindingResponse = .init()
+ var response: TSDKBindingResponse = .init()
response.update(requestId, params, responseType, finished)
if let error = response.error {
continuation.resume(throwing: error)
diff --git a/Sources/EverscaleClientSwift/Boc/BocTypes.swift b/Sources/EverscaleClientSwift/Boc/BocTypes.swift
index 4ca37d2..0253389 100644
--- a/Sources/EverscaleClientSwift/Boc/BocTypes.swift
+++ b/Sources/EverscaleClientSwift/Boc/BocTypes.swift
@@ -7,6 +7,18 @@ public enum TSDKBocCacheTypeEnumTypes: String, Codable {
case Unpinned = "Unpinned"
}
+public enum TSDKBuilderOpEnumTypes: String, Codable {
+ case Integer = "Integer"
+ case BitString = "BitString"
+ case Cell = "Cell"
+ case CellBoc = "CellBoc"
+ case Address = "Address"
+}
+
+public enum TSDKTvcEnumTypes: String, Codable {
+ case V1 = "V1"
+}
+
public enum TSDKBocErrorCode: Int, Codable {
case InvalidBoc = 201
case SerializationError = 202
@@ -17,14 +29,6 @@ public enum TSDKBocErrorCode: Int, Codable {
case InvalidBocRef = 207
}
-public enum TSDKBuilderOpEnumTypes: String, Codable {
- case Integer = "Integer"
- case BitString = "BitString"
- case Cell = "Cell"
- case CellBoc = "CellBoc"
- case Address = "Address"
-}
-
public struct TSDKBocCacheType: Codable {
public var type: TSDKBocCacheTypeEnumTypes
public var pin: String?
@@ -35,6 +39,71 @@ public struct TSDKBocCacheType: Codable {
}
}
+public struct TSDKBuilderOp: Codable {
+ public var type: TSDKBuilderOpEnumTypes
+ /// Bit size of the value.
+ public var size: UInt32?
+ /// Value: - `Number` containing integer number.
+ /// e.g. `123`, `-123`. - Decimal string. e.g. `"123"`, `"-123"`.
+ /// - `0x` prefixed hexadecimal string.
+ /// e.g `0x123`, `0X123`, `-0x123`.
+ public var value: AnyValue?
+ /// 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, address: String? = nil) {
+ self.type = type
+ self.size = size
+ self.value = value
+ self.builder = builder
+ self.boc = boc
+ self.address = address
+ }
+}
+
+/// Cell builder operation.
+public struct TSDKTvc: Codable {
+ public var type: TSDKTvcEnumTypes
+ public var value: TSDKTvcV1?
+
+ public init(type: TSDKTvcEnumTypes, value: TSDKTvcV1? = nil) {
+ self.type = type
+ self.value = value
+ }
+}
+
+public struct TSDKTvcV1: Codable {
+ public var code: String?
+ public var description: String?
+
+ public init(code: String? = nil, description: String? = nil) {
+ self.code = code
+ self.description = description
+ }
+}
+
+public struct TSDKParamsOfDecodeTvc: Codable {
+ /// Contract TVC BOC encoded as base64 or BOC handle
+ public var tvc: String
+
+ public init(tvc: String) {
+ self.tvc = tvc
+ }
+}
+
+public struct TSDKResultOfDecodeTvc: Codable {
+ /// Decoded TVC
+ public var tvc: TSDKTvc
+
+ public init(tvc: TSDKTvc) {
+ self.tvc = tvc
+ }
+}
+
public struct TSDKParamsOfParse: Codable {
/// BOC encoded as base64
public var boc: String
@@ -192,33 +261,6 @@ public struct TSDKParamsOfBocCacheUnpin: Codable {
}
}
-public struct TSDKBuilderOp: Codable {
- public var type: TSDKBuilderOpEnumTypes
- /// Bit size of the value.
- public var size: UInt32?
- /// Value: - `Number` containing integer number.
- /// e.g. `123`, `-123`. - Decimal string. e.g. `"123"`, `"-123"`.
- /// - `0x` prefixed hexadecimal string.
- /// e.g `0x123`, `0X123`, `-0x123`.
- public var value: AnyValue?
- /// 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, address: String? = nil) {
- self.type = type
- self.size = size
- self.value = value
- self.builder = builder
- self.boc = boc
- self.address = address
- }
-}
-
-/// Cell builder operation.
public struct TSDKParamsOfEncodeBoc: Codable {
/// Cell builder operations.
public var builder: [TSDKBuilderOp]
@@ -288,19 +330,19 @@ public struct TSDKResultOfSetCodeSalt: Codable {
}
}
-public struct TSDKParamsOfDecodeTvc: Codable {
- /// Contract TVC image BOC encoded as base64 or BOC handle
- public var tvc: String
+public struct TSDKParamsOfDecodeStateInit: Codable {
+ /// Contract StateInit image BOC encoded as base64 or BOC handle
+ public var state_init: 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
+ public init(state_init: String, boc_cache: TSDKBocCacheType? = nil) {
+ self.state_init = state_init
self.boc_cache = boc_cache
}
}
-public struct TSDKResultOfDecodeTvc: Codable {
+public struct TSDKResultOfDecodeStateInit: Codable {
/// Contract code BOC encoded as base64 or BOC handle
public var code: String?
/// Contract code hash
@@ -341,7 +383,7 @@ public struct TSDKResultOfDecodeTvc: Codable {
}
}
-public struct TSDKParamsOfEncodeTvc: Codable {
+public struct TSDKParamsOfEncodeStateInit: Codable {
/// Contract code BOC encoded as base64 or BOC handle
public var code: String?
/// Contract data BOC encoded as base64 or BOC handle
@@ -370,12 +412,12 @@ public struct TSDKParamsOfEncodeTvc: Codable {
}
}
-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 struct TSDKResultOfEncodeStateInit: Codable {
+ /// Contract StateInit image BOC encoded as base64 or BOC handle of boc_cache parameter was specified
+ public var state_init: String
- public init(tvc: String) {
- self.tvc = tvc
+ public init(state_init: String) {
+ self.state_init = state_init
}
}
diff --git a/Sources/EverscaleClientSwift/Client/ClientTypes.swift b/Sources/EverscaleClientSwift/Client/ClientTypes.swift
index 3cce2c9..9194128 100644
--- a/Sources/EverscaleClientSwift/Client/ClientTypes.swift
+++ b/Sources/EverscaleClientSwift/Client/ClientTypes.swift
@@ -60,7 +60,7 @@ public struct TSDKClientError: Codable, LocalizedError {
public var failureReason: String? { self.message }
public var recoverySuggestion: String? { self.message }
public var helpAnchor: String? { self.message }
- public var data: AnyValue = ([:] as! [String: Any]).toAnyValue()
+ public var data: AnyValue = [String: Any]().toAnyValue()
public init(_ error: Error) {
self.code = 0
diff --git a/Sources/EverscaleClientSwift/Tvm/TvmTypes.swift b/Sources/EverscaleClientSwift/Tvm/TvmTypes.swift
index 68641a1..c950f7e 100644
--- a/Sources/EverscaleClientSwift/Tvm/TvmTypes.swift
+++ b/Sources/EverscaleClientSwift/Tvm/TvmTypes.swift
@@ -17,6 +17,7 @@ public enum TSDKTvmErrorCode: Int, Codable {
case InvalidAccountBoc = 412
case InvalidMessageType = 413
case ContractExecutionError = 414
+ case AccountIsSuspended = 415
}
public enum TSDKAccountForExecutorEnumTypes: String, Codable {