ton_sdk_client 1.12.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,140 +5,31 @@ module TonSdk
5
5
  # types
6
6
  #
7
7
 
8
- class ParamsOfParse
9
- attr_reader :boc
8
+ ParamsOfParse = Struct.new(:boc)
9
+ ResultOfParse = Struct.new(:parsed)
10
+ ParamsOfParseShardstate = Struct.new(:boc, :id_, :workchain_id, keyword_init: true)
11
+ ParamsOfGetBlockchainConfig = Struct.new(:block_boc)
12
+ ResultOfGetBlockchainConfig = Struct.new(:config_boc)
10
13
 
11
- def initialize(a)
12
- @boc = a
13
- end
14
-
15
- def to_h = { boc: @boc }
16
- end
17
-
18
- class ResultOfParse
19
- attr_reader :parsed
20
-
21
- def initialize(a)
22
- @parsed = a
23
- end
24
- end
25
-
26
- class ParamsOfParseShardstate
27
- attr_reader :boc, :id, :workchain_id
28
-
29
- def initialize(boc:, id_:, workchain_id:)
30
- @boc = boc
31
- @id_ = id_
32
- @workchain_id = workchain_id
33
- end
34
-
35
- def to_h
36
- {
37
- boc: @boc,
38
- id: @id_,
39
- workchain_id: @workchain_id
40
- }
41
- end
42
- end
43
-
44
- class ParamsOfGetBlockchainConfig
45
- attr_reader :block_boc
46
-
47
- def initialize(a)
48
- @block_boc = a
49
- end
50
-
51
- def to_h
52
- {
53
- block_boc: @block_boc
54
- }
55
- end
56
- end
57
-
58
- class ResultOfGetBlockchainConfig
59
- attr_reader :config_boc
60
-
61
- def initialize(a)
62
- @config_boc = a
63
- end
64
- end
65
-
66
- class ParamsOfGetBocHash
67
- attr_reader :boc
68
-
69
- def initialize(a)
70
- @boc = a
71
- end
72
-
73
- def to_h
74
- {
75
- boc: @boc
76
- }
77
- end
78
- end
79
-
80
- class ResultOfGetBocHash
81
- attr_reader :hash
82
-
83
- def initialize(a)
84
- @hash = a
85
- end
86
- end
87
-
88
- class ParamsOfGetCodeFromTvc
89
- attr_reader :tvc
90
-
91
- def initialize(a)
92
- @tvc = a
93
- end
94
-
95
- def to_h
96
- {
97
- tvc: @tvc
98
- }
99
- end
100
- end
101
-
102
- class ResultOfGetCodeFromTvc
103
- attr_reader :code
14
+ ParamsOfGetBocHash = Struct.new(:boc)
15
+ ResultOfGetBocHash = Struct.new(:hash)
16
+ ParamsOfGetCodeFromTvc = Struct.new(:hash)
17
+ ResultOfGetCodeFromTvc = Struct.new(:code)
18
+ ParamsOfBocCacheGet = Struct.new(:boc_ref)
104
19
 
105
- def initialize(a)
106
- @code = a
107
- end
108
- end
109
-
110
- class ParamsOfBocCacheGet
111
- attr_reader :boc_ref
112
-
113
- def initialize(a)
114
- @boc_ref = a
115
- end
116
-
117
- def to_h = { boc_ref: @boc_ref }
118
- end
119
-
120
- class ResultOfBocCacheGet
121
- attr_reader :boc
122
-
123
- def initialize(boc: nil)
124
- @boc = boc
125
- end
126
- end
20
+ ResultOfBocCacheGet = Struct.new(:boc)
127
21
 
128
22
  class BocCacheType
129
- TYPES = [
130
- :pinned,
131
- :unpinned
132
- ]
23
+ private_class_method :new
133
24
 
134
25
  attr_reader :type_, :pin
135
26
 
136
- def new_with_type_pinned(pin)
27
+ def self.new_with_type_pinned(pin)
137
28
  @type_ = :pinned
138
29
  @pin = pin
139
30
  end
140
31
 
141
- def new_with_type_unpinned
32
+ def self.new_with_type_unpinned
142
33
  @type_ = :unpinned
143
34
  end
144
35
 
@@ -159,14 +50,7 @@ module TonSdk
159
50
  end
160
51
  end
161
52
 
162
- class ParamsOfBocCacheSet
163
- attr_reader :boc, :cache_type
164
-
165
- def initialize(boc:, cache_type:)
166
- @boc = boc
167
- @cache_type = cache_type
168
- end
169
-
53
+ ParamsOfBocCacheSet = Struct.new(:boc, :cache_type) do
170
54
  def to_h
171
55
  {
172
56
  boc: @boc,
@@ -175,75 +59,11 @@ module TonSdk
175
59
  end
176
60
  end
177
61
 
178
- class ResultOfBocCacheGet
179
- attr_reader :boc_ref
180
-
181
- def initialize(a)
182
- @boc_ref = a
183
- end
184
- end
185
-
186
- class ParamsOfBocCacheUnpin
187
- attr_reader :boc, :boc_ref
188
-
189
- def initialize(boc:, boc_ref: nil)
190
- @boc = boc
191
- @boc_ref = boc_ref
192
- end
193
-
194
- def to_h
195
- {
196
- boc: @boc,
197
- boc_ref: @boc_ref
198
- }
199
- end
200
- end
62
+ ResultOfBocCacheSet = Struct.new(:boc_ref)
63
+ ParamsOfBocCacheUnpin = Struct.new(:boc, :boc_ref)
64
+ ParamsOfEncodeBoc = Struct.new(:builder, :boc_cache)
65
+ ResultOfEncodeBoc = Struct.new(:boc)
201
66
 
202
- class ParamsOfEncodeBoc
203
- attr_reader :builder, :boc_cache
204
-
205
- def initialize(builder:, boc_cache: nil)
206
- @builder = builder
207
- @boc_cache = boc_cache
208
- end
209
-
210
- def to_h
211
- {
212
- boc: @boc,
213
- boc_ref: @boc_ref
214
- }
215
- end
216
- end
217
-
218
- class ResultOfEncodeBoc
219
- attr_reader :boc
220
-
221
- def initialize(a)
222
- @boc = a
223
- end
224
- end
225
-
226
- class ParamsOfGetBlockchainConfig
227
- attr_reader :block_boc
228
-
229
- def initialize(a)
230
- @block_boc = a
231
- end
232
-
233
- def to_h
234
- {
235
- block_boc: @block_boc
236
- }
237
- end
238
- end
239
-
240
- class ResultOfGetBlockchainConfig
241
- attr_reader :config_boc
242
-
243
- def initialize(a)
244
- @config_boc = a
245
- end
246
- end
247
67
 
248
68
 
249
69
  #
@@ -251,7 +71,7 @@ module TonSdk
251
71
  #
252
72
 
253
73
  def self.parse_message(ctx, params)
254
- Interop::request_to_native_lib(ctx, "boc.parse_message", params.to_h.to_json) do |resp|
74
+ Interop::request_to_native_lib(ctx, "boc.parse_message", params) do |resp|
255
75
  if resp.success?
256
76
  yield NativeLibResponsetResult.new(
257
77
  result: ResultOfParse.new(resp.result["parsed"])
@@ -263,7 +83,7 @@ module TonSdk
263
83
  end
264
84
 
265
85
  def self.parse_transaction(ctx, params)
266
- Interop::request_to_native_lib(ctx, "boc.parse_transaction", params.to_h.to_json) do |resp|
86
+ Interop::request_to_native_lib(ctx, "boc.parse_transaction", params) do |resp|
267
87
  if resp.success?
268
88
  yield NativeLibResponsetResult.new(
269
89
  result: ResultOfParse.new(resp.result["parsed"])
@@ -275,7 +95,7 @@ module TonSdk
275
95
  end
276
96
 
277
97
  def self.parse_account(ctx, params)
278
- Interop::request_to_native_lib(ctx, "boc.parse_account", params.to_h.to_json) do |resp|
98
+ Interop::request_to_native_lib(ctx, "boc.parse_account", params) do |resp|
279
99
  if resp.success?
280
100
  yield NativeLibResponsetResult.new(
281
101
  result: ResultOfParse.new(resp.result["parsed"])
@@ -287,7 +107,7 @@ module TonSdk
287
107
  end
288
108
 
289
109
  def self.parse_block(ctx, params)
290
- Interop::request_to_native_lib(ctx, "boc.parse_block", params.to_h.to_json) do |resp|
110
+ Interop::request_to_native_lib(ctx, "boc.parse_block", params) do |resp|
291
111
  if resp.success?
292
112
  yield NativeLibResponsetResult.new(
293
113
  result: ResultOfParse.new(resp.result["parsed"])
@@ -299,7 +119,7 @@ module TonSdk
299
119
  end
300
120
 
301
121
  def self.parse_shardstate(ctx, params)
302
- Interop::request_to_native_lib(ctx, "boc.parse_shardstate", params.to_h.to_json) do |resp|
122
+ Interop::request_to_native_lib(ctx, "boc.parse_shardstate", params) do |resp|
303
123
  if resp.success?
304
124
  yield NativeLibResponsetResult.new(
305
125
  result: ResultOfParse.new(resp.result["parsed"])
@@ -311,7 +131,7 @@ module TonSdk
311
131
  end
312
132
 
313
133
  def self.get_blockchain_config(ctx, params)
314
- Interop::request_to_native_lib(ctx, "boc.get_blockchain_config", params.to_h.to_json) do |resp|
134
+ Interop::request_to_native_lib(ctx, "boc.get_blockchain_config", params) do |resp|
315
135
  if resp.success?
316
136
  yield NativeLibResponsetResult.new(
317
137
  result: ResultOfGetBlockchainConfig.new(resp.result["config_boc"])
@@ -323,7 +143,7 @@ module TonSdk
323
143
  end
324
144
 
325
145
  def self.get_boc_hash(ctx, params)
326
- Interop::request_to_native_lib(ctx, "boc.get_boc_hash", params.to_h.to_json) do |resp|
146
+ Interop::request_to_native_lib(ctx, "boc.get_boc_hash", params) do |resp|
327
147
  if resp.success?
328
148
  yield NativeLibResponsetResult.new(
329
149
  result: ResultOfGetBocHash.new(resp.result["hash"])
@@ -335,7 +155,7 @@ module TonSdk
335
155
  end
336
156
 
337
157
  def self.get_code_from_tvc(ctx, params)
338
- Interop::request_to_native_lib(ctx, "boc.get_code_from_tvc", params.to_h.to_json) do |resp|
158
+ Interop::request_to_native_lib(ctx, "boc.get_code_from_tvc", params) do |resp|
339
159
  if resp.success?
340
160
  yield NativeLibResponsetResult.new(
341
161
  result: ResultOfGetCodeFromTvc.new(resp.result["code"])
@@ -347,7 +167,7 @@ module TonSdk
347
167
  end
348
168
 
349
169
  def self.cache_get(ctx, params)
350
- Interop::request_to_native_lib(ctx, "boc.cache_get", params.to_h.to_json) do |resp|
170
+ Interop::request_to_native_lib(ctx, "boc.cache_get", params) do |resp|
351
171
  if resp.success?
352
172
  yield NativeLibResponsetResult.new(
353
173
  result: ResultOfBocCacheGet.new(
@@ -361,7 +181,7 @@ module TonSdk
361
181
  end
362
182
 
363
183
  def self.cache_set(ctx, params)
364
- Interop::request_to_native_lib(ctx, "boc.cache_set", params.to_h.to_json) do |resp|
184
+ Interop::request_to_native_lib(ctx, "boc.cache_set", params) do |resp|
365
185
  if resp.success?
366
186
  yield NativeLibResponsetResult.new(
367
187
  result: ResultOfBocCacheSet.new(
@@ -375,7 +195,7 @@ module TonSdk
375
195
  end
376
196
 
377
197
  def self.cache_unpin(ctx, params)
378
- Interop::request_to_native_lib(ctx, "boc.cache_unpin", params.to_h.to_json) do |resp|
198
+ Interop::request_to_native_lib(ctx, "boc.cache_unpin", params) do |resp|
379
199
  if resp.success?
380
200
  yield NativeLibResponsetResult.new(
381
201
  result: nil
@@ -387,7 +207,7 @@ module TonSdk
387
207
  end
388
208
 
389
209
  def self.encode_boc(ctx, params)
390
- Interop::request_to_native_lib(ctx, "boc.encode_boc", params.to_h.to_json) do |resp|
210
+ Interop::request_to_native_lib(ctx, "boc.encode_boc", params) do |resp|
391
211
  if resp.success?
392
212
  yield NativeLibResponsetResult.new(
393
213
  result: ResultOfEncodeBoc.new(
@@ -401,7 +221,7 @@ module TonSdk
401
221
  end
402
222
 
403
223
  def self.get_blockchain_config(ctx, params)
404
- Interop::request_to_native_lib(ctx, "boc.get_blockchain_config", params.to_h.to_json) do |resp|
224
+ Interop::request_to_native_lib(ctx, "boc.get_blockchain_config", params) do |resp|
405
225
  if resp.success?
406
226
  yield NativeLibResponsetResult.new(
407
227
  result: ResultOfGetBlockchainConfig.new(
@@ -45,7 +45,6 @@ module TonSdk
45
45
  end
46
46
 
47
47
  ResultOfVersion = Struct.new(:version)
48
-
49
48
  ResultOfGetApiReference = Struct.new(:api)
50
49
 
51
50
  BuildInfoDependency = Struct.new(:name, :git_commit, keyword_init: true) do
@@ -153,7 +152,7 @@ module TonSdk
153
152
  end
154
153
 
155
154
  def self.resolve_app_request(ctx, params)
156
- Interop::request_to_native_lib(ctx, "client.resolve_app_request", params.to_h.to_json) do |resp|
155
+ Interop::request_to_native_lib(ctx, "client.resolve_app_request", params) do |resp|
157
156
  if resp.success?
158
157
  yield NativeLibResponsetResult.new(
159
158
  result: ""
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+
2
3
  require_relative './interop.rb'
3
4
  require_relative './types.rb'
4
5
  require_relative './helper.rb'
@@ -14,6 +15,7 @@ require_relative './tvm.rb'
14
15
  require_relative './processing.rb'
15
16
  require_relative './debot.rb'
16
17
 
18
+
17
19
  module TonSdk
18
20
  class ClientContext
19
21
  attr_reader :context
@@ -1,108 +1,67 @@
1
1
  module TonSdk
2
- class ClientConfig
3
- attr_reader :network, :crypto, :abi
4
-
5
- def initialize(network: nil, crypto: nil, abi: nil)
6
- if network.nil? && crypto.nil? && abi.nil?
7
- raise ArgumentError.new("all 3 arguments may not be nil")
8
- end
9
-
10
- @network = network
11
- @crypto = crypto
12
- @abi = abi
13
- end
14
-
15
- def to_h
16
- {
17
- network: @network.nil? ? nil : @network.to_h,
18
- crypto: @crypto.nil? ? nil : @crypto.to_h,
19
- abi: @abi.nil? ? nil : @abi.to_h
20
- }
21
- end
22
- end
23
-
24
- class NetworkConfig
25
- DEFAULT_RETRIES_COUNT = 5
26
- DEFAULT_PROCESSING_TIMEOUT = 40000
27
- DEFAULT_WAIT_TIMEOUT = 40000
28
- DEFAULT_OUT_OF_SYNC_THRESHOLD = 15000
29
- DEFAULT_NETWORK_RETRIES_COUNT = 5
30
- DEFAULT_MAX_RECONNECT_TIMEOUT = 2
31
-
32
- attr_reader :server_address, :endpoints, :network_retries_count,
33
- :message_retries_count, :message_processing_timeout,
34
- :wait_for_timeout, :out_of_sync_threshold, :reconnect_timeout,
35
- :access_key, :max_reconnect_timeout
36
-
2
+ CryptoConfig = Struct.new(:mnemonic_dictionary, :mnemonic_word_count, :hdkey_derivation_path, keyword_init: true)
3
+ BocConfig = Struct.new(:cache_max_size)
4
+ NetworkConfig = Struct.new(
5
+ :server_address,
6
+ :endpoints,
7
+ :network_retries_count,
8
+ :message_retries_count,
9
+ :message_processing_timeout,
10
+ :wait_for_timeout,
11
+ :out_of_sync_threshold,
12
+ :reconnect_timeout,
13
+ :max_reconnect_timeout,
14
+ :sending_endpoint_count,
15
+ :latency_detection_interval,
16
+ :max_latency,
17
+ :access_key,
18
+ keyword_init: true
19
+ ) do
37
20
  def initialize(
38
21
  server_address: "",
39
22
  endpoints: [],
40
- network_retries_count: DEFAULT_NETWORK_RETRIES_COUNT,
41
- message_retries_count: DEFAULT_RETRIES_COUNT,
42
- message_processing_timeout: DEFAULT_PROCESSING_TIMEOUT,
43
- wait_for_timeout: DEFAULT_WAIT_TIMEOUT,
44
- out_of_sync_threshold: DEFAULT_OUT_OF_SYNC_THRESHOLD,
45
- reconnect_timeout: 0,
46
- access_key: nil,
47
- max_reconnect_timeout: DEFAULT_MAX_RECONNECT_TIMEOUT
23
+ network_retries_count: 5,
24
+ max_reconnect_timeout: 120000,
25
+ reconnect_timeout: 1000,
26
+ message_retries_count: 5,
27
+ message_processing_timeout: 40000,
28
+ wait_for_timeout: 40000,
29
+ out_of_sync_threshold: 15000,
30
+ sending_endpoint_count: 2,
31
+ latency_detection_interval: 60000,
32
+ max_latency: 60000,
33
+ access_key: nil
48
34
  )
49
- @server_address = server_address
50
- @endpoints = endpoints
51
- @network_retries_count = network_retries_count
52
- @message_retries_count = message_retries_count
53
- @message_processing_timeout = message_processing_timeout
54
- @wait_for_timeout = wait_for_timeout
55
- @out_of_sync_threshold = out_of_sync_threshold
56
- @reconnect_timeout = reconnect_timeout
57
- @access_key = access_key
58
- @max_reconnect_timeout = max_reconnect_timeout
59
- end
60
-
61
- def to_h
62
- {
63
- server_address: @server_address,
64
- endpoints: @endpoints,
65
- network_retries_count: @network_retries_count,
66
- message_retries_count: @message_retries_count,
67
- message_processing_timeout: @message_processing_timeout,
68
- wait_for_timeout: @wait_for_timeout,
69
- out_of_sync_threshold: @out_of_sync_threshold,
70
- reconnect_timeout: @reconnect_timeout,
71
- access_key: @access_key,
72
- max_reconnect_timeout: @max_reconnect_timeout
73
- }
35
+ super
74
36
  end
75
37
  end
76
38
 
77
- class CryptoConfig
78
- attr_reader :fish_param
79
-
80
- def initialize(a)
81
- @fish_param = a
82
- end
83
-
84
- def to_h = { fish_param: @fish_param }
85
- end
86
-
87
- class AbiConfig
88
- DEFAULT_EXPIRATION_TIMEOUT = 40000
89
- DEFAULT_TIMEOUT_GROW_FACTOR = 1.5
90
-
91
- attr_reader :message_expiration_timeout, :message_expiration_timeout_grow_factor
92
-
39
+ AbiConfig = Struct.new(
40
+ :workchain,
41
+ :message_expiration_timeout,
42
+ :message_expiration_timeout_grow_factor,
43
+ keyword_init: true
44
+ ) do
93
45
  def initialize(
94
- message_expiration_timeout: DEFAULT_EXPIRATION_TIMEOUT,
95
- message_expiration_timeout_grow_factor: DEFAULT_TIMEOUT_GROW_FACTOR
46
+ workchain: nil,
47
+ message_expiration_timeout: 40000,
48
+ message_expiration_timeout_grow_factor: 1.5
96
49
  )
97
- @message_expiration_timeout = message_expiration_timeout
98
- @message_expiration_timeout_grow_factor = message_expiration_timeout_grow_factor
50
+ super
99
51
  end
52
+ end
100
53
 
54
+ ClientConfig = Struct.new(:network, :crypto, :abi, :boc, keyword_init: true) do
101
55
  def to_h
56
+ res = super.to_h
57
+
102
58
  {
103
- message_expiration_timeout: @message_expiration_timeout,
104
- message_expiration_timeout_grow_factor: @message_expiration_timeout_grow_factor
59
+ network: res[:network]&.to_h,
60
+ crypto: res[:crypto]&.to_h,
61
+ abi: res[:abi]&.to_h,
62
+ boc: res[:boc]&.to_h
105
63
  }
106
64
  end
107
65
  end
66
+
108
67
  end