ton_sdk_client 1.7.1
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +46 -0
- data/LICENSE +201 -0
- data/README.md +235 -0
- data/lib/ton_sdk_client.rb +6 -0
- data/lib/ton_sdk_client/abi.rb +956 -0
- data/lib/ton_sdk_client/boc.rb +344 -0
- data/lib/ton_sdk_client/client.rb +208 -0
- data/lib/ton_sdk_client/client_context.rb +51 -0
- data/lib/ton_sdk_client/config.rb +108 -0
- data/lib/ton_sdk_client/crypto.rb +1325 -0
- data/lib/ton_sdk_client/debot.rb +466 -0
- data/lib/ton_sdk_client/helper.rb +20 -0
- data/lib/ton_sdk_client/interop.rb +230 -0
- data/lib/ton_sdk_client/net.rb +452 -0
- data/lib/ton_sdk_client/processing.rb +257 -0
- data/lib/ton_sdk_client/tvm.rb +264 -0
- data/lib/ton_sdk_client/types.rb +44 -0
- data/lib/ton_sdk_client/utils.rb +76 -0
- data/lib/ton_sdk_client/version.rb +5 -0
- metadata +134 -0
@@ -0,0 +1,956 @@
|
|
1
|
+
module TonSdk
|
2
|
+
module Abi
|
3
|
+
|
4
|
+
#
|
5
|
+
# types
|
6
|
+
#
|
7
|
+
|
8
|
+
class Abi
|
9
|
+
TYPES = [:contract, :json, :handle, :serialized]
|
10
|
+
attr_reader :type_, :value
|
11
|
+
|
12
|
+
def initialize(type_:, value:)
|
13
|
+
unless TYPES.include?(type_)
|
14
|
+
raise ArgumentError.new("type #{type_} is unknown; known types: #{TYPES}")
|
15
|
+
end
|
16
|
+
@type_ = type_
|
17
|
+
@value = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_h
|
21
|
+
h1 = {
|
22
|
+
type: Helper.sym_to_capitalized_case_str(@type_)
|
23
|
+
}
|
24
|
+
|
25
|
+
h2 = case @type_
|
26
|
+
when :contract, :serialized
|
27
|
+
{
|
28
|
+
value: @value.to_h
|
29
|
+
}
|
30
|
+
when :json, :handle
|
31
|
+
{
|
32
|
+
value: @value
|
33
|
+
}
|
34
|
+
else
|
35
|
+
raise ArgumentError.new("type #{type_} is unknown; known types: #{TYPES}")
|
36
|
+
end
|
37
|
+
|
38
|
+
h1.merge(h2)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class FunctionHeader
|
43
|
+
attr_reader :expire, :time, :pubkey
|
44
|
+
|
45
|
+
def initialize(expire: nil, time: nil, pubkey: nil)
|
46
|
+
@expire = expire
|
47
|
+
@time = time
|
48
|
+
@pubkey = pubkey
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_h
|
52
|
+
{
|
53
|
+
expire: @expire,
|
54
|
+
time: @time,
|
55
|
+
pubkey: @pubkey
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class CallSet
|
61
|
+
attr_reader :function_name, :header, :input
|
62
|
+
|
63
|
+
def initialize(function_name:, header: nil, input: nil)
|
64
|
+
@function_name = function_name
|
65
|
+
@header = header
|
66
|
+
@input = input
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_h
|
70
|
+
{
|
71
|
+
function_name: @function_name,
|
72
|
+
header: @header.nil? ? nil : @header.to_h,
|
73
|
+
input: @input
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class DeploySet
|
79
|
+
attr_reader :tvc, :workchain_id, :initial_data, :initial_pubkey
|
80
|
+
|
81
|
+
def initialize(tvc:, workchain_id: nil, initial_data: nil, initial_pubkey: nil)
|
82
|
+
@tvc = tvc
|
83
|
+
@workchain_id = workchain_id
|
84
|
+
@initial_data = initial_data
|
85
|
+
@initial_pubkey = initial_pubkey
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_h
|
89
|
+
{
|
90
|
+
tvc: @tvc,
|
91
|
+
workchain_id: @workchain_id,
|
92
|
+
initial_data: @initial_data,
|
93
|
+
initial_pubkey: @initial_pubkey
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class Signer
|
99
|
+
TYPES = [:none, :external, :keys, :signing_box]
|
100
|
+
attr_reader :type_, :public_key, :keys, :handle
|
101
|
+
|
102
|
+
def initialize(type_:, public_key: nil, keys: nil, handle: nil)
|
103
|
+
unless TYPES.include?(type_)
|
104
|
+
raise ArgumentError.new("type #{type_} is unknown; known types: #{TYPES}")
|
105
|
+
end
|
106
|
+
|
107
|
+
@type_ = type_
|
108
|
+
@public_key = public_key
|
109
|
+
@keys = keys
|
110
|
+
@handle = handle
|
111
|
+
end
|
112
|
+
|
113
|
+
def to_h
|
114
|
+
h1 = {
|
115
|
+
type: Helper.sym_to_capitalized_case_str(@type_)
|
116
|
+
}
|
117
|
+
|
118
|
+
h2 = case @type_
|
119
|
+
when :none
|
120
|
+
{ }
|
121
|
+
when :external
|
122
|
+
{
|
123
|
+
public_key: @public_key
|
124
|
+
}
|
125
|
+
when :keys
|
126
|
+
{
|
127
|
+
keys: @keys.to_h
|
128
|
+
}
|
129
|
+
when :signing_box
|
130
|
+
{
|
131
|
+
handle: @handle
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
h1.merge(h2)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class StateInitSource
|
140
|
+
TYPES = [:message, :state_init, :tvc]
|
141
|
+
attr_reader :type_, :source, :code, :data, :library, :tvc, :public_key, :init_params
|
142
|
+
|
143
|
+
def initialize(
|
144
|
+
type_:,
|
145
|
+
source: nil,
|
146
|
+
code: nil,
|
147
|
+
data: nil,
|
148
|
+
library: nil,
|
149
|
+
tvc: nil,
|
150
|
+
public_key: nil,
|
151
|
+
init_params: nil
|
152
|
+
)
|
153
|
+
unless TYPES.include?(type_)
|
154
|
+
raise ArgumentError.new("unknown type: #{type_}; known types: #{TYPES}")
|
155
|
+
end
|
156
|
+
@type_ = type_
|
157
|
+
@source = source
|
158
|
+
@code = code
|
159
|
+
@data = data
|
160
|
+
@library = library
|
161
|
+
@tvc = tvc
|
162
|
+
@public_key = public_key
|
163
|
+
@init_params = init_params
|
164
|
+
end
|
165
|
+
|
166
|
+
def to_h
|
167
|
+
h1 = {
|
168
|
+
type: Helper.sym_to_capitalized_case_str(@type_)
|
169
|
+
}
|
170
|
+
|
171
|
+
h2 = case @type_
|
172
|
+
when :message
|
173
|
+
{
|
174
|
+
source: @source.to_h
|
175
|
+
}
|
176
|
+
when :state_init
|
177
|
+
{
|
178
|
+
code: @code,
|
179
|
+
data: @data,
|
180
|
+
library: @library
|
181
|
+
}
|
182
|
+
when :tvc
|
183
|
+
{
|
184
|
+
public_key: @public_key,
|
185
|
+
init_params: @init_params.to_h
|
186
|
+
}
|
187
|
+
else
|
188
|
+
raise ArgumentError.new("unknown type: #{@type_}; known types: #{TYPES}")
|
189
|
+
end
|
190
|
+
|
191
|
+
h1.merge(h2)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
class StateInitParams
|
196
|
+
attr_reader :abi, :value
|
197
|
+
|
198
|
+
def initialize(abi:, value:)
|
199
|
+
@abi = abi
|
200
|
+
@value = value
|
201
|
+
end
|
202
|
+
|
203
|
+
def to_h
|
204
|
+
{
|
205
|
+
abi: abi.to_h,
|
206
|
+
value: @value
|
207
|
+
}
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
class MessageSource
|
212
|
+
TYPES = [:encoded, :encoding_params]
|
213
|
+
|
214
|
+
attr_reader :type_, :message, :abi, :address, :deploy_set, :call_set,
|
215
|
+
:signer, :processing_try_index
|
216
|
+
|
217
|
+
def initialize(type_:, message: nil, abi: nil, address: nil, deploy_set: nil,
|
218
|
+
call_set: nil, signer: nil, processing_try_index: 0)
|
219
|
+
unless TYPES.include?(type_)
|
220
|
+
raise ArgumentError.new("unknown type: #{type_}; known types: #{TYPES}")
|
221
|
+
end
|
222
|
+
|
223
|
+
@type_ = type_
|
224
|
+
@message = message
|
225
|
+
@abi = abi
|
226
|
+
@address = address
|
227
|
+
@deploy_set = deploy_set
|
228
|
+
@call_set = call_set
|
229
|
+
@signer = signer
|
230
|
+
@processing_try_index = processing_try_index
|
231
|
+
end
|
232
|
+
|
233
|
+
def to_h
|
234
|
+
h1 = {
|
235
|
+
type: Helper.sym_to_capitalized_case_str(@type_)
|
236
|
+
}
|
237
|
+
|
238
|
+
h2 = case @type_
|
239
|
+
when :encoded
|
240
|
+
{
|
241
|
+
message: @message,
|
242
|
+
abi: @abi.nil? ? nil : @abi.to_h
|
243
|
+
}
|
244
|
+
when :encoding_params
|
245
|
+
{
|
246
|
+
abi: @abi.to_h,
|
247
|
+
address: @address,
|
248
|
+
deploy_set: @deploy_set.nil? ? nil : @deploy_set.to_h,
|
249
|
+
call_set: @call_set.nil? ? nil : @call_set.to_h,
|
250
|
+
signer: @signer.to_h,
|
251
|
+
processing_try_index: @processing_try_index
|
252
|
+
}
|
253
|
+
end
|
254
|
+
|
255
|
+
h1.merge(h2)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
class ParamsOfEncodeMessageBody
|
260
|
+
attr_reader :abi, :call_set, :is_internal, :signer, :processing_try_index
|
261
|
+
|
262
|
+
def initialize(abi:, call_set:, is_internal:, signer:, processing_try_index: 0)
|
263
|
+
@abi = abi
|
264
|
+
@call_set = call_set
|
265
|
+
@is_internal = is_internal
|
266
|
+
@signer = signer
|
267
|
+
@processing_try_index = processing_try_index
|
268
|
+
end
|
269
|
+
|
270
|
+
def to_h
|
271
|
+
{
|
272
|
+
abi: @abi.to_h,
|
273
|
+
call_set: @call_set.to_h,
|
274
|
+
is_internal: @is_internal,
|
275
|
+
signer: @signer.to_h,
|
276
|
+
processing_try_index: @processing_try_index
|
277
|
+
}
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
class ResultOfEncodeMessageBody
|
282
|
+
attr_reader :body, :data_to_sign
|
283
|
+
|
284
|
+
def initialize(body:, data_to_sign: nil)
|
285
|
+
@body = body
|
286
|
+
@data_to_sign = data_to_sign
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
class ParamsOfAttachSignatureToMessageBody
|
291
|
+
attr_reader :abi, :public_key, :message, :signature
|
292
|
+
|
293
|
+
def initialize(abi:, public_key:, message:, signature:)
|
294
|
+
@abi = abi
|
295
|
+
@public_key = public_key
|
296
|
+
@message = message
|
297
|
+
@signature = signature
|
298
|
+
end
|
299
|
+
|
300
|
+
def to_h
|
301
|
+
{
|
302
|
+
abi: @abi.to_h,
|
303
|
+
public_key: @public_key,
|
304
|
+
message: @message,
|
305
|
+
signature: @signature
|
306
|
+
}
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
class ResultOfAttachSignatureToMessageBody
|
311
|
+
attr_reader :body
|
312
|
+
|
313
|
+
def initialize(a)
|
314
|
+
@body = a
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
class ParamsOfEncodeMessage
|
319
|
+
attr_reader :abi, :address, :deploy_set, :call_set, :signer, :processing_try_index
|
320
|
+
|
321
|
+
def initialize(abi:, address: nil, deploy_set: nil, call_set: nil, signer:, processing_try_index: 0)
|
322
|
+
@abi = abi
|
323
|
+
@address = address
|
324
|
+
@deploy_set = deploy_set
|
325
|
+
@call_set = call_set
|
326
|
+
@signer = signer
|
327
|
+
@processing_try_index = processing_try_index
|
328
|
+
end
|
329
|
+
|
330
|
+
def to_h
|
331
|
+
{
|
332
|
+
abi: @abi.to_h,
|
333
|
+
address: @address,
|
334
|
+
deploy_set: @deploy_set.nil? ? nil: @deploy_set.to_h,
|
335
|
+
call_set: @call_set.nil? ? nil: @call_set.to_h,
|
336
|
+
signer: @signer.to_h,
|
337
|
+
processing_try_index: @processing_try_index
|
338
|
+
}
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
class ResultOfEncodeMessage
|
343
|
+
attr_reader :message, :data_to_sign, :address, :message_id
|
344
|
+
|
345
|
+
def initialize(message:, data_to_sign: nil, address:, message_id:)
|
346
|
+
@message = message
|
347
|
+
@data_to_sign = data_to_sign
|
348
|
+
@address = address
|
349
|
+
@message_id = message_id
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
class ParamsOfAttachSignature
|
354
|
+
attr_reader :abi, :public_key, :message, :signature
|
355
|
+
|
356
|
+
def initialize(abi:, public_key:, message:, signature:)
|
357
|
+
@abi = abi
|
358
|
+
@public_key = public_key
|
359
|
+
@message = message
|
360
|
+
@signature = signature
|
361
|
+
end
|
362
|
+
|
363
|
+
def to_h
|
364
|
+
{
|
365
|
+
abi: @abi.to_h,
|
366
|
+
public_key: @public_key,
|
367
|
+
message: @message,
|
368
|
+
signature: @signature
|
369
|
+
}
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
class ResultOfAttachSignature
|
374
|
+
attr_reader :message, :message_id
|
375
|
+
|
376
|
+
def initialize(message:, message_id:)
|
377
|
+
@message = message
|
378
|
+
@message_id = message_id
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
class ParamsOfDecodeMessage
|
383
|
+
attr_reader :abi, :message
|
384
|
+
|
385
|
+
def initialize(abi:, message:)
|
386
|
+
@abi = abi
|
387
|
+
@message = message
|
388
|
+
end
|
389
|
+
|
390
|
+
def to_h
|
391
|
+
{
|
392
|
+
abi: @abi.to_h,
|
393
|
+
message: @message
|
394
|
+
}
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
class DecodedMessageBody
|
399
|
+
MESSAGE_BODY_TYPE_VALUES = [:input, :output, :internal_output, :event]
|
400
|
+
attr_reader :body_type, :name, :value, :header
|
401
|
+
|
402
|
+
def initialize(body_type:, name:, value: nil, header: nil)
|
403
|
+
unless MESSAGE_BODY_TYPE_VALUES.include?(body_type)
|
404
|
+
raise ArgumentError.new("unknown body_type: #{body_type}; known ones: #{MESSAGE_BODY_TYPE_VALUES}")
|
405
|
+
end
|
406
|
+
|
407
|
+
@body_type = body_type
|
408
|
+
@name = name
|
409
|
+
@value = value
|
410
|
+
@header = header
|
411
|
+
end
|
412
|
+
|
413
|
+
def to_h
|
414
|
+
{
|
415
|
+
body_type: Helper.sym_to_capitalized_case_str(@body_type),
|
416
|
+
name: @name,
|
417
|
+
value: @value,
|
418
|
+
header: @header
|
419
|
+
}
|
420
|
+
end
|
421
|
+
|
422
|
+
def self.from_json(j)
|
423
|
+
return nil if j.nil?
|
424
|
+
|
425
|
+
hdr = if !j["header"].nil?
|
426
|
+
FunctionHeader.new(
|
427
|
+
expire: j["header"]["expire"],
|
428
|
+
time: j["header"]["time"],
|
429
|
+
pubkey: j["header"]["pubkey"]
|
430
|
+
)
|
431
|
+
else
|
432
|
+
nil
|
433
|
+
end
|
434
|
+
|
435
|
+
self.new(
|
436
|
+
body_type: self.parse_body_type(j["body_type"]),
|
437
|
+
name: j["name"],
|
438
|
+
value: j["value"],
|
439
|
+
header: hdr
|
440
|
+
)
|
441
|
+
end
|
442
|
+
|
443
|
+
private
|
444
|
+
|
445
|
+
def self.parse_body_type(s)
|
446
|
+
case s.downcase
|
447
|
+
when 'input'
|
448
|
+
:input
|
449
|
+
when 'output'
|
450
|
+
:output
|
451
|
+
when 'internaloutput'
|
452
|
+
:internal_output
|
453
|
+
when 'event'
|
454
|
+
:event
|
455
|
+
else
|
456
|
+
raise ArgumentError.new("unknown body_type: #{s}; known ones: #{MESSAGE_BODY_TYPE_VALUES}")
|
457
|
+
end
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
class ParamsOfDecodeMessageBody
|
462
|
+
attr_reader :abi, :body, :is_internal
|
463
|
+
|
464
|
+
def initialize(abi:, body:, is_internal:)
|
465
|
+
@abi = abi
|
466
|
+
@body = body
|
467
|
+
@is_internal = is_internal
|
468
|
+
end
|
469
|
+
|
470
|
+
def to_h
|
471
|
+
{
|
472
|
+
abi: @abi.to_h,
|
473
|
+
body: @body,
|
474
|
+
is_internal: @is_internal
|
475
|
+
}
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
class ParamsOfEncodeAccount
|
480
|
+
attr_reader :state_init, :balance, :last_trans_lt, :last_paid
|
481
|
+
|
482
|
+
def initialize(state_init:, balance: nil, last_trans_lt: nil, last_paid: nil)
|
483
|
+
@state_init = state_init
|
484
|
+
@balance = balance
|
485
|
+
@last_trans_lt = last_trans_lt
|
486
|
+
@last_paid = last_paid
|
487
|
+
end
|
488
|
+
|
489
|
+
def to_h
|
490
|
+
{
|
491
|
+
state_init: @state_init.to_h,
|
492
|
+
balance: @balance,
|
493
|
+
last_trans_lt: @last_trans_lt,
|
494
|
+
last_paid: @last_paid
|
495
|
+
}
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
class ResultOfEncodeAccount
|
500
|
+
attr_reader :account, :id_
|
501
|
+
|
502
|
+
def initialize(account:, id_:)
|
503
|
+
@account = account
|
504
|
+
@id_ = id_
|
505
|
+
end
|
506
|
+
|
507
|
+
def to_h
|
508
|
+
{
|
509
|
+
account: @account,
|
510
|
+
id: @id_
|
511
|
+
}
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
class AbiParam
|
516
|
+
attr_reader :name, :type_, :components
|
517
|
+
|
518
|
+
def initialize(name:, type_:, components: [])
|
519
|
+
@name = name
|
520
|
+
@type_ = type_
|
521
|
+
@components = components
|
522
|
+
end
|
523
|
+
|
524
|
+
def to_h
|
525
|
+
cm_h_s = if !@components.nil?
|
526
|
+
@components.compact.map(&:to_h)
|
527
|
+
end
|
528
|
+
|
529
|
+
{
|
530
|
+
name: @name,
|
531
|
+
type: @type_,
|
532
|
+
components: cm_h_s
|
533
|
+
}
|
534
|
+
end
|
535
|
+
|
536
|
+
def self.from_json(j)
|
537
|
+
return nil if j.nil?
|
538
|
+
|
539
|
+
comp_s = if j["components"].nil?
|
540
|
+
[]
|
541
|
+
else
|
542
|
+
j["components"].compact.map do |x|
|
543
|
+
# TODO recursive parsing of AbiParam
|
544
|
+
self.from_json(x)
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
self.new(
|
549
|
+
name: j["name"],
|
550
|
+
type_: j["type"],
|
551
|
+
components: comp_s
|
552
|
+
)
|
553
|
+
end
|
554
|
+
end
|
555
|
+
|
556
|
+
class AbiEvent
|
557
|
+
attr_reader :name, :inputs, :id_
|
558
|
+
|
559
|
+
def initialize(name:, inputs:, id_:)
|
560
|
+
@name = name
|
561
|
+
@inputs = inputs
|
562
|
+
@id_ = id_
|
563
|
+
end
|
564
|
+
|
565
|
+
def to_h
|
566
|
+
in_h_s = if !@inputs.nil?
|
567
|
+
@inputs.compact.map(&:to_h)
|
568
|
+
else
|
569
|
+
[]
|
570
|
+
end
|
571
|
+
|
572
|
+
{
|
573
|
+
name: @name,
|
574
|
+
inputs: in_h_s,
|
575
|
+
id: @id_
|
576
|
+
}
|
577
|
+
end
|
578
|
+
|
579
|
+
def self.from_json(j)
|
580
|
+
return nil if j.nil?
|
581
|
+
|
582
|
+
inp_s = if j["inputs"].nil?
|
583
|
+
[]
|
584
|
+
else
|
585
|
+
j["inputs"].compact.map do |x|
|
586
|
+
# TODO recursive parsing of AbiParam
|
587
|
+
AbiParam.from_json(x)
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
self.new(
|
592
|
+
name: j["name"],
|
593
|
+
inputs: inp_s,
|
594
|
+
id_: j["id"],
|
595
|
+
)
|
596
|
+
end
|
597
|
+
end
|
598
|
+
|
599
|
+
class AbiData
|
600
|
+
attr_reader :key, :name, :type_, :components
|
601
|
+
|
602
|
+
def initialize(key:, name:, type_:, components: [])
|
603
|
+
@key = key
|
604
|
+
@name = name
|
605
|
+
@type_ = type_
|
606
|
+
@components = components
|
607
|
+
end
|
608
|
+
|
609
|
+
def to_h
|
610
|
+
cm_h_s = if !@components.nil?
|
611
|
+
@components.compact.map(&:to_h)
|
612
|
+
end
|
613
|
+
|
614
|
+
{
|
615
|
+
key: @key,
|
616
|
+
name: @name,
|
617
|
+
type: @type_,
|
618
|
+
components: cm_h_s
|
619
|
+
}
|
620
|
+
end
|
621
|
+
|
622
|
+
def self.from_json(j)
|
623
|
+
return nil if j.nil?
|
624
|
+
|
625
|
+
comp_s = if j["components"].nil?
|
626
|
+
[]
|
627
|
+
else
|
628
|
+
j["components"].compact.map do |x|
|
629
|
+
# TODO recursive parsing of AbiParam
|
630
|
+
AbiParam.from_json(x)
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
self.new(
|
635
|
+
key: j["key"],
|
636
|
+
name: j["name"],
|
637
|
+
type_: j["type"],
|
638
|
+
components: comp_s
|
639
|
+
)
|
640
|
+
end
|
641
|
+
end
|
642
|
+
|
643
|
+
class AbiFunction
|
644
|
+
attr_reader :name, :inputs, :outputs, :id_
|
645
|
+
|
646
|
+
def initialize(name:, inputs:, outputs:, id_: nil)
|
647
|
+
@name = name
|
648
|
+
@inputs = inputs
|
649
|
+
@outputs = outputs
|
650
|
+
@id_ = id_
|
651
|
+
end
|
652
|
+
|
653
|
+
def to_h
|
654
|
+
in_h_s = if !@inputs.nil?
|
655
|
+
@inputs.compact.map(&:to_h)
|
656
|
+
else
|
657
|
+
[]
|
658
|
+
end
|
659
|
+
|
660
|
+
ou_h_s = if !@outputs.nil?
|
661
|
+
@outputs.compact.map(&:to_h)
|
662
|
+
else
|
663
|
+
[]
|
664
|
+
end
|
665
|
+
|
666
|
+
{
|
667
|
+
name: @name,
|
668
|
+
inputs: in_h_s,
|
669
|
+
outputs: ou_h_s,
|
670
|
+
id: @id_
|
671
|
+
}
|
672
|
+
end
|
673
|
+
|
674
|
+
def self.from_json(j)
|
675
|
+
return nil if j.nil?
|
676
|
+
|
677
|
+
inp_s = if j["inputs"].nil?
|
678
|
+
[]
|
679
|
+
else
|
680
|
+
j["inputs"].compact.map do |x|
|
681
|
+
# TODO recursive parsing of AbiParam
|
682
|
+
AbiParam.from_json(x)
|
683
|
+
end
|
684
|
+
end
|
685
|
+
|
686
|
+
out_s = if j["outputs"].nil?
|
687
|
+
[]
|
688
|
+
else
|
689
|
+
j["outputs"].compact.map do |x|
|
690
|
+
# TODO recursive parsing of AbiParam
|
691
|
+
AbiParam.from_json(x)
|
692
|
+
end
|
693
|
+
end
|
694
|
+
|
695
|
+
self.new(
|
696
|
+
name: j["name"],
|
697
|
+
inputs: inp_s,
|
698
|
+
outputs: out_s,
|
699
|
+
id_: j["id"]
|
700
|
+
)
|
701
|
+
end
|
702
|
+
end
|
703
|
+
|
704
|
+
class AbiContract
|
705
|
+
attr_reader :abi_version, :header, :functions, :events, :data
|
706
|
+
|
707
|
+
def initialize(abi_version: nil, header: [], functions: [], events: [], data: [])
|
708
|
+
@abi_version = abi_version
|
709
|
+
|
710
|
+
# in case if an argument has been passed as nil,
|
711
|
+
# a default value should be used instead
|
712
|
+
|
713
|
+
@header = header || []
|
714
|
+
@functions = functions || []
|
715
|
+
@events = events || []
|
716
|
+
@data = data || []
|
717
|
+
end
|
718
|
+
|
719
|
+
def to_h
|
720
|
+
@header.compact! if !@header.nil?
|
721
|
+
|
722
|
+
fn_h_s = if !@functions.nil?
|
723
|
+
@functions.compact.map(&:to_h)
|
724
|
+
end
|
725
|
+
|
726
|
+
ev_h_s = if !@events.nil?
|
727
|
+
@events.compact.map(&:to_h)
|
728
|
+
end
|
729
|
+
|
730
|
+
dt_h_s = if !@data.nil?
|
731
|
+
@data.compact.map(&:to_h)
|
732
|
+
end
|
733
|
+
|
734
|
+
{
|
735
|
+
abi_version: @abi_version,
|
736
|
+
:"ABI version" => @abi_version, #TODO
|
737
|
+
|
738
|
+
header: @header,
|
739
|
+
functions: fn_h_s,
|
740
|
+
events: ev_h_s,
|
741
|
+
data: dt_h_s,
|
742
|
+
}
|
743
|
+
end
|
744
|
+
|
745
|
+
def self.from_json(j)
|
746
|
+
return nil if j.nil?
|
747
|
+
|
748
|
+
fn_s = if j["functions"].nil?
|
749
|
+
[]
|
750
|
+
else
|
751
|
+
j["functions"].compact.map { |x| AbiFunction.from_json(x) }
|
752
|
+
end
|
753
|
+
|
754
|
+
ev_s = if j["events"].nil?
|
755
|
+
[]
|
756
|
+
else
|
757
|
+
j["events"].compact.map { |x| AbiEvent.from_json(x) }
|
758
|
+
end
|
759
|
+
|
760
|
+
dt_s = if j["data"].nil?
|
761
|
+
[]
|
762
|
+
else
|
763
|
+
j["data"].compact.map {|x| AbiData.from_json(x) }
|
764
|
+
end
|
765
|
+
|
766
|
+
self.new(
|
767
|
+
abi_version: j["ABI version"],
|
768
|
+
header: j["header"],
|
769
|
+
functions: fn_s,
|
770
|
+
events: ev_s,
|
771
|
+
data: dt_s
|
772
|
+
)
|
773
|
+
end
|
774
|
+
end
|
775
|
+
|
776
|
+
class ParamsOfEncodeInternalMessage
|
777
|
+
attr_reader :abi, :address, :src_address, :deploy_set, :call_set, :value, :bounce, :enable_ihr
|
778
|
+
|
779
|
+
def initialize(
|
780
|
+
abi:,
|
781
|
+
address: nil,
|
782
|
+
src_address: nil,
|
783
|
+
deploy_set: nil,
|
784
|
+
call_set: nil,
|
785
|
+
value:,
|
786
|
+
bounce: nil,
|
787
|
+
enable_ihr: nil
|
788
|
+
)
|
789
|
+
@abi = abi
|
790
|
+
@address = address
|
791
|
+
@src_address = src_address
|
792
|
+
@deploy_set = deploy_set
|
793
|
+
@call_set = call_set
|
794
|
+
@value = value
|
795
|
+
@bounce = bounce
|
796
|
+
@enable_ihr = enable_ihr
|
797
|
+
end
|
798
|
+
|
799
|
+
def to_h
|
800
|
+
{
|
801
|
+
abi: @abi,
|
802
|
+
address: @address,
|
803
|
+
src_address: @src_address,
|
804
|
+
deploy_set: @deploy_set.nil? ? nil : @deploy_set.to_h,
|
805
|
+
call_set: @call_set.nil? ? nil : @call_set.to_h,
|
806
|
+
value: @value,
|
807
|
+
bounce: @bounce,
|
808
|
+
enable_ihr: @enable_ihr
|
809
|
+
}
|
810
|
+
end
|
811
|
+
end
|
812
|
+
|
813
|
+
class ResultOfEncodeInternalMessage
|
814
|
+
attr_reader :message, :address, :message_id
|
815
|
+
|
816
|
+
def initialize(message:, address:, message_id:)
|
817
|
+
@message = message
|
818
|
+
@address = address
|
819
|
+
@message_id = message_id
|
820
|
+
end
|
821
|
+
|
822
|
+
def to_h
|
823
|
+
{
|
824
|
+
message: @message,
|
825
|
+
address: @address,
|
826
|
+
message_id: @message_id
|
827
|
+
}
|
828
|
+
end
|
829
|
+
end
|
830
|
+
|
831
|
+
|
832
|
+
#
|
833
|
+
# functions
|
834
|
+
#
|
835
|
+
|
836
|
+
def self.encode_message_body(ctx, params)
|
837
|
+
pr_json = params.to_h.to_json
|
838
|
+
Interop::request_to_native_lib(ctx, "abi.encode_message_body", pr_json) do |resp|
|
839
|
+
if resp.success?
|
840
|
+
yield NativeLibResponsetResult.new(
|
841
|
+
result: ResultOfEncodeMessageBody.new(
|
842
|
+
body: resp.result["body"],
|
843
|
+
data_to_sign: resp.result["data_to_sign"])
|
844
|
+
)
|
845
|
+
else
|
846
|
+
yield resp
|
847
|
+
end
|
848
|
+
end
|
849
|
+
end
|
850
|
+
|
851
|
+
def self.attach_signature_to_message_body(ctx, params)
|
852
|
+
pr_json = params.to_h.to_json
|
853
|
+
Interop::request_to_native_lib(ctx, "abi.attach_signature_to_message_body", pr_json) do |resp|
|
854
|
+
if resp.success?
|
855
|
+
yield NativeLibResponsetResult.new(
|
856
|
+
result: ResultOfAttachSignatureToMessageBody.new(resp.result["body"])
|
857
|
+
)
|
858
|
+
else
|
859
|
+
yield resp
|
860
|
+
end
|
861
|
+
end
|
862
|
+
end
|
863
|
+
|
864
|
+
def self.encode_message(ctx, params)
|
865
|
+
pr_json = params.to_h.to_json
|
866
|
+
Interop::request_to_native_lib(ctx, "abi.encode_message", pr_json) do |resp|
|
867
|
+
if resp.success?
|
868
|
+
yield NativeLibResponsetResult.new(
|
869
|
+
result: ResultOfEncodeMessage.new(
|
870
|
+
message: resp.result["message"],
|
871
|
+
data_to_sign: resp.result["data_to_sign"],
|
872
|
+
address: resp.result["address"],
|
873
|
+
message_id: resp.result["message_id"]
|
874
|
+
)
|
875
|
+
)
|
876
|
+
else
|
877
|
+
yield resp
|
878
|
+
end
|
879
|
+
end
|
880
|
+
end
|
881
|
+
|
882
|
+
def self.attach_signature(ctx, params)
|
883
|
+
pr_json = params.to_h.to_json
|
884
|
+
Interop::request_to_native_lib(ctx, "abi.attach_signature", pr_json) do |resp|
|
885
|
+
if resp.success?
|
886
|
+
yield NativeLibResponsetResult.new(
|
887
|
+
result: ResultOfAttachSignature.new(
|
888
|
+
message: resp.result["message"],
|
889
|
+
message_id: resp.result["message_id"])
|
890
|
+
)
|
891
|
+
else
|
892
|
+
yield resp
|
893
|
+
end
|
894
|
+
end
|
895
|
+
end
|
896
|
+
|
897
|
+
def self.decode_message(ctx, params)
|
898
|
+
pr_json = params.to_h.to_json
|
899
|
+
Interop::request_to_native_lib(ctx, "abi.decode_message", pr_json) do |resp|
|
900
|
+
if resp.success?
|
901
|
+
yield NativeLibResponsetResult.new(
|
902
|
+
result: DecodedMessageBody.from_json(resp.result)
|
903
|
+
)
|
904
|
+
else
|
905
|
+
yield resp
|
906
|
+
end
|
907
|
+
end
|
908
|
+
end
|
909
|
+
|
910
|
+
def self.decode_message_body(ctx, params)
|
911
|
+
pr_json = params.to_h.to_json
|
912
|
+
Interop::request_to_native_lib(ctx, "abi.decode_message_body", pr_json) do |resp|
|
913
|
+
if resp.success?
|
914
|
+
yield NativeLibResponsetResult.new(
|
915
|
+
result: DecodedMessageBody.from_json(resp.result)
|
916
|
+
)
|
917
|
+
else
|
918
|
+
yield resp
|
919
|
+
end
|
920
|
+
end
|
921
|
+
end
|
922
|
+
|
923
|
+
def self.encode_account(ctx, params)
|
924
|
+
pr_json = params.to_h.to_json
|
925
|
+
Interop::request_to_native_lib(ctx, "abi.encode_account", pr_json) do |resp|
|
926
|
+
if resp.success?
|
927
|
+
yield NativeLibResponsetResult.new(
|
928
|
+
result: ResultOfEncodeAccount.new(
|
929
|
+
account: resp.result["account"],
|
930
|
+
id_: resp.result["id"]
|
931
|
+
)
|
932
|
+
)
|
933
|
+
else
|
934
|
+
yield resp
|
935
|
+
end
|
936
|
+
end
|
937
|
+
end
|
938
|
+
|
939
|
+
def self.encode_internal_message(ctx, params)
|
940
|
+
pr_json = params.to_h.to_json
|
941
|
+
Interop::request_to_native_lib(ctx, "abi.encode_internal_message", pr_json) do |resp|
|
942
|
+
if resp.success?
|
943
|
+
yield NativeLibResponsetResult.new(
|
944
|
+
result: ResultOfEncodeInternalMessage.new(
|
945
|
+
message: resp.result["message"],
|
946
|
+
address: resp.result["address"],
|
947
|
+
message_id: resp.result["message_id"]
|
948
|
+
)
|
949
|
+
)
|
950
|
+
else
|
951
|
+
yield resp
|
952
|
+
end
|
953
|
+
end
|
954
|
+
end
|
955
|
+
end
|
956
|
+
end
|