Skip to content

Commit c5767f9

Browse files
committed
up
1 parent 360535c commit c5767f9

File tree

6 files changed

+156
-69
lines changed

6 files changed

+156
-69
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Swift Client for TVM SDK (toncoin, everscale, venom, gosh)
22

3+
<! --
34
<p align="center">
45
<a href="https://github.com/venom-blockchain/developer-program">
56
<img src="https://raw.githubusercontent.com/venom-blockchain/developer-program/main/vf-dev-program.png" alt="Logo" width="366.8" height="146.4">
67
</a>
78
</p>
9+
-->
810

911
[![SPM](https://img.shields.io/badge/swift-package%20manager-green)](https://swift.org/package-manager/)
10-
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.42.1-orange)](https://github.com/tonlabs/ever-sdk)
12+
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.43.3-orange)](https://github.com/tonlabs/ever-sdk)
1113

1214
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.
1315

Sources/EverscaleClientSwift/Abi/AbiTypes.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public struct TSDKAbi: Codable {
7070
}
7171

7272
public struct TSDKFunctionHeader: Codable {
73-
/// 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).
73+
/// Message expiration timestamp (UNIX time) in seconds.
74+
/// If not specified - calculated automatically from message_expiration_timeout(),try_index and message_expiration_timeout_grow_factor() (if ABI includes `expire` header).
7475
public var expire: UInt32?
7576
/// Message creation time in milliseconds.
7677
/// If not specified, `now` is used (if ABI includes `time` header).
@@ -103,8 +104,12 @@ public struct TSDKCallSet: Codable {
103104
}
104105

105106
public struct TSDKDeploySet: Codable {
106-
/// Content of TVC file encoded in `base64`.
107-
public var tvc: String
107+
/// Content of TVC file encoded in `base64`. For compatibility reason this field can contain an encoded `StateInit`.
108+
public var tvc: String?
109+
/// Contract code BOC encoded with base64.
110+
public var code: String?
111+
/// State init BOC encoded with base64.
112+
public var state_init: String?
108113
/// Target workchain for destination address.
109114
/// Default is `0`.
110115
public var workchain_id: Int32?
@@ -117,8 +122,10 @@ public struct TSDKDeploySet: Codable {
117122
/// 3. Public key, provided by Signer.
118123
public var initial_pubkey: String?
119124

120-
public init(tvc: String, workchain_id: Int32? = nil, initial_data: AnyValue? = nil, initial_pubkey: String? = nil) {
125+
public init(tvc: String? = nil, code: String? = nil, state_init: String? = nil, workchain_id: Int32? = nil, initial_data: AnyValue? = nil, initial_pubkey: String? = nil) {
121126
self.tvc = tvc
127+
self.code = code
128+
self.state_init = state_init
122129
self.workchain_id = workchain_id
123130
self.initial_data = initial_data
124131
self.initial_pubkey = initial_pubkey

Sources/EverscaleClientSwift/Boc/Boc.swift

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,41 @@ public final class TSDKBocModule {
77
self.binding = binding
88
}
99

10+
/// 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
11+
public func decode_tvc(_ payload: TSDKParamsOfDecodeTvc, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfDecodeTvc, TSDKClientError>) throws -> Void
12+
) throws {
13+
let method: String = "decode_tvc"
14+
try binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
15+
var response: TSDKBindingResponse<TSDKResultOfDecodeTvc, TSDKClientError> = .init()
16+
response.update(requestId, params, responseType, finished)
17+
try handler(response)
18+
}
19+
}
20+
21+
/// 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
22+
@available(iOS 13, *)
23+
@available(macOS 12, *)
24+
public func decode_tvc(_ payload: TSDKParamsOfDecodeTvc) async throws -> TSDKResultOfDecodeTvc {
25+
try await withCheckedThrowingContinuation { continuation in
26+
do {
27+
let method: String = "decode_tvc"
28+
try binding.requestLibraryAsyncAwait(methodName(module, method), payload) { (requestId, params, responseType, finished) in
29+
var response: TSDKBindingResponse<TSDKResultOfDecodeTvc, TSDKClientError> = .init()
30+
response.update(requestId, params, responseType, finished)
31+
if let error = response.error {
32+
continuation.resume(throwing: error)
33+
} else if let result = response.result {
34+
continuation.resume(returning: result)
35+
} else {
36+
continuation.resume(throwing: TSDKClientError("Nothing for return"))
37+
}
38+
}
39+
} catch {
40+
continuation.resume(throwing: error)
41+
}
42+
}
43+
}
44+
1045
/// Parses message boc into a JSON
1146
/// JSON structure is compatible with GraphQL API message object
1247
public func parse_message(_ payload: TSDKParamsOfParse, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfParse, TSDKClientError>) throws -> Void
@@ -544,26 +579,26 @@ public final class TSDKBocModule {
544579
}
545580
}
546581

547-
/// Decodes tvc into code, data, libraries and special options.
548-
public func decode_tvc(_ payload: TSDKParamsOfDecodeTvc, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfDecodeTvc, TSDKClientError>) throws -> Void
582+
/// Decodes contract's initial state into code, data, libraries and special options.
583+
public func decode_state_init(_ payload: TSDKParamsOfDecodeStateInit, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfDecodeStateInit, TSDKClientError>) throws -> Void
549584
) throws {
550-
let method: String = "decode_tvc"
585+
let method: String = "decode_state_init"
551586
try binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
552-
var response: TSDKBindingResponse<TSDKResultOfDecodeTvc, TSDKClientError> = .init()
587+
var response: TSDKBindingResponse<TSDKResultOfDecodeStateInit, TSDKClientError> = .init()
553588
response.update(requestId, params, responseType, finished)
554589
try handler(response)
555590
}
556591
}
557592

558-
/// Decodes tvc into code, data, libraries and special options.
593+
/// Decodes contract's initial state into code, data, libraries and special options.
559594
@available(iOS 13, *)
560595
@available(macOS 12, *)
561-
public func decode_tvc(_ payload: TSDKParamsOfDecodeTvc) async throws -> TSDKResultOfDecodeTvc {
596+
public func decode_state_init(_ payload: TSDKParamsOfDecodeStateInit) async throws -> TSDKResultOfDecodeStateInit {
562597
try await withCheckedThrowingContinuation { continuation in
563598
do {
564-
let method: String = "decode_tvc"
599+
let method: String = "decode_state_init"
565600
try binding.requestLibraryAsyncAwait(methodName(module, method), payload) { (requestId, params, responseType, finished) in
566-
var response: TSDKBindingResponse<TSDKResultOfDecodeTvc, TSDKClientError> = .init()
601+
var response: TSDKBindingResponse<TSDKResultOfDecodeStateInit, TSDKClientError> = .init()
567602
response.update(requestId, params, responseType, finished)
568603
if let error = response.error {
569604
continuation.resume(throwing: error)
@@ -579,26 +614,26 @@ public final class TSDKBocModule {
579614
}
580615
}
581616

582-
/// Encodes tvc from code, data, libraries ans special options (see input params)
583-
public func encode_tvc(_ payload: TSDKParamsOfEncodeTvc, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeTvc, TSDKClientError>) throws -> Void
617+
/// Encodes initial contract state from code, data, libraries ans special options (see input params)
618+
public func encode_state_init(_ payload: TSDKParamsOfEncodeStateInit, _ handler: @escaping (TSDKBindingResponse<TSDKResultOfEncodeStateInit, TSDKClientError>) throws -> Void
584619
) throws {
585-
let method: String = "encode_tvc"
620+
let method: String = "encode_state_init"
586621
try binding.requestLibraryAsync(methodName(module, method), payload) { (requestId, params, responseType, finished) in
587-
var response: TSDKBindingResponse<TSDKResultOfEncodeTvc, TSDKClientError> = .init()
622+
var response: TSDKBindingResponse<TSDKResultOfEncodeStateInit, TSDKClientError> = .init()
588623
response.update(requestId, params, responseType, finished)
589624
try handler(response)
590625
}
591626
}
592627

593-
/// Encodes tvc from code, data, libraries ans special options (see input params)
628+
/// Encodes initial contract state from code, data, libraries ans special options (see input params)
594629
@available(iOS 13, *)
595630
@available(macOS 12, *)
596-
public func encode_tvc(_ payload: TSDKParamsOfEncodeTvc) async throws -> TSDKResultOfEncodeTvc {
631+
public func encode_state_init(_ payload: TSDKParamsOfEncodeStateInit) async throws -> TSDKResultOfEncodeStateInit {
597632
try await withCheckedThrowingContinuation { continuation in
598633
do {
599-
let method: String = "encode_tvc"
634+
let method: String = "encode_state_init"
600635
try binding.requestLibraryAsyncAwait(methodName(module, method), payload) { (requestId, params, responseType, finished) in
601-
var response: TSDKBindingResponse<TSDKResultOfEncodeTvc, TSDKClientError> = .init()
636+
var response: TSDKBindingResponse<TSDKResultOfEncodeStateInit, TSDKClientError> = .init()
602637
response.update(requestId, params, responseType, finished)
603638
if let error = response.error {
604639
continuation.resume(throwing: error)

Sources/EverscaleClientSwift/Boc/BocTypes.swift

Lines changed: 89 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ public enum TSDKBocCacheTypeEnumTypes: String, Codable {
77
case Unpinned = "Unpinned"
88
}
99

10+
public enum TSDKBuilderOpEnumTypes: String, Codable {
11+
case Integer = "Integer"
12+
case BitString = "BitString"
13+
case Cell = "Cell"
14+
case CellBoc = "CellBoc"
15+
case Address = "Address"
16+
}
17+
18+
public enum TSDKTvcEnumTypes: String, Codable {
19+
case V1 = "V1"
20+
}
21+
1022
public enum TSDKBocErrorCode: Int, Codable {
1123
case InvalidBoc = 201
1224
case SerializationError = 202
@@ -17,14 +29,6 @@ public enum TSDKBocErrorCode: Int, Codable {
1729
case InvalidBocRef = 207
1830
}
1931

20-
public enum TSDKBuilderOpEnumTypes: String, Codable {
21-
case Integer = "Integer"
22-
case BitString = "BitString"
23-
case Cell = "Cell"
24-
case CellBoc = "CellBoc"
25-
case Address = "Address"
26-
}
27-
2832
public struct TSDKBocCacheType: Codable {
2933
public var type: TSDKBocCacheTypeEnumTypes
3034
public var pin: String?
@@ -35,6 +39,71 @@ public struct TSDKBocCacheType: Codable {
3539
}
3640
}
3741

42+
public struct TSDKBuilderOp: Codable {
43+
public var type: TSDKBuilderOpEnumTypes
44+
/// Bit size of the value.
45+
public var size: UInt32?
46+
/// Value: - `Number` containing integer number.
47+
/// e.g. `123`, `-123`. - Decimal string. e.g. `"123"`, `"-123"`.
48+
/// - `0x` prefixed hexadecimal string.
49+
/// e.g `0x123`, `0X123`, `-0x123`.
50+
public var value: AnyValue?
51+
/// Nested cell builder.
52+
public var builder: [TSDKBuilderOp]?
53+
/// Nested cell BOC encoded with `base64` or BOC cache key.
54+
public var boc: String?
55+
/// Address in a common `workchain:account` or base64 format.
56+
public var address: String?
57+
58+
public init(type: TSDKBuilderOpEnumTypes, size: UInt32? = nil, value: AnyValue? = nil, builder: [TSDKBuilderOp]? = nil, boc: String? = nil, address: String? = nil) {
59+
self.type = type
60+
self.size = size
61+
self.value = value
62+
self.builder = builder
63+
self.boc = boc
64+
self.address = address
65+
}
66+
}
67+
68+
/// Cell builder operation.
69+
public struct TSDKTvc: Codable {
70+
public var type: TSDKTvcEnumTypes
71+
public var value: TSDKTvcV1?
72+
73+
public init(type: TSDKTvcEnumTypes, value: TSDKTvcV1? = nil) {
74+
self.type = type
75+
self.value = value
76+
}
77+
}
78+
79+
public struct TSDKTvcV1: Codable {
80+
public var code: String?
81+
public var description: String?
82+
83+
public init(code: String? = nil, description: String? = nil) {
84+
self.code = code
85+
self.description = description
86+
}
87+
}
88+
89+
public struct TSDKParamsOfDecodeTvc: Codable {
90+
/// Contract TVC BOC encoded as base64 or BOC handle
91+
public var tvc: String
92+
93+
public init(tvc: String) {
94+
self.tvc = tvc
95+
}
96+
}
97+
98+
public struct TSDKResultOfDecodeTvc: Codable {
99+
/// Decoded TVC
100+
public var tvc: TSDKTvc
101+
102+
public init(tvc: TSDKTvc) {
103+
self.tvc = tvc
104+
}
105+
}
106+
38107
public struct TSDKParamsOfParse: Codable {
39108
/// BOC encoded as base64
40109
public var boc: String
@@ -192,33 +261,6 @@ public struct TSDKParamsOfBocCacheUnpin: Codable {
192261
}
193262
}
194263

195-
public struct TSDKBuilderOp: Codable {
196-
public var type: TSDKBuilderOpEnumTypes
197-
/// Bit size of the value.
198-
public var size: UInt32?
199-
/// Value: - `Number` containing integer number.
200-
/// e.g. `123`, `-123`. - Decimal string. e.g. `"123"`, `"-123"`.
201-
/// - `0x` prefixed hexadecimal string.
202-
/// e.g `0x123`, `0X123`, `-0x123`.
203-
public var value: AnyValue?
204-
/// Nested cell builder.
205-
public var builder: [TSDKBuilderOp]?
206-
/// Nested cell BOC encoded with `base64` or BOC cache key.
207-
public var boc: String?
208-
/// Address in a common `workchain:account` or base64 format.
209-
public var address: String?
210-
211-
public init(type: TSDKBuilderOpEnumTypes, size: UInt32? = nil, value: AnyValue? = nil, builder: [TSDKBuilderOp]? = nil, boc: String? = nil, address: String? = nil) {
212-
self.type = type
213-
self.size = size
214-
self.value = value
215-
self.builder = builder
216-
self.boc = boc
217-
self.address = address
218-
}
219-
}
220-
221-
/// Cell builder operation.
222264
public struct TSDKParamsOfEncodeBoc: Codable {
223265
/// Cell builder operations.
224266
public var builder: [TSDKBuilderOp]
@@ -288,19 +330,19 @@ public struct TSDKResultOfSetCodeSalt: Codable {
288330
}
289331
}
290332

291-
public struct TSDKParamsOfDecodeTvc: Codable {
292-
/// Contract TVC image BOC encoded as base64 or BOC handle
293-
public var tvc: String
333+
public struct TSDKParamsOfDecodeStateInit: Codable {
334+
/// Contract StateInit image BOC encoded as base64 or BOC handle
335+
public var state_init: String
294336
/// Cache type to put the result. The BOC itself returned if no cache type provided.
295337
public var boc_cache: TSDKBocCacheType?
296338

297-
public init(tvc: String, boc_cache: TSDKBocCacheType? = nil) {
298-
self.tvc = tvc
339+
public init(state_init: String, boc_cache: TSDKBocCacheType? = nil) {
340+
self.state_init = state_init
299341
self.boc_cache = boc_cache
300342
}
301343
}
302344

303-
public struct TSDKResultOfDecodeTvc: Codable {
345+
public struct TSDKResultOfDecodeStateInit: Codable {
304346
/// Contract code BOC encoded as base64 or BOC handle
305347
public var code: String?
306348
/// Contract code hash
@@ -341,7 +383,7 @@ public struct TSDKResultOfDecodeTvc: Codable {
341383
}
342384
}
343385

344-
public struct TSDKParamsOfEncodeTvc: Codable {
386+
public struct TSDKParamsOfEncodeStateInit: Codable {
345387
/// Contract code BOC encoded as base64 or BOC handle
346388
public var code: String?
347389
/// Contract data BOC encoded as base64 or BOC handle
@@ -370,12 +412,12 @@ public struct TSDKParamsOfEncodeTvc: Codable {
370412
}
371413
}
372414

373-
public struct TSDKResultOfEncodeTvc: Codable {
374-
/// Contract TVC image BOC encoded as base64 or BOC handle of boc_cache parameter was specified
375-
public var tvc: String
415+
public struct TSDKResultOfEncodeStateInit: Codable {
416+
/// Contract StateInit image BOC encoded as base64 or BOC handle of boc_cache parameter was specified
417+
public var state_init: String
376418

377-
public init(tvc: String) {
378-
self.tvc = tvc
419+
public init(state_init: String) {
420+
self.state_init = state_init
379421
}
380422
}
381423

Sources/EverscaleClientSwift/Client/ClientTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public struct TSDKClientError: Codable, LocalizedError {
6060
public var failureReason: String? { self.message }
6161
public var recoverySuggestion: String? { self.message }
6262
public var helpAnchor: String? { self.message }
63-
public var data: AnyValue = ([:] as! [String: Any]).toAnyValue()
63+
public var data: AnyValue = [String: Any]().toAnyValue()
6464

6565
public init(_ error: Error) {
6666
self.code = 0

Sources/EverscaleClientSwift/Tvm/TvmTypes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum TSDKTvmErrorCode: Int, Codable {
1717
case InvalidAccountBoc = 412
1818
case InvalidMessageType = 413
1919
case ContractExecutionError = 414
20+
case AccountIsSuspended = 415
2021
}
2122

2223
public enum TSDKAccountForExecutorEnumTypes: String, Codable {

0 commit comments

Comments
 (0)