ton_sdk_client 1.13.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,12 +26,12 @@ module TonSdk
26
26
  DebotAction = Struct.new(:description, :name, :action_type, :to, :attributes, :misc, keyword_init: true) do
27
27
  def to_h
28
28
  {
29
- description: @description,
30
- name: @name,
31
- action_type: @action_type,
32
- to: @to,
33
- attributes: @attributes,
34
- misc: @misc
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
35
35
  }
36
36
  end
37
37
 
@@ -49,15 +49,18 @@ module TonSdk
49
49
  end
50
50
  end
51
51
 
52
- ParamsOfStart = Struct.new(:debot_handle) do
53
- def to_h = { debot_handle: @debot_handle }
54
- end
52
+ ParamsOfStart = Struct.new(:debot_handle)
55
53
 
56
- RegisteredDebot = Struct.new(:debot_handle) do
57
- def to_h = { debot_handle: @debot_handle }
54
+ RegisteredDebot = Struct.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
+ }
58
60
  end
59
61
 
60
62
  class ParamsOfAppDebotBrowser
63
+ private_class_method :new
61
64
 
62
65
  # todo remove?
63
66
  TYPE_VALUES = [
@@ -68,50 +71,56 @@ module TonSdk
68
71
  :input,
69
72
  :get_signing_box,
70
73
  :invoke_debot,
71
- :send
74
+ :send,
75
+ :approve
72
76
  ]
73
77
 
74
- attr_reader :type_, :msg, :context_id, :action, :prompt, :debot_addr, :message
78
+ attr_reader :type_, :msg, :context_id, :action, :prompt, :debot_addr, :message, :activity
75
79
 
76
- def new_with_type_log(msg)
80
+ def self.new_with_type_log(msg)
77
81
  @type_ = :log
78
82
  @msg = msg
79
83
  end
80
84
 
81
- def new_with_type_switch(context_id)
85
+ def self.new_with_type_switch(context_id)
82
86
  @type_ = :switch
83
87
  @context_id = context_id
84
88
  end
85
89
 
86
- def new_with_type_switch_completed
90
+ def self.new_with_type_switch_completed
87
91
  @type_ = :switch_completed
88
92
  end
89
93
 
90
- def new_with_type_show_action(action)
94
+ def self.new_with_type_show_action(action)
91
95
  @type_ = :show_action
92
96
  @action = action
93
97
  end
94
98
 
95
- def new_with_type_input(prompt)
99
+ def self.new_with_type_input(prompt)
96
100
  @type_ = :input
97
101
  @prompt = prompt
98
102
  end
99
103
 
100
- def new_with_type_get_signing_box
104
+ def self.new_with_type_get_signing_box
101
105
  @type_ = :get_signing_box
102
106
  end
103
107
 
104
- def new_with_type_invoke_debot(debot_addr, action)
108
+ def self.new_with_type_invoke_debot(debot_addr, action)
105
109
  @type_ = :invoke_debot
106
110
  @debot_addr = debot_addr
107
111
  @action = action
108
112
  end
109
113
 
110
- def new_with_type_send(message)
114
+ def self.new_with_type_send(message)
111
115
  @type_ = :send
112
116
  @message = message
113
117
  end
114
118
 
119
+ def self.new_with_type_approve(activity)
120
+ @type_ = :approve
121
+ @activity = activity
122
+ end
123
+
115
124
  def to_h
116
125
  {
117
126
  type: Helper.sym_to_capitalized_case_str(@type_),
@@ -127,14 +136,38 @@ module TonSdk
127
136
  def self.from_json(j)
128
137
  return nil if j.nil?
129
138
 
130
- self.new(
131
- type_: self.parse_type(j["type"]),
132
- msg: j["msg"],
133
- context_id: j["context_id"],
134
- action: DebotAction.from_json(j["action"]),
135
- prompt: j["prompt"],
136
- debot_addr: j["debot_addr"]
137
- )
139
+ tp = self.parse_type(j["type"])
140
+ case tp
141
+ when :log
142
+ self.new_with_type_log(j["msg"])
143
+
144
+ when :switch
145
+ self.new_with_type_switch(j["context_id"])
146
+
147
+ when :switch_completed
148
+ self.new_with_type_switch_completed
149
+
150
+ when :show_action
151
+ self.new_with_type_show_action(DebotAction.from_json(j["action"]))
152
+
153
+ when :input
154
+ self.new_with_type_input(j["prompt"])
155
+
156
+ when :get_signing_box
157
+ self.new_with_type_get_signing_box
158
+
159
+ when :invoke_debot
160
+ self.new_with_type_invoke_debot(j["debot_addr"], DebotAction.from_json(j["action"]))
161
+
162
+ when :send
163
+ self.new_with_type_send(j["message"])
164
+
165
+ when :approve
166
+ self.new_with_type_send(DebotActivity.from_json(j["activity"]))
167
+
168
+ else
169
+ raise ArgumentError.new("no handler for type: #{tp}")
170
+ end
138
171
  end
139
172
 
140
173
  private
@@ -150,31 +183,31 @@ module TonSdk
150
183
  end
151
184
 
152
185
  class ResultOfAppDebotBrowser
186
+ private_class_method :new
187
+
153
188
  attr_reader :type_, :value, :signing_box, :is_approved
154
189
 
155
- def new_with_type_input(a)
190
+ def self.new_with_type_input(a)
156
191
  @type_ = :input
157
192
  @value = a
158
193
  end
159
194
 
160
- def new_with_type_get_signing_box(a)
195
+ def self.new_with_type_get_signing_box(a)
161
196
  @type_ = :get_signing_box
162
197
  @signing_box = signing_box
163
198
  end
164
199
 
165
- def new_with_type_invoke_debot
200
+ def self.new_with_type_invoke_debot
166
201
  @type_ = :invoke_debot
167
202
  end
168
203
 
169
- def new_with_type_approve(a)
204
+ def self.new_with_type_approve(a)
170
205
  @type_ = :approve
171
206
  @is_approved = a
172
207
  end
173
208
  end
174
209
 
175
- ParamsOfFetch = Struct.new(:address) do
176
- def to_h = { address: @address }
177
- end
210
+ ParamsOfFetch = Struct.new(:address)
178
211
 
179
212
  ParamsOfExecute = Struct.new(:debot_handle, :action) do
180
213
  def to_h
@@ -185,22 +218,13 @@ module TonSdk
185
218
  end
186
219
  end
187
220
 
188
- ParamsOfSend = Struct.new(:debot_handle, :message) do
189
- def to_h
190
- {
191
- debot_handle: @debot_handle,
192
- message: @message
193
- }
194
- end
195
- end
196
-
221
+ ParamsOfSend = Struct.new(:debot_handle, :message)
197
222
  ParamsOfInit = Struct.new(:address)
198
-
199
223
  DebotInfo = Struct.new(
200
224
  :name,
201
225
  :version,
202
226
  :publisher,
203
- :key,
227
+ :caption,
204
228
  :author,
205
229
  :support,
206
230
  :hello,
@@ -209,9 +233,48 @@ module TonSdk
209
233
  :icon,
210
234
  :interfaces,
211
235
  keyword_init: true
212
- )
236
+ ) do
237
+ def initialize(
238
+ name: nil,
239
+ version: nil,
240
+ publisher: nil,
241
+ caption: nil,
242
+ author: nil,
243
+ support: nil,
244
+ hello: nil,
245
+ language: nil,
246
+ dabi: nil,
247
+ icon: nil,
248
+ interfaces: []
249
+ )
250
+ super
251
+ end
252
+ end
213
253
 
214
254
  ResultOfFetch = Struct.new(:info)
255
+ Spending = Struct.new(:amount, :dst)
256
+
257
+ class DebotActivity
258
+ private_class_method :new
259
+
260
+ attr_reader :type_, :msg, :dst, :out, :fee, :setcode, :signkey, :signing_box_handle
261
+
262
+ def self.new_with_type_transaction(msg:, dst:, out:, fee:, setcode:, signkey:, signing_box_handle:)
263
+ @type_ = :transaction
264
+ @msg = msg
265
+ @dst = dst
266
+ @out = out
267
+ @fee = fee
268
+ @setcode = setcode
269
+ @signkey = signkey
270
+ @signing_box_handle = signing_box_handle
271
+ end
272
+
273
+ def self.from_json(j)
274
+ # todo
275
+ end
276
+ end
277
+
215
278
 
216
279
 
217
280
  #
@@ -219,7 +282,7 @@ module TonSdk
219
282
  #
220
283
 
221
284
  def self.init(ctx, params, app_browser_obj)
222
- Interop::request_to_native_lib(ctx, "debot.init", params.to_h.to_json) do |resp|
285
+ Interop::request_to_native_lib(ctx, "debot.init", params) do |resp|
223
286
  if resp.success?
224
287
  yield NativeLibResponsetResult.new(
225
288
  result: nil
@@ -234,7 +297,7 @@ module TonSdk
234
297
  Interop::request_to_native_lib(
235
298
  ctx,
236
299
  "debot.start",
237
- params.to_h.to_json,
300
+ params,
238
301
  is_single_thread_only: false
239
302
  ) do |resp|
240
303
  if resp.success?
@@ -251,7 +314,7 @@ module TonSdk
251
314
  Interop::request_to_native_lib(
252
315
  ctx,
253
316
  "debot.fetch",
254
- params.to_h.to_json,
317
+ params,
255
318
  is_single_thread_only: false
256
319
  ) do |resp|
257
320
  if resp.success?
@@ -266,7 +329,7 @@ module TonSdk
266
329
  end
267
330
 
268
331
  def self.execute(ctx, params)
269
- Interop::request_to_native_lib(ctx, "debot.execute", params.to_h.to_json) do |resp|
332
+ Interop::request_to_native_lib(ctx, "debot.execute", params) do |resp|
270
333
  if resp.success?
271
334
  yield NativeLibResponsetResult.new(
272
335
  result: nil
@@ -278,7 +341,7 @@ module TonSdk
278
341
  end
279
342
 
280
343
  def self.remove(ctx, params)
281
- Interop::request_to_native_lib(ctx, "debot.remove", params.to_h.to_json) do |resp|
344
+ Interop::request_to_native_lib(ctx, "debot.remove", params) do |resp|
282
345
  if resp.success?
283
346
  yield NativeLibResponsetResult.new(
284
347
  result: nil
@@ -290,7 +353,7 @@ module TonSdk
290
353
  end
291
354
 
292
355
  def self.send(ctx, params)
293
- Interop::request_to_native_lib(ctx, "debot.send", params.to_h.to_json) do |resp|
356
+ Interop::request_to_native_lib(ctx, "debot.send", params) do |resp|
294
357
  if resp.success?
295
358
  yield NativeLibResponsetResult.new(
296
359
  result: nil
@@ -132,12 +132,12 @@ module TonSdk
132
132
  def self.request_to_native_lib(
133
133
  ctx,
134
134
  function_name,
135
- function_params_json = nil,
135
+ function_params = nil,
136
136
  client_callback: nil,
137
137
  is_single_thread_only: true
138
138
  )
139
139
  function_name_tc_str = TcStringData.from_string(function_name)
140
- function_params_json_str = function_params_json || ""
140
+ function_params_json_str = function_params&.to_h.to_json || ""
141
141
  function_params_json_tc_str = TcStringData.from_string(function_params_json_str)
142
142
 
143
143
  @sm = Concurrent::Semaphore.new(1)
@@ -37,20 +37,15 @@ module TonSdk
37
37
  end
38
38
  end
39
39
 
40
- class ParamsOfQueryCollection
41
- attr_reader :collection, :filter, :result, :order, :limit
42
-
40
+ ParamsOfQueryCollection = Struct.new(:collection, :filter, :result, :order, :limit, keyword_init: true) do
43
41
  def initialize(collection: , filter: nil, result: , order: [], limit: nil)
44
- @collection = collection
45
- @filter = filter
46
- @result = result
47
- @order = order
48
- @limit = limit
42
+ super
49
43
  end
50
44
 
51
45
  def to_h
52
- ord_h_s = if !@order.nil?
53
- @order.map do |x|
46
+ h = super
47
+ ord_h_s = if !self.order.nil?
48
+ self.order.map do |x|
54
49
  {
55
50
  path: x.path,
56
51
  direction: x.direction.to_s.upcase
@@ -58,105 +53,54 @@ module TonSdk
58
53
  end
59
54
  end
60
55
 
61
- {
62
- collection: @collection,
63
- filter: @filter,
64
- result: @result,
65
- order: ord_h_s,
66
- limit: @limit
67
- }
56
+ h[:order] = ord_h_s
57
+ h
68
58
  end
69
59
  end
70
60
 
71
61
  ResultOfQueryCollection = Struct.new(:result)
72
-
73
62
  ResultOfWaitForCollection = Struct.new(:result)
74
-
75
63
  ResultOfQuery = Struct.new(:result)
76
-
77
- ResultOfBatchQuery = Struct.new(:results) do
78
- def to_h = { results: @results }
79
- end
80
-
81
- class ParamsOfWaitForCollection
82
- attr_reader :collection, :filter, :result, :timeout
83
-
64
+ ResultOfBatchQuery = Struct.new(:results)
65
+ ParamsOfWaitForCollection = Struct.new(:collection, :filter, :result, :timeout) do
84
66
  def initialize(collection:, filter: nil, result:, timeout: nil)
85
- @collection = collection
86
- @filter = filter
87
- @result = result
88
- @timeout = timeout
89
- end
90
-
91
- def to_h
92
- {
93
- collection: @collection,
94
- filter: @filter,
95
- result: @result,
96
- timeout: @timeout
97
- }
67
+ super
98
68
  end
99
69
  end
100
70
 
101
- class ParamsOfSubscribeCollection
102
- attr_reader :collection, :filter, :result
103
-
71
+ ParamsOfSubscribeCollection = Struct.new(:collection, :filter, :result) do
104
72
  def initialize(collection:, filter: nil, result:)
105
- @collection = collection
106
- @filter = filter
107
- @result = result
108
- end
109
-
110
- def to_h
111
- {
112
- collection: @collection,
113
- filter: @filter,
114
- result: @result
115
- }
73
+ super
116
74
  end
117
75
  end
118
76
 
119
- ResultOfSubscribeCollection = Struct.new(:handle) do
120
- def to_h = { handle: @handle }
121
- end
122
-
77
+ ResultOfSubscribeCollection = Struct.new(:handle)
123
78
  ParamsOfQuery = Struct.new(:query, :variables) do
124
79
  def initialize(query:, variables: nil)
125
80
  super
126
81
  end
127
-
128
- def to_h
129
- {
130
- query: @query,
131
- variables: @variables
132
- }
133
- end
134
- end
135
-
136
- ParamsOfFindLastShardBlock = Struct.new(:address) do
137
- def to_h = { address: @address }
138
82
  end
139
83
 
84
+ ParamsOfFindLastShardBlock = Struct.new(:address)
140
85
  ResultOfFindLastShardBlock = Struct.new(:block_id)
141
-
142
- EndpointsSet = Struct.new(:endpoints) do
143
- def to_h = { endpoints: @endpoints }
144
- end
86
+ EndpointsSet = Struct.new(:endpoints)
145
87
 
146
88
  class ParamsOfQueryOperation
89
+ private_class_method :new
90
+
147
91
  attr_reader :type_, :params
148
92
 
149
- def new_with_type_query_collection(params)
93
+ def self.new_with_type_query_collection(params)
150
94
  @type_ = :query_collection
151
95
  @params = params
152
96
  end
153
97
 
154
- def new_with_type_wait_for_collection(params)
98
+ def self.new_with_type_wait_for_collection(params)
155
99
  @type_ = :wait_for_collection
156
100
  @params = params
157
101
  end
158
102
 
159
- def new_with_type_aggregate_collection(params)
103
+ def self.new_with_type_aggregate_collection(params)
160
104
  @type_ = :aggregate_collection
161
105
  @params = params
162
106
  end
@@ -174,26 +118,20 @@ module TonSdk
174
118
  ParamsOfBatchQuery = Struct.new(:operations) do
175
119
  def to_h
176
120
  {
177
- operations: @operations.compact.map(&:to_h)
121
+ operations: self.operations.compact.map(&:to_h)
178
122
  }
179
123
  end
180
124
  end
181
125
 
182
- class ParamsOfAggregateCollection
183
- attr_reader :collection, :filter, :fields
184
-
126
+ ParamsOfAggregateCollection = Struct.new(:collection, :filter, :fields) do
185
127
  def initialize(collection:, filter: nil, fields: [])
186
- @collection = collection
187
- @filter = filter
188
- @fields = fields
128
+ super
189
129
  end
190
130
 
191
131
  def to_h
192
- {
193
- collection: @collection,
194
- filter: @filter,
195
- fields: @fields.map(&:to_h)
196
- }
132
+ h = super
133
+ h[:fields] = self.fields.map(&:to_h)
134
+ h
197
135
  end
198
136
  end
199
137
 
@@ -224,25 +162,16 @@ module TonSdk
224
162
  end
225
163
  end
226
164
 
227
- ResultOfAggregateCollection = Struct.new(:values) do
228
- def to_h = { values: @values }
229
- end
165
+ ResultOfAggregateCollection = Struct.new(:values)
230
166
 
231
167
  ParamsOfQueryCounterparties = Struct.new(:account, :result, :first, :after, keyword_init: true) do
232
168
  def initialize(account:, result:, first: nil, after: nil)
233
169
  super
234
170
  end
235
-
236
- def to_h
237
- {
238
- account: @account,
239
- result: @result,
240
- first: @first,
241
- after: @after
242
- }
243
- end
244
171
  end
245
172
 
173
+ ResultOfGetEndpoints = Struct.new(:query, :endpoints, keyword_init: true)
174
+
246
175
 
247
176
  #
248
177
  # functions
@@ -252,7 +181,7 @@ module TonSdk
252
181
  Interop::request_to_native_lib(
253
182
  ctx,
254
183
  "net.query_collection",
255
- params.to_h.to_json,
184
+ params,
256
185
  is_single_thread_only: false
257
186
  ) do |resp|
258
187
  if resp.success?
@@ -269,7 +198,7 @@ module TonSdk
269
198
  Interop::request_to_native_lib(
270
199
  ctx,
271
200
  "net.wait_for_collection",
272
- params.to_h.to_json,
201
+ params,
273
202
  is_single_thread_only: false
274
203
  ) do |resp|
275
204
  if resp.success?
@@ -283,7 +212,7 @@ module TonSdk
283
212
  end
284
213
 
285
214
  def self.unsubscribe(ctx, params)
286
- Interop::request_to_native_lib(ctx, "net.unsubscribe", params.to_h.to_json) do |resp|
215
+ Interop::request_to_native_lib(ctx, "net.unsubscribe", params) do |resp|
287
216
  if resp.success?
288
217
  yield NativeLibResponsetResult.new(
289
218
  result: ""
@@ -298,7 +227,7 @@ module TonSdk
298
227
  Interop::request_to_native_lib(
299
228
  ctx,
300
229
  "net.subscribe_collection",
301
- params.to_h.to_json,
230
+ params,
302
231
  client_callback: client_callback,
303
232
  is_single_thread_only: false
304
233
  ) do |resp|
@@ -313,7 +242,7 @@ module TonSdk
313
242
  end
314
243
 
315
244
  def self.query(ctx, params)
316
- Interop::request_to_native_lib(ctx, "net.query", params.to_h.to_json) do |resp|
245
+ Interop::request_to_native_lib(ctx, "net.query", params) do |resp|
317
246
  if resp.success?
318
247
  yield NativeLibResponsetResult.new(
319
248
  result: ResultOfQuery.new(resp.result["result"])
@@ -325,7 +254,7 @@ module TonSdk
325
254
  end
326
255
 
327
256
  def self.suspend(ctx)
328
- Interop::request_to_native_lib(ctx, "net.suspend", "") do |resp|
257
+ Interop::request_to_native_lib(ctx, "net.suspend") do |resp|
329
258
  if resp.success?
330
259
  yield NativeLibResponsetResult.new(result: "")
331
260
  else
@@ -335,7 +264,7 @@ module TonSdk
335
264
  end
336
265
 
337
266
  def self.resume(ctx)
338
- Interop::request_to_native_lib(ctx, "net.resume", "") do |resp|
267
+ Interop::request_to_native_lib(ctx, "net.resume") do |resp|
339
268
  if resp.success?
340
269
  yield NativeLibResponsetResult.new(result: "")
341
270
  else
@@ -345,7 +274,7 @@ module TonSdk
345
274
  end
346
275
 
347
276
  def self.find_last_shard_block(ctx, params)
348
- Interop::request_to_native_lib(ctx, "net.find_last_shard_block", params.to_h.to_json) do |resp|
277
+ Interop::request_to_native_lib(ctx, "net.find_last_shard_block", params) do |resp|
349
278
  if resp.success?
350
279
  yield NativeLibResponsetResult.new(
351
280
  result: ResultOfFindLastShardBlock.new(resp.result["block_id"])
@@ -357,7 +286,7 @@ module TonSdk
357
286
  end
358
287
 
359
288
  def self.fetch_endpoints(ctx)
360
- Interop::request_to_native_lib(ctx, "net.fetch_endpoints", nil) do |resp|
289
+ Interop::request_to_native_lib(ctx, "net.fetch_endpoints") do |resp|
361
290
  if resp.success?
362
291
  yield NativeLibResponsetResult.new(
363
292
  result: EndpointsSet.new(resp.result["endpoints"])
@@ -369,7 +298,7 @@ module TonSdk
369
298
  end
370
299
 
371
300
  def self.set_endpoints(ctx, params)
372
- Interop::request_to_native_lib(ctx, "net.set_endpoints", params.to_h.to_json) do |resp|
301
+ Interop::request_to_native_lib(ctx, "net.set_endpoints", params) do |resp|
373
302
  if resp.success?
374
303
  yield NativeLibResponsetResult.new(
375
304
  result: nil
@@ -382,7 +311,7 @@ module TonSdk
382
311
  end
383
312
 
384
313
  def self.batch_query(ctx, params)
385
- Interop::request_to_native_lib(ctx, "net.batch_query", params.to_h.to_json) do |resp|
314
+ Interop::request_to_native_lib(ctx, "net.batch_query", params) do |resp|
386
315
  if resp.success?
387
316
  yield NativeLibResponsetResult.new(
388
317
  result: ResultOfBatchQuery.new(resp.result["results"])
@@ -394,7 +323,7 @@ module TonSdk
394
323
  end
395
324
 
396
325
  def self.aggregate_collection(ctx, params)
397
- Interop::request_to_native_lib(ctx, "net.aggregate_collection", params.to_h.to_json) do |resp|
326
+ Interop::request_to_native_lib(ctx, "net.aggregate_collection", params) do |resp|
398
327
  if resp.success?
399
328
  yield NativeLibResponsetResult.new(
400
329
  result: ResultOfAggregateCollection.new(resp.result["values"])
@@ -406,7 +335,7 @@ module TonSdk
406
335
  end
407
336
 
408
337
  def self.query_counterparties(ctx, params)
409
- Interop::request_to_native_lib(ctx, "net.query_counterparties", params.to_h.to_json) do |resp|
338
+ Interop::request_to_native_lib(ctx, "net.query_counterparties", params) do |resp|
410
339
  if resp.success?
411
340
  yield NativeLibResponsetResult.new(
412
341
  result: ResultOfQueryCollection.new(resp.result["result"])
@@ -416,4 +345,19 @@ module TonSdk
416
345
  end
417
346
  end
418
347
  end
348
+
349
+ def self.get_endpoints(ctx, params)
350
+ Interop::request_to_native_lib(ctx, "net.get_endpoints", params) do |resp|
351
+ if resp.success?
352
+ yield NativeLibResponsetResult.new(
353
+ result: ResultOfGetEndpoints.new(
354
+ query: resp.result["query"],
355
+ endpoints: resp.result["endpoints"],
356
+ )
357
+ )
358
+ else
359
+ yield resp
360
+ end
361
+ end
362
+ end
419
363
  end