ton_sdk_client 1.9.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
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)
57
19
 
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
104
-
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,29 +59,10 @@ 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
67
 
203
68
 
@@ -206,7 +71,7 @@ module TonSdk
206
71
  #
207
72
 
208
73
  def self.parse_message(ctx, params)
209
- 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|
210
75
  if resp.success?
211
76
  yield NativeLibResponsetResult.new(
212
77
  result: ResultOfParse.new(resp.result["parsed"])
@@ -218,7 +83,7 @@ module TonSdk
218
83
  end
219
84
 
220
85
  def self.parse_transaction(ctx, params)
221
- 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|
222
87
  if resp.success?
223
88
  yield NativeLibResponsetResult.new(
224
89
  result: ResultOfParse.new(resp.result["parsed"])
@@ -230,7 +95,7 @@ module TonSdk
230
95
  end
231
96
 
232
97
  def self.parse_account(ctx, params)
233
- 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|
234
99
  if resp.success?
235
100
  yield NativeLibResponsetResult.new(
236
101
  result: ResultOfParse.new(resp.result["parsed"])
@@ -242,7 +107,7 @@ module TonSdk
242
107
  end
243
108
 
244
109
  def self.parse_block(ctx, params)
245
- 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|
246
111
  if resp.success?
247
112
  yield NativeLibResponsetResult.new(
248
113
  result: ResultOfParse.new(resp.result["parsed"])
@@ -254,7 +119,7 @@ module TonSdk
254
119
  end
255
120
 
256
121
  def self.parse_shardstate(ctx, params)
257
- 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|
258
123
  if resp.success?
259
124
  yield NativeLibResponsetResult.new(
260
125
  result: ResultOfParse.new(resp.result["parsed"])
@@ -266,7 +131,7 @@ module TonSdk
266
131
  end
267
132
 
268
133
  def self.get_blockchain_config(ctx, params)
269
- 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|
270
135
  if resp.success?
271
136
  yield NativeLibResponsetResult.new(
272
137
  result: ResultOfGetBlockchainConfig.new(resp.result["config_boc"])
@@ -278,7 +143,7 @@ module TonSdk
278
143
  end
279
144
 
280
145
  def self.get_boc_hash(ctx, params)
281
- 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|
282
147
  if resp.success?
283
148
  yield NativeLibResponsetResult.new(
284
149
  result: ResultOfGetBocHash.new(resp.result["hash"])
@@ -290,7 +155,7 @@ module TonSdk
290
155
  end
291
156
 
292
157
  def self.get_code_from_tvc(ctx, params)
293
- 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|
294
159
  if resp.success?
295
160
  yield NativeLibResponsetResult.new(
296
161
  result: ResultOfGetCodeFromTvc.new(resp.result["code"])
@@ -302,7 +167,7 @@ module TonSdk
302
167
  end
303
168
 
304
169
  def self.cache_get(ctx, params)
305
- 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|
306
171
  if resp.success?
307
172
  yield NativeLibResponsetResult.new(
308
173
  result: ResultOfBocCacheGet.new(
@@ -316,7 +181,7 @@ module TonSdk
316
181
  end
317
182
 
318
183
  def self.cache_set(ctx, params)
319
- 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|
320
185
  if resp.success?
321
186
  yield NativeLibResponsetResult.new(
322
187
  result: ResultOfBocCacheSet.new(
@@ -330,7 +195,7 @@ module TonSdk
330
195
  end
331
196
 
332
197
  def self.cache_unpin(ctx, params)
333
- 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|
334
199
  if resp.success?
335
200
  yield NativeLibResponsetResult.new(
336
201
  result: nil
@@ -340,5 +205,33 @@ module TonSdk
340
205
  end
341
206
  end
342
207
  end
208
+
209
+ def self.encode_boc(ctx, params)
210
+ Interop::request_to_native_lib(ctx, "boc.encode_boc", params) do |resp|
211
+ if resp.success?
212
+ yield NativeLibResponsetResult.new(
213
+ result: ResultOfEncodeBoc.new(
214
+ resp.result["boc"]
215
+ )
216
+ )
217
+ else
218
+ yield resp
219
+ end
220
+ end
221
+ end
222
+
223
+ def self.get_blockchain_config(ctx, params)
224
+ Interop::request_to_native_lib(ctx, "boc.get_blockchain_config", params) do |resp|
225
+ if resp.success?
226
+ yield NativeLibResponsetResult.new(
227
+ result: ResultOfGetBlockchainConfig.new(
228
+ resp.result["config_boc"]
229
+ )
230
+ )
231
+ else
232
+ yield resp
233
+ end
234
+ end
235
+ end
343
236
  end
344
237
  end
@@ -44,57 +44,22 @@ module TonSdk
44
44
  INTERNAL_ERROR = 33
45
45
  end
46
46
 
47
- class ResultOfVersion
48
- attr_reader :version
49
-
50
- def initialize(a)
51
- @version = a
52
- end
53
- end
54
-
55
- class ResultOfGetApiReference
56
- attr_reader :api
57
-
58
- def initialize(a)
59
- @api = a
60
- end
61
- end
62
-
63
- class BuildInfoDependency
64
- attr_reader :name, :git_commit
65
-
66
- def initialize(name:, git_commit:)
67
- @name = name
68
- @git_commit = git_commit
69
- end
47
+ ResultOfVersion = Struct.new(:version)
48
+ ResultOfGetApiReference = Struct.new(:api)
70
49
 
50
+ BuildInfoDependency = Struct.new(:name, :git_commit, keyword_init: true) do
71
51
  def self.from_json(j)
72
52
  return nil if j.nil?
73
53
 
74
54
  self.new(
75
- name: j["name"],
76
- git_commit: j["git_commit"]
55
+ j["name"],
56
+ j["git_commit"]
77
57
  )
78
58
  end
79
59
  end
80
60
 
81
- class ResultOfBuildInfo
82
- attr_reader :build_number, :dependencies
83
-
84
- def initialize(build_number:, dependencies:)
85
- @build_number = build_number
86
- @dependencies = dependencies
87
- end
88
- end
89
-
90
- class ParamsOfAppRequest
91
- attr_reader :app_request_id, :request_data
92
-
93
- def initialize(app_request_id:, request_data:)
94
- @app_request_id = app_request_id
95
- @request_data = request_data
96
- end
97
- end
61
+ ResultOfBuildInfo = Struct.new(:build_number, :dependencies, keyword_init: true)
62
+ ParamsOfAppRequest = Struct.new(:app_request_id, :request_data, keyword_init: true)
98
63
 
99
64
  class AppRequestResult
100
65
  TYPES = [:ok, :error]
@@ -128,14 +93,7 @@ module TonSdk
128
93
  end
129
94
  end
130
95
 
131
- class ParamsOfResolveAppRequest
132
- attr_reader :app_request_id, :result
133
-
134
- def initialize(app_request_id:, result:)
135
- @app_request_id = app_request_id
136
- @result = result
137
- end
138
-
96
+ ParamsOfResolveAppRequest = Struct.new(:app_request_id, :result, keyword_init: true) do
139
97
  def to_h
140
98
  {
141
99
  app_request_id: @app_request_id,
@@ -194,7 +152,7 @@ module TonSdk
194
152
  end
195
153
 
196
154
  def self.resolve_app_request(ctx, params)
197
- 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|
198
156
  if resp.success?
199
157
  yield NativeLibResponsetResult.new(
200
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