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