ton_sdk_client 1.24.0 → 1.28.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,4 @@
1
1
  module TonSdk
2
-
3
- # NOTE
4
- # as of 28 apr 2021, in the main repository this module is still unstable
5
2
  module Debot
6
3
 
7
4
  #
@@ -21,22 +18,23 @@ module TonSdk
21
18
  EXTERNAL_CALL_FAILED = 810
22
19
  BROWSER_CALLBACK_FAILED = 811
23
20
  OPERATION_REJECTED = 812
21
+ DEBOT_NO_CODE = 813
24
22
  end
25
23
 
26
24
  DebotAction = KwStruct.new(:description, :name, :action_type, :to, :attributes, :misc) do
27
25
  def to_h
28
26
  {
29
- description: self.description,
30
- name: self.name,
31
- action_type: self.action_type,
32
- to: self.to,
33
- attributes: self.attributes,
34
- misc: self.misc
27
+ description: description,
28
+ name: name,
29
+ action_type: action_type,
30
+ to: to,
31
+ attributes: attributes,
32
+ misc: misc
35
33
  }
36
34
  end
37
35
 
38
36
  def self.from_json(j)
39
- return nil if j.nil?
37
+ return if j.nil?
40
38
 
41
39
  self.new(
42
40
  description: j["description"],
@@ -49,20 +47,59 @@ module TonSdk
49
47
  end
50
48
  end
51
49
 
52
- ParamsOfStart = KwStruct.new(:debot_handle)
50
+ DebotInfo = KwStruct.new(
51
+ :name,
52
+ :version,
53
+ :publisher,
54
+ :caption,
55
+ :author,
56
+ :support,
57
+ :hello,
58
+ :language,
59
+ :dabi,
60
+ :icon,
61
+ :interfaces,
62
+ :dabi_version
63
+ ) do
64
+ def initialize(
65
+ name: nil,
66
+ version: nil,
67
+ publisher: nil,
68
+ caption: nil,
69
+ author: nil,
70
+ support: nil,
71
+ hello: nil,
72
+ language: nil,
73
+ dabi: nil,
74
+ icon: nil,
75
+ interfaces: [],
76
+ dabi_version: nil
77
+ )
78
+ super
79
+ end
80
+ end
81
+
82
+ class DebotActivity
83
+ attr_reader :type, :msg, :dst, :out, :fee, :setcode, :signkey, :signing_box_handle
84
+ end
85
+
86
+ Spending = KwStruct.new(:amount, :dst)
87
+
88
+ ParamsOfInit = KwStruct.new(:address)
53
89
 
54
90
  RegisteredDebot = KwStruct.new(:debot_handle, :debot_abi, :info) do
55
- def to_h = {
56
- debot_handle: @debot_handle,
57
- debot_abi: @debot_abi,
58
- info: @info.to_h
59
- }
91
+ def to_h
92
+ {
93
+ debot_handle: debot_handle,
94
+ debot_abi: debot_abi,
95
+ info: info.to_h
96
+ }
97
+ end
60
98
  end
61
99
 
62
100
  class ParamsOfAppDebotBrowser
63
101
  private_class_method :new
64
102
 
65
- # todo remove?
66
103
  TYPE_VALUES = [
67
104
  :log,
68
105
  :switch,
@@ -75,61 +112,61 @@ module TonSdk
75
112
  :approve
76
113
  ]
77
114
 
78
- attr_reader :type_, :msg, :context_id, :action, :prompt, :debot_addr, :message, :activity
115
+ attr_reader :type, :msg, :context_id, :action, :prompt, :debot_addr, :message, :activity
79
116
 
80
117
  def self.new_with_type_log(msg)
81
- @type_ = :log
118
+ @type = :log
82
119
  @msg = msg
83
120
  end
84
121
 
85
122
  def self.new_with_type_switch(context_id)
86
- @type_ = :switch
123
+ @type = :switch
87
124
  @context_id = context_id
88
125
  end
89
126
 
90
127
  def self.new_with_type_switch_completed
91
- @type_ = :switch_completed
128
+ @type = :switch_completed
92
129
  end
93
130
 
94
131
  def self.new_with_type_show_action(action)
95
- @type_ = :show_action
132
+ @type = :show_action
96
133
  @action = action
97
134
  end
98
135
 
99
136
  def self.new_with_type_input(prompt)
100
- @type_ = :input
137
+ @type = :input
101
138
  @prompt = prompt
102
139
  end
103
140
 
104
141
  def self.new_with_type_get_signing_box
105
- @type_ = :get_signing_box
142
+ @type = :get_signing_box
106
143
  end
107
144
 
108
145
  def self.new_with_type_invoke_debot(debot_addr, action)
109
- @type_ = :invoke_debot
146
+ @type = :invoke_debot
110
147
  @debot_addr = debot_addr
111
148
  @action = action
112
149
  end
113
150
 
114
151
  def self.new_with_type_send(message)
115
- @type_ = :send
152
+ @type = :send
116
153
  @message = message
117
154
  end
118
155
 
119
156
  def self.new_with_type_approve(activity)
120
- @type_ = :approve
157
+ @type = :approve
121
158
  @activity = activity
122
159
  end
123
160
 
124
161
  def to_h
125
162
  {
126
- type: Helper.sym_to_capitalized_case_str(@type_),
127
- msg: @msg,
128
- context_id: @context_id,
129
- action: @action,
130
- prompt: @prompt,
131
- debot_addr: @debot_addr,
132
- message: @message
163
+ type: Helper.sym_to_capitalized_case_str(type),
164
+ msg: msg,
165
+ context_id: context_id,
166
+ action: action,
167
+ prompt: prompt,
168
+ debot_addr: debot_addr,
169
+ message: message
133
170
  }
134
171
  end
135
172
 
@@ -173,118 +210,79 @@ module TonSdk
173
210
  private
174
211
 
175
212
  def self.parse_type(type_str)
176
- types_str = TYPE_VALUES.map(Helper.capitalized_case_str_to_snake_case_sym)
177
- unless types_str.include?(type_str)
178
- raise ArgumentError.new("type #{type_str} is unknown; known types: #{types_str}")
213
+ parsed_type = Helper.capitalized_case_str_to_snake_case_sym(type_str)
214
+
215
+ unless TYPE_VALUES.include?(type_str)
216
+ raise ArgumentError.new("type #{type_str} is unknown; known types: #{TYPE_VALUES}")
179
217
  end
180
218
 
181
- Helper.capitalized_case_str_to_snake_case_sym(type_str)
219
+ parsed_type
182
220
  end
183
221
  end
184
222
 
185
223
  class ResultOfAppDebotBrowser
186
224
  private_class_method :new
187
225
 
188
- attr_reader :type_, :value, :signing_box, :is_approved
226
+ attr_reader :type, :value, :signing_box, :is_approved
189
227
 
190
228
  def self.new_with_type_input(a)
191
- @type_ = :input
229
+ @type = :input
192
230
  @value = a
193
231
  end
194
232
 
195
233
  def self.new_with_type_get_signing_box(a)
196
- @type_ = :get_signing_box
234
+ @type = :get_signing_box
197
235
  @signing_box = signing_box
198
236
  end
199
237
 
200
238
  def self.new_with_type_invoke_debot
201
- @type_ = :invoke_debot
239
+ @type = :invoke_debot
202
240
  end
203
241
 
204
242
  def self.new_with_type_approve(a)
205
- @type_ = :approve
243
+ @type = :approve
206
244
  @is_approved = a
207
245
  end
208
246
  end
209
247
 
248
+ ParamsOfStart = KwStruct.new(:debot_handle)
249
+
210
250
  ParamsOfFetch = KwStruct.new(:address)
211
251
 
252
+ ResultOfFetch = KwStruct.new(:info)
253
+
212
254
  ParamsOfExecute = KwStruct.new(:debot_handle, :action) do
213
255
  def to_h
214
256
  {
215
- debot_handle: @debot_handle,
216
- action: @action.to_h
257
+ debot_handle: debot_handle,
258
+ action: action.to_h
217
259
  }
218
260
  end
219
261
  end
220
262
 
221
263
  ParamsOfSend = KwStruct.new(:debot_handle, :message)
222
- ParamsOfInit = KwStruct.new(:address)
223
- DebotInfo = KwStruct.new(
224
- :name,
225
- :version,
226
- :publisher,
227
- :caption,
228
- :author,
229
- :support,
230
- :hello,
231
- :language,
232
- :dabi,
233
- :icon,
234
- :interfaces
235
- ) do
236
- def initialize(
237
- name: nil,
238
- version: nil,
239
- publisher: nil,
240
- caption: nil,
241
- author: nil,
242
- support: nil,
243
- hello: nil,
244
- language: nil,
245
- dabi: nil,
246
- icon: nil,
247
- interfaces: []
248
- )
249
- super
250
- end
251
- end
252
-
253
- ResultOfFetch = KwStruct.new(:info)
254
- Spending = KwStruct.new(:amount, :dst)
255
-
256
- class DebotActivity
257
- private_class_method :new
258
-
259
- attr_reader :type_, :msg, :dst, :out, :fee, :setcode, :signkey, :signing_box_handle
260
-
261
- def self.new_with_type_transaction(msg:, dst:, out:, fee:, setcode:, signkey:, signing_box_handle:)
262
- @type_ = :transaction
263
- @msg = msg
264
- @dst = dst
265
- @out = out
266
- @fee = fee
267
- @setcode = setcode
268
- @signkey = signkey
269
- @signing_box_handle = signing_box_handle
270
- end
271
-
272
- def self.from_json(j)
273
- # todo
274
- end
275
- end
276
-
277
264
 
265
+ ParamsOfRemove = KwStruct.new(:debot_handle)
278
266
 
279
267
  #
280
268
  # functions
281
269
  #
282
270
 
283
- def self.init(ctx, params, app_browser_obj)
284
- Interop::request_to_native_lib(ctx, "debot.init", params) do |resp|
271
+ def self.init(ctx, params, app_browser_obj = nil)
272
+ Interop::request_to_native_lib(
273
+ ctx,
274
+ "debot.init",
275
+ params
276
+ ) do |resp|
285
277
  if resp.success?
286
- yield NativeLibResponsetResult.new(
287
- result: nil
278
+ debot_info = resp.result["info"].transform_keys(&:to_sym)
279
+ debot_info[:dabi_version] = debot_info.delete(:dabiVersion)
280
+ yield NativeLibResponseResult.new(
281
+ result: RegisteredDebot.new(
282
+ debot_handle: resp.result["debot_handle"],
283
+ debot_abi: resp.result["debot_abi"],
284
+ info: DebotInfo.new(**debot_info)
285
+ )
288
286
  )
289
287
  else
290
288
  yield resp
@@ -300,7 +298,7 @@ module TonSdk
300
298
  is_single_thread_only: false
301
299
  ) do |resp|
302
300
  if resp.success?
303
- yield NativeLibResponsetResult.new(
301
+ yield NativeLibResponseResult.new(
304
302
  result: nil
305
303
  )
306
304
  else
@@ -317,9 +315,12 @@ module TonSdk
317
315
  is_single_thread_only: false
318
316
  ) do |resp|
319
317
  if resp.success?
320
- yield NativeLibResponsetResult.new(
321
- # TODO: parse DebotInfo
322
- result: ResultOfFetch.new(info: resp.result["info"])
318
+ debot_info = resp.result["info"].transform_keys(&:to_sym)
319
+ debot_info[:dabi_version] = debot_info.delete(:dabiVersion)
320
+ yield NativeLibResponseResult.new(
321
+ result: ResultOfFetch.new(
322
+ info: DebotInfo.new(**debot_info)
323
+ )
323
324
  )
324
325
  else
325
326
  yield resp
@@ -330,7 +331,7 @@ module TonSdk
330
331
  def self.execute(ctx, params)
331
332
  Interop::request_to_native_lib(ctx, "debot.execute", params) do |resp|
332
333
  if resp.success?
333
- yield NativeLibResponsetResult.new(
334
+ yield NativeLibResponseResult.new(
334
335
  result: nil
335
336
  )
336
337
  else
@@ -342,7 +343,7 @@ module TonSdk
342
343
  def self.remove(ctx, params)
343
344
  Interop::request_to_native_lib(ctx, "debot.remove", params) do |resp|
344
345
  if resp.success?
345
- yield NativeLibResponsetResult.new(
346
+ yield NativeLibResponseResult.new(
346
347
  result: nil
347
348
  )
348
349
  else
@@ -354,7 +355,7 @@ module TonSdk
354
355
  def self.send(ctx, params)
355
356
  Interop::request_to_native_lib(ctx, "debot.send", params) do |resp|
356
357
  if resp.success?
357
- yield NativeLibResponsetResult.new(
358
+ yield NativeLibResponseResult.new(
358
359
  result: nil
359
360
  )
360
361
  else
@@ -17,4 +17,4 @@ module TonSdk
17
17
 
18
18
  def self.base64_from_hex(hex_digest) = [[hex_digest].pack("H*")].pack("m0")
19
19
  end
20
- end
20
+ end
@@ -148,7 +148,7 @@ module TonSdk
148
148
 
149
149
  # using @@request_counter here to pass a @@request_counter and handlers and then retrieve them
150
150
  # is probably isn't needed.
151
- # Thanks to the way Ruby is, the same affect can be achived by a block which is an easier way.
151
+ # Thanks to the way Ruby is, the same affect can be achieved by a block which is an easier way.
152
152
  # Nonetheless, @@request_counter is incremented with each request and then sent out to a server
153
153
  # in order to keep a server happy,
154
154
  # because otherwise a server will, probably, reply in a wrong way.
@@ -172,12 +172,12 @@ module TonSdk
172
172
 
173
173
  when TcResponseCodes::SUCCESS
174
174
  if block_given?
175
- yield NativeLibResponsetResult.new(result: tc_data_json_content)
175
+ yield NativeLibResponseResult.new(result: tc_data_json_content)
176
176
  end
177
177
 
178
178
  when TcResponseCodes::ERROR
179
179
  if block_given?
180
- yield NativeLibResponsetResult.new(error: tc_data_json_content)
180
+ yield NativeLibResponseResult.new(error: tc_data_json_content)
181
181
  end
182
182
 
183
183
  when TcResponseCodes::NOP
@@ -135,7 +135,7 @@ module TonSdk
135
135
 
136
136
  def to_h
137
137
  h = super
138
- h[:fields] = self.fields.map(&:to_h)
138
+ h[:fields] = fields.map(&:to_h)
139
139
  h
140
140
  end
141
141
  end
@@ -222,7 +222,7 @@ module TonSdk
222
222
 
223
223
  def to_h
224
224
  h = super
225
- h[:abi_registry] = self.abi_registry&.map(&:to_h)
225
+ h[:abi_registry] = abi_registry&.map(&:to_h)
226
226
  h
227
227
  end
228
228
  end
@@ -261,7 +261,7 @@ module TonSdk
261
261
  is_single_thread_only: false
262
262
  ) do |resp|
263
263
  if resp.success?
264
- yield NativeLibResponsetResult.new(
264
+ yield NativeLibResponseResult.new(
265
265
  result: ResultOfQueryCollection.new(result: resp.result["result"])
266
266
  )
267
267
  else
@@ -278,7 +278,7 @@ module TonSdk
278
278
  is_single_thread_only: false
279
279
  ) do |resp|
280
280
  if resp.success?
281
- yield NativeLibResponsetResult.new(
281
+ yield NativeLibResponseResult.new(
282
282
  result: ResultOfWaitForCollection.new(result: resp.result["result"])
283
283
  )
284
284
  else
@@ -290,7 +290,7 @@ module TonSdk
290
290
  def self.unsubscribe(ctx, params)
291
291
  Interop::request_to_native_lib(ctx, "net.unsubscribe", params) do |resp|
292
292
  if resp.success?
293
- yield NativeLibResponsetResult.new(
293
+ yield NativeLibResponseResult.new(
294
294
  result: ""
295
295
  )
296
296
  else
@@ -308,7 +308,7 @@ module TonSdk
308
308
  is_single_thread_only: false
309
309
  ) do |resp|
310
310
  if resp.success?
311
- yield NativeLibResponsetResult.new(
311
+ yield NativeLibResponseResult.new(
312
312
  result: ResultOfSubscribeCollection.new(handle: resp.result["handle"])
313
313
  )
314
314
  else
@@ -320,7 +320,7 @@ module TonSdk
320
320
  def self.query(ctx, params)
321
321
  Interop::request_to_native_lib(ctx, "net.query", params) do |resp|
322
322
  if resp.success?
323
- yield NativeLibResponsetResult.new(
323
+ yield NativeLibResponseResult.new(
324
324
  result: ResultOfQuery.new(result: resp.result["result"])
325
325
  )
326
326
  else
@@ -332,7 +332,7 @@ module TonSdk
332
332
  def self.suspend(ctx)
333
333
  Interop::request_to_native_lib(ctx, "net.suspend") do |resp|
334
334
  if resp.success?
335
- yield NativeLibResponsetResult.new(result: "")
335
+ yield NativeLibResponseResult.new(result: "")
336
336
  else
337
337
  yield resp
338
338
  end
@@ -342,7 +342,7 @@ module TonSdk
342
342
  def self.resume(ctx)
343
343
  Interop::request_to_native_lib(ctx, "net.resume") do |resp|
344
344
  if resp.success?
345
- yield NativeLibResponsetResult.new(result: "")
345
+ yield NativeLibResponseResult.new(result: "")
346
346
  else
347
347
  yield resp
348
348
  end
@@ -352,7 +352,7 @@ module TonSdk
352
352
  def self.find_last_shard_block(ctx, params)
353
353
  Interop::request_to_native_lib(ctx, "net.find_last_shard_block", params) do |resp|
354
354
  if resp.success?
355
- yield NativeLibResponsetResult.new(
355
+ yield NativeLibResponseResult.new(
356
356
  result: ResultOfFindLastShardBlock.new(block_id: resp.result["block_id"])
357
357
  )
358
358
  else
@@ -364,7 +364,7 @@ module TonSdk
364
364
  def self.fetch_endpoints(ctx)
365
365
  Interop::request_to_native_lib(ctx, "net.fetch_endpoints") do |resp|
366
366
  if resp.success?
367
- yield NativeLibResponsetResult.new(
367
+ yield NativeLibResponseResult.new(
368
368
  result: EndpointsSet.new(endpoints: resp.result["endpoints"])
369
369
  )
370
370
  else
@@ -376,7 +376,7 @@ module TonSdk
376
376
  def self.set_endpoints(ctx, params)
377
377
  Interop::request_to_native_lib(ctx, "net.set_endpoints", params) do |resp|
378
378
  if resp.success?
379
- yield NativeLibResponsetResult.new(
379
+ yield NativeLibResponseResult.new(
380
380
  result: nil
381
381
  )
382
382
  else
@@ -388,7 +388,7 @@ module TonSdk
388
388
  def self.batch_query(ctx, params)
389
389
  Interop::request_to_native_lib(ctx, "net.batch_query", params) do |resp|
390
390
  if resp.success?
391
- yield NativeLibResponsetResult.new(
391
+ yield NativeLibResponseResult.new(
392
392
  result: ResultOfBatchQuery.new(results: resp.result["results"])
393
393
  )
394
394
  else
@@ -400,7 +400,7 @@ module TonSdk
400
400
  def self.aggregate_collection(ctx, params)
401
401
  Interop::request_to_native_lib(ctx, "net.aggregate_collection", params) do |resp|
402
402
  if resp.success?
403
- yield NativeLibResponsetResult.new(
403
+ yield NativeLibResponseResult.new(
404
404
  result: ResultOfAggregateCollection.new(values: resp.result["values"])
405
405
  )
406
406
  else
@@ -409,10 +409,10 @@ module TonSdk
409
409
  end
410
410
  end
411
411
 
412
- def self.get_endpoints(ctx, params)
413
- Interop::request_to_native_lib(ctx, "net.get_endpoints", params) do |resp|
412
+ def self.get_endpoints(ctx)
413
+ Interop::request_to_native_lib(ctx, "net.get_endpoints") do |resp|
414
414
  if resp.success?
415
- yield NativeLibResponsetResult.new(
415
+ yield NativeLibResponseResult.new(
416
416
  result: ResultOfGetEndpoints.new(
417
417
  query: resp.result["query"],
418
418
  endpoints: resp.result["endpoints"],
@@ -427,7 +427,7 @@ module TonSdk
427
427
  def self.query_counterparties(ctx, params)
428
428
  Interop::request_to_native_lib(ctx, "net.query_counterparties", params) do |resp|
429
429
  if resp.success?
430
- yield NativeLibResponsetResult.new(
430
+ yield NativeLibResponseResult.new(
431
431
  result: ResultOfQueryCollection.new(result: resp.result["result"])
432
432
  )
433
433
  else
@@ -439,7 +439,7 @@ module TonSdk
439
439
  def self.query_transaction_tree(ctx, params)
440
440
  Interop::request_to_native_lib(ctx, "net.query_transaction_tree", params) do |resp|
441
441
  if resp.success?
442
- yield NativeLibResponsetResult.new(
442
+ yield NativeLibResponseResult.new(
443
443
  result: ResultOfQueryTransactionTree.new(
444
444
  messages: resp.result["messages"],
445
445
  transactions: resp.result["transactions"],
@@ -454,7 +454,7 @@ module TonSdk
454
454
  def self.create_block_iterator(ctx, params)
455
455
  Interop::request_to_native_lib(ctx, "net.create_block_iterator", params) do |resp|
456
456
  if resp.success?
457
- yield NativeLibResponsetResult.new(
457
+ yield NativeLibResponseResult.new(
458
458
  result: RegisteredIterator.new(handle: resp.result["handle"])
459
459
  )
460
460
  else
@@ -466,7 +466,7 @@ module TonSdk
466
466
  def self.resume_block_iterator(ctx, params)
467
467
  Interop::request_to_native_lib(ctx, "net.resume_block_iterator", params) do |resp|
468
468
  if resp.success?
469
- yield NativeLibResponsetResult.new(
469
+ yield NativeLibResponseResult.new(
470
470
  result: RegisteredIterator.new(handle: resp.result["handle"])
471
471
  )
472
472
  else
@@ -478,7 +478,7 @@ module TonSdk
478
478
  def self.create_transaction_iterator(ctx, params)
479
479
  Interop::request_to_native_lib(ctx, "net.create_transaction_iterator", params) do |resp|
480
480
  if resp.success?
481
- yield NativeLibResponsetResult.new(
481
+ yield NativeLibResponseResult.new(
482
482
  result: RegisteredIterator.new(handle: resp.result["handle"])
483
483
  )
484
484
  else
@@ -490,7 +490,7 @@ module TonSdk
490
490
  def self.resume_transaction_iterator(ctx, params)
491
491
  Interop::request_to_native_lib(ctx, "net.resume_transaction_iterator", params) do |resp|
492
492
  if resp.success?
493
- yield NativeLibResponsetResult.new(
493
+ yield NativeLibResponseResult.new(
494
494
  result: RegisteredIterator.new(handle: resp.result["handle"])
495
495
  )
496
496
  else
@@ -502,7 +502,7 @@ module TonSdk
502
502
  def self.iterator_next(ctx, params)
503
503
  Interop::request_to_native_lib(ctx, "net.iterator_next", params) do |resp|
504
504
  if resp.success?
505
- yield NativeLibResponsetResult.new(
505
+ yield NativeLibResponseResult.new(
506
506
  result: ResultOfIteratorNext.new(
507
507
  items: resp.result["items"],
508
508
  has_more: resp.result["has_more"],
@@ -518,7 +518,7 @@ module TonSdk
518
518
  def self.remove_iterator(ctx, params)
519
519
  Interop::request_to_native_lib(ctx, "net.remove_iterator", params) do |resp|
520
520
  if resp.success?
521
- yield NativeLibResponsetResult.new(
521
+ yield NativeLibResponseResult.new(
522
522
  result: nil
523
523
  )
524
524
  else