ton_sdk_client 1.26.0 → 1.34.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.
@@ -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?
278
+ debot_info = resp.result["info"].transform_keys(&:to_sym)
279
+ debot_info[:dabi_version] = debot_info.delete(:dabiVersion)
286
280
  yield NativeLibResponseResult.new(
287
- result: nil
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
@@ -317,9 +315,12 @@ module TonSdk
317
315
  is_single_thread_only: false
318
316
  ) do |resp|
319
317
  if resp.success?
318
+ debot_info = resp.result["info"].transform_keys(&:to_sym)
319
+ debot_info[:dabi_version] = debot_info.delete(:dabiVersion)
320
320
  yield NativeLibResponseResult.new(
321
- # TODO: parse DebotInfo
322
- result: ResultOfFetch.new(info: resp.result["info"])
321
+ result: ResultOfFetch.new(
322
+ info: DebotInfo.new(**debot_info)
323
+ )
323
324
  )
324
325
  else
325
326
  yield resp
@@ -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.
@@ -74,7 +74,10 @@ module TonSdk
74
74
  end
75
75
  end
76
76
 
77
+ ParamsOfSubscribe = KwStruct.new(:subscription, :variables)
78
+
77
79
  ResultOfSubscribeCollection = KwStruct.new(:handle)
80
+
78
81
  ParamsOfQuery = KwStruct.new(:query, :variables) do
79
82
  def initialize(query:, variables: nil)
80
83
  super
@@ -135,7 +138,7 @@ module TonSdk
135
138
 
136
139
  def to_h
137
140
  h = super
138
- h[:fields] = self.fields.map(&:to_h)
141
+ h[:fields] = fields.map(&:to_h)
139
142
  h
140
143
  end
141
144
  end
@@ -222,7 +225,7 @@ module TonSdk
222
225
 
223
226
  def to_h
224
227
  h = super
225
- h[:abi_registry] = self.abi_registry&.map(&:to_h)
228
+ h[:abi_registry] = abi_registry&.map(&:to_h)
226
229
  h
227
230
  end
228
231
  end
@@ -317,6 +320,24 @@ module TonSdk
317
320
  end
318
321
  end
319
322
 
323
+ def self.subscribe(ctx, params, client_callback: nil)
324
+ Interop::request_to_native_lib(
325
+ ctx,
326
+ "net.subscribe",
327
+ params,
328
+ client_callback: client_callback,
329
+ is_single_thread_only: false
330
+ ) do |resp|
331
+ if resp.success?
332
+ yield NativeLibResponseResult.new(
333
+ result: ResultOfSubscribeCollection.new(handle: resp.result["handle"])
334
+ )
335
+ else
336
+ yield resp
337
+ end
338
+ end
339
+ end
340
+
320
341
  def self.query(ctx, params)
321
342
  Interop::request_to_native_lib(ctx, "net.query", params) do |resp|
322
343
  if resp.success?
@@ -409,8 +430,8 @@ module TonSdk
409
430
  end
410
431
  end
411
432
 
412
- def self.get_endpoints(ctx, params)
413
- Interop::request_to_native_lib(ctx, "net.get_endpoints", params) do |resp|
433
+ def self.get_endpoints(ctx)
434
+ Interop::request_to_native_lib(ctx, "net.get_endpoints") do |resp|
414
435
  if resp.success?
415
436
  yield NativeLibResponseResult.new(
416
437
  result: ResultOfGetEndpoints.new(
@@ -526,6 +547,5 @@ module TonSdk
526
547
  end
527
548
  end
528
549
  end
529
-
530
550
  end
531
551
  end
@@ -1,10 +1,28 @@
1
1
  module TonSdk
2
2
  module Processing
3
-
4
3
  #
5
4
  # types
6
5
  #
7
6
 
7
+ module ErrorCode
8
+ MESSAGE_ALREADY_EXPIRED = 501
9
+ MESSAGE_HAS_NOT_DESTINATION_ADDRESS = 502
10
+ CAN_NOT_BUILD_MESSAGE_CELL = 503
11
+ FETCH_BLOCK_FAILED = 504
12
+ SEND_MESSAGE_FAILED = 505
13
+ INVALID_MESSAGE_BOC = 506
14
+ MESSAGE_EXPIRED = 507
15
+ TRANSACTION_WAIT_TIMEOUT = 508
16
+ INVALID_BLOCK_RECEIVED = 509
17
+ CAN_NOT_CHECK_BLOCK_SHARD = 510
18
+ BLOCK_NOT_FOUND = 511
19
+ INVALID_DATA = 512
20
+ EXTERNAL_SIGNER_MUST_NOT_BE_USED = 513
21
+ MESSAGE_REJECTED = 514
22
+ INVALID_REMP_STATUS = 515
23
+ NEXT_REMP_STATUS_TIMEOUT = 516
24
+ end
25
+
8
26
  class ParamsOfSendMessage
9
27
  attr_reader :message, :abi, :send_events
10
28
 
@@ -16,9 +34,9 @@ module TonSdk
16
34
 
17
35
  def to_h
18
36
  {
19
- message: @message,
20
- abi: @abi.nil? ? nil : @abi.to_h,
21
- send_events: @send_events
37
+ message: message,
38
+ abi: abi&.to_h,
39
+ send_events: send_events
22
40
  }
23
41
  end
24
42
  end
@@ -37,10 +55,10 @@ module TonSdk
37
55
 
38
56
  def to_h
39
57
  {
40
- abi: @abi.nil? ? nil : @abi.to_h,
41
- message: @message,
42
- shard_block_id: @shard_block_id,
43
- send_events: @send_events
58
+ abi: abi&.to_h,
59
+ message: message,
60
+ shard_block_id: shard_block_id,
61
+ send_events: send_events
44
62
  }
45
63
  end
46
64
  end
@@ -57,29 +75,34 @@ module TonSdk
57
75
 
58
76
  def to_h
59
77
  {
60
- transaction: @transaction,
61
- out_messages: @out_messages,
62
- decoded: @decoded,
63
- fees: @fees
78
+ transaction: transaction,
79
+ out_messages: out_messages,
80
+ decoded: decoded,
81
+ fees: fees
64
82
  }
65
83
  end
66
84
  end
67
85
 
68
86
  class ProcessingEvent
69
- TYPES = [
70
- :will_fetch_first_block,
71
- :fetch_first_block_failed,
72
- :will_send,
73
- :did_send,
74
- :send_failed,
75
- :will_fetch_next_block,
76
- :fetch_next_block_failed,
77
- :message_expired
87
+ TYPES = %i[
88
+ will_fetch_first_block
89
+ fetch_first_block_failed
90
+ will_send
91
+ did_send
92
+ send_failed
93
+ will_fetch_next_block
94
+ fetch_next_block_failed
95
+ message_expired
96
+ remp_sent_to_validators
97
+ remp_included_into_block
98
+ remp_included_into_accepted_block
99
+ remp_other
100
+ remp_error
78
101
  ]
79
102
 
80
- attr_reader :type_, :error, :shard_block_id, :message_id, :message
103
+ attr_reader :type_, :error, :shard_block_id, :message_id, :message, :args
81
104
 
82
- def initialize(type_:, error: nil, shard_block_id: nil, message_id: nil, message: nil)
105
+ def initialize(type_:, error: nil, shard_block_id: nil, message_id: nil, message: nil, **args)
83
106
  unless TYPES.include?(type_)
84
107
  raise ArgumentError.new("type #{type_} is unknown; known types: #{TYPES}")
85
108
  end
@@ -88,6 +111,7 @@ module TonSdk
88
111
  @shard_block_id = shard_block_id
89
112
  @message_id = message_id
90
113
  @message = message
114
+ @args = args
91
115
  end
92
116
 
93
117
  def to_h
@@ -96,34 +120,40 @@ module TonSdk
96
120
  }
97
121
 
98
122
  h2 = case @type_
99
- when :will_fetch_first_block
100
- { }
101
- when :fetch_first_block_failed
102
- {
103
- error: @error
104
- }
105
- when :will_send, :did_send, :will_fetch_next_block
106
- {
107
- shard_block_id: @shard_block_id,
108
- message_id: @message_id,
109
- message: @message
110
- }
111
- when :send_failed, :fetch_next_block_failed
112
- {
113
- shard_block_id: @shard_block_id,
114
- message_id: @message_id,
115
- message: @message,
116
- error: @error
117
- }
118
- when :message_expired
119
- {
120
- message_id: @message_id,
121
- message: @message,
122
- error: @error
123
- }
124
- else
125
- raise ArgumentError.new("unsupported type: #{@type_}")
126
- end
123
+ when :will_fetch_first_block
124
+ { }
125
+ when :fetch_first_block_failed
126
+ {
127
+ error: @error
128
+ }
129
+ when :will_send, :did_send, :will_fetch_next_block
130
+ {
131
+ shard_block_id: @shard_block_id,
132
+ message_id: @message_id,
133
+ message: @message
134
+ }
135
+ when :send_failed, :fetch_next_block_failed
136
+ {
137
+ shard_block_id: @shard_block_id,
138
+ message_id: @message_id,
139
+ message: @message,
140
+ error: @error
141
+ }
142
+ when :message_expired
143
+ {
144
+ message_id: @message_id,
145
+ message: @message,
146
+ error: @error
147
+ }
148
+ when :remp_sent_to_validators, :remp_included_into_block, :remp_included_into_accepted_block, :remp_other, :remp_error
149
+ {
150
+ message_id: message_id,
151
+ timestamp: args[:timestamp],
152
+ json: args[:json]
153
+ }
154
+ else
155
+ raise ArgumentError.new("unsupported type: #{@type_}")
156
+ end
127
157
 
128
158
  h1.merge(h2)
129
159
  end
@@ -136,6 +166,10 @@ module TonSdk
136
166
  end
137
167
 
138
168
  ParamsOfProcessMessage = KwStruct.new(:message_encode_params, :send_events) do
169
+ def initialize(message_encode_params:, send_events:)
170
+ super
171
+ end
172
+
139
173
  def to_h
140
174
  {
141
175
  message_encode_params: message_encode_params.to_h,
@@ -188,8 +222,11 @@ module TonSdk
188
222
  result: ResultOfProcessMessage.new(
189
223
  transaction: resp.result["transaction"],
190
224
  out_messages: resp.result["out_messages"],
191
- decoded: resp.result["decoded"],
192
- fees: resp.result["fees"]
225
+ decoded: DecodedOutput.new(
226
+ out_messages: resp.result.dig("decoded", "out_messages"),
227
+ output: resp.result.dig("decoded", "output")
228
+ ),
229
+ fees: Tvm::TransactionFees.new(**resp.result["fees"].transform_keys(&:to_sym))
193
230
  )
194
231
  )
195
232
  else
@@ -215,8 +252,11 @@ module TonSdk
215
252
  result: ResultOfProcessMessage.new(
216
253
  transaction: resp.result["transaction"],
217
254
  out_messages: resp.result["out_messages"],
218
- decoded: resp.result["decoded"],
219
- fees: resp.result["fees"]
255
+ decoded: DecodedOutput.new(
256
+ out_messages: resp.result.dig("decoded", "out_messages"),
257
+ output: resp.result.dig("decoded", "output")
258
+ ),
259
+ fees: Tvm::TransactionFees.new(**resp.result["fees"].transform_keys(&:to_sym))
220
260
  )
221
261
  )
222
262
  else
@@ -162,7 +162,10 @@ module TonSdk
162
162
  :gas_fee,
163
163
  :out_msgs_fwd_fee,
164
164
  :total_account_fees,
165
- :total_output
165
+ :total_output,
166
+ :ext_in_msg_fee,
167
+ :total_fwd_fees,
168
+ :account_fees
166
169
  ) do
167
170
  def initialize(
168
171
  in_msg_fwd_fee:,
@@ -170,7 +173,10 @@ module TonSdk
170
173
  gas_fee:,
171
174
  out_msgs_fwd_fee:,
172
175
  total_account_fees:,
173
- total_output:
176
+ total_output:,
177
+ ext_in_msg_fee:,
178
+ total_fwd_fees:,
179
+ account_fees:
174
180
  )
175
181
  super
176
182
  end
@@ -1,4 +1,4 @@
1
1
  module TonSdk
2
- VERSION = "1.26.0"
3
- NATIVE_SDK_VERSION = "1.26.0"
2
+ VERSION = "1.34.0"
3
+ NATIVE_SDK_VERSION = "1.34.0"
4
4
  end