everscale-client-ruby 1.1.47 → 1.1.50

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ef18c6e5ec06aec7b4d2a5469980f3ba4a14d74122a72ee66f64138e08f87d8
4
- data.tar.gz: ca752bcc10ae424fdf22fc8d26809df20cf9e030078bf828fa0c814fb61e0334
3
+ metadata.gz: 7c1679c80cf853cae8d1cffde46b65563c2cddaa06c5eb5b05aabe10a3740abf
4
+ data.tar.gz: 9e9a8dfcbe28dddebc09981b6a9e13d7c3ed288807d5cd6f22469fe33ba5e13a
5
5
  SHA512:
6
- metadata.gz: a51eb6ea6dc7624e8583bac6c886a58085ac49cbb38d298a8f9dc24da84506acc89338c0d1178b93ddb3f9a605f2e296a57427c265a00cc4bedcbfb8cdda0861
7
- data.tar.gz: 2add7a7abf6a257a925bc40a4670a8579e6d89580753681811ac40458eb34ea427bc9ea51faa315f4b831a3e6ffeb18b3dcf81d4f797ebdacd92356c15f7f4aa
6
+ metadata.gz: 2a437e75114c234743d8be5295b15b62e9a3dface3ce0c7214c718b5bec0f3fb12bf01ccfdfbac5728e7d1ef270ba273455f70a40cd360fe4ef10f8fb38708ee
7
+ data.tar.gz: 7f31de976109046cb9351e8f5fa7649e6f086e065ac581cab352188bf1f254f0caf370318575dbd239bb4d40cb2ca5612ebec2e562be6287deed62281b1972bc
@@ -234,7 +234,7 @@ cd everscale-client-ruby\n
234
234
 
235
235
  private def generateClientModule(mod, modules)
236
236
  content = "module TonClient\n\n#{TAB}class #{mod.name.capitalize}\n#{TAB}#{TAB}include CommonInstanceHelpers\n\n"
237
- content << "#{TAB}#{TAB}attr_reader :context, :context_config\n"
237
+ content << "#{TAB}#{TAB}attr_reader :context, :context_config, :request_id, :requests\n"
238
238
  content << "#{TAB}#{TAB}private_accessor "
239
239
  modules.each_with_index do |m, i|
240
240
  next if m.name.downcase == 'client'
@@ -243,16 +243,24 @@ cd everscale-client-ruby\n
243
243
  content << "#{TAB}#{TAB}MODULE = self.to_s.downcase.gsub(/^(.+::|)(\\w+)$/, '\\2').freeze\n\n"
244
244
  content << "#{TAB}#{TAB}def initialize(context_config: {})\n"
245
245
  content << "#{TAB}#{TAB}#{TAB}@context_config = context_config\n"
246
+ content << "#{TAB}#{TAB}#{TAB}@request_id = Concurrent::AtomicFixnum.new(1)\n"
247
+ content << "#{TAB}#{TAB}#{TAB}@requests = Concurrent::Hash.new()\n"
246
248
  content << "#{TAB}#{TAB}#{TAB}config = TonBinding.make_string(context_config.to_json)\n"
247
249
  content << "#{TAB}#{TAB}#{TAB}context_ptr = TonBinding.tc_create_context(config)\n"
248
250
  content << "#{TAB}#{TAB}#{TAB}@context = TonBinding.read_string_to_hash(context_ptr)['result']\n"
251
+ content << "#{TAB}#{TAB}#{TAB}ObjectSpace.define_finalizer(self, self.class.finalize(@context))\n"
252
+ content << "#{TAB}#{TAB}end\n\n"
253
+ content << "#{TAB}#{TAB}def self.finalize(ctx)\n"
254
+ content << "#{TAB}#{TAB}#{TAB}Proc.new do\n"
255
+ content << "#{TAB}#{TAB}#{TAB}#{TAB}if (ctx != nil) && (ctx > 0)\n"
256
+ content << "#{TAB}#{TAB}#{TAB}#{TAB}#{TAB}TonBinding.tc_destroy_context(ctx)\n"
257
+ content << "#{TAB}#{TAB}#{TAB}#{TAB}end\n"
258
+ content << "#{TAB}#{TAB}#{TAB}end\n"
249
259
  content << "#{TAB}#{TAB}end\n\n"
250
- content << "#{TAB}#{TAB}def destroy_context\n"
251
- content << "#{TAB}#{TAB}#{TAB}TonBinding.tc_destroy_context(context)\n#{TAB}#{TAB}end\n\n"
252
260
  modules.each_with_index do |m, i|
253
261
  next if m.name.downcase == 'client'
254
262
  content << "#{TAB}#{TAB}def #{m.name}\n"
255
- content << "#{TAB}#{TAB}#{TAB}_#{m.name} ||= #{m.name.capitalize}.new(context: context)\n"
263
+ content << "#{TAB}#{TAB}#{TAB}_#{m.name} ||= #{m.name.capitalize}.new(context: context, request_id: request_id, requests: requests)\n"
256
264
  content << "#{TAB}#{TAB}end\n\n"
257
265
  end
258
266
 
@@ -268,10 +276,12 @@ cd everscale-client-ruby\n
268
276
 
269
277
  private def generateModule(mod)
270
278
  content = "module TonClient\n\n#{TAB}class #{mod.name.capitalize}\n#{TAB}#{TAB}include CommonInstanceHelpers\n\n"
271
- content << "#{TAB}#{TAB}attr_reader :context\n"
279
+ content << "#{TAB}#{TAB}attr_reader :context, :request_id, :requests\n"
272
280
  content << "#{TAB}#{TAB}MODULE = self.to_s.downcase.gsub(/^(.+::|)(\\w+)$/, '\\2').freeze\n\n"
273
- content << "#{TAB}#{TAB}def initialize(context: nil)\n"
281
+ content << "#{TAB}#{TAB}def initialize(context: nil, request_id: nil, requests: nil)\n"
274
282
  content << "#{TAB}#{TAB}#{TAB}@context = context\n"
283
+ content << "#{TAB}#{TAB}#{TAB}@request_id = request_id\n"
284
+ content << "#{TAB}#{TAB}#{TAB}@requests = requests\n"
275
285
  content << "#{TAB}#{TAB}end\n\n"
276
286
 
277
287
  mod.functions.each do |func|
@@ -289,10 +299,10 @@ cd everscale-client-ruby\n
289
299
  content << "#{TAB}#{TAB}def #{function.name}"
290
300
  if function.arguments.empty?
291
301
  content << "(&block)\n"
292
- content << "#{TAB}#{TAB}#{TAB}TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)\n"
302
+ content << "#{TAB}#{TAB}#{TAB}TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)\n"
293
303
  else
294
304
  content << "(payload, &block)\n"
295
- content << "#{TAB}#{TAB}#{TAB}TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)\n"
305
+ content << "#{TAB}#{TAB}#{TAB}TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)\n"
296
306
  end
297
307
  content << "#{TAB}#{TAB}end\n\n"
298
308
 
@@ -2,11 +2,8 @@ require 'byebug'
2
2
 
3
3
  module TonClient
4
4
  module TonBinding
5
- @@request_id = Concurrent::AtomicFixnum.new(1)
6
- @@requests = Concurrent::Hash.new()
7
-
8
5
  class Response
9
- attr_accessor :result, :error, :custom_response, :finished, :request_id, :current_response
6
+ attr_accessor :result, :error, :custom_response, :finished, :request_id, :response_type
10
7
 
11
8
  def initialize(request_id, string_data, response_type, finished)
12
9
  update(request_id, string_data, response_type, finished)
@@ -14,45 +11,36 @@ module TonClient
14
11
 
15
12
  private
16
13
  def update(request_id, string_data, response_type, finished)
14
+ if response_type == -1
15
+ @finished = true
16
+ @request_id = request_id
17
+ @response_type = response_type
18
+ @error = string_data || "Client deallocated"
19
+ return self
20
+ end
21
+
17
22
  response_hash = TonBinding.read_string_to_hash(string_data)
18
- self.finished = finished
19
- self.request_id = request_id
20
- self.current_response = response_hash
23
+ @finished = finished
24
+ @request_id = request_id
25
+ @response_type = response_type
21
26
 
22
27
  case response_type
23
28
  when 0
24
29
  # result
25
- self.result = response_hash
30
+ @result = response_hash
26
31
  when 1
27
32
  # error
28
- self.error = response_hash
33
+ @error = response_hash
29
34
  else
30
- # another
31
- if response_type >= 100
32
- self.custom_responses = response_hash
33
- end
35
+ # # another
36
+ # if response_type >= 100
37
+ @custom_response = response_hash
38
+ # end
34
39
  end
35
40
 
36
41
  self
37
42
  end
38
43
  end
39
-
40
- def self.generate_request_id
41
- @@request_id.increment()
42
- @@request_id.value
43
- end
44
-
45
- def self.get_request(id)
46
- @@requests[id]
47
- end
48
-
49
- def self.set_request(id, &request_block)
50
- @@requests[id] = request_block
51
- end
52
-
53
- def self.delete_request(id)
54
- @@requests[id] = nil
55
- end
56
44
  end
57
45
  end
58
46
 
@@ -146,14 +134,15 @@ module TonClient
146
134
  end
147
135
 
148
136
  if string[:content].address > 1
149
- string = string[:content].read_string(string[:len])
137
+ result = string[:content].read_string(string[:len])
150
138
  if is_ref
151
139
  tc_destroy_string(tc_string_handle)
152
140
  # free(tc_string_handle)
153
141
  end
154
- return string
142
+ result
143
+ else
144
+ nil
155
145
  end
156
- nil
157
146
  end
158
147
 
159
148
  def self.read_string_to_hash(tc_string_handle_t_ref)
@@ -176,21 +165,34 @@ module TonClient
176
165
  end
177
166
 
178
167
  # block = { |response| }
179
- def self.requestLibrary(context: 1, method_name: '', payload: {}, &block)
168
+ def self.requestLibrary(context: nil, request_id: nil, requests: nil, sm: nil, method_name: '', payload: {}, &block)
180
169
  raise 'context not found' unless context
181
170
  raise 'method_name is empty' if method_name.empty?
182
-
183
- request_id = generate_request_id
171
+ # raise "context: #{context}. request_id not is nil. Client dealloc." unless request_id
172
+ unless request_id
173
+ # p "context: #{context}. request_id is nil. Client deallocated."
174
+ block.call(Response.new(request_id, "Client deallocated", -1, true)) if block
175
+ return
176
+ end
184
177
  method_name_string = make_string(method_name)
185
178
  payload_string = make_string(payload.to_json)
186
- set_request(request_id, &block)
179
+
180
+ request_id = request_id.increment
181
+ requests[request_id] = block
182
+
187
183
  tc_request(context, method_name_string, payload_string, request_id) do |request_id, string_data, response_type, finished|
188
- request = get_request(request_id)
189
- if request
190
- request.call(Response.new(request_id, string_data, response_type, finished))
191
- delete_request(request_id) if finished
184
+ begin
185
+ request = requests[request_id]
186
+ if request
187
+ request.call(Response.new(request_id, string_data, response_type, finished))
188
+ requests.delete(request_id) if finished
189
+ end
190
+ rescue => ex
191
+ block.call(Response.new(request_id, ex.message, -1, true)) if block
192
192
  end
193
193
  end
194
+ rescue => ex
195
+ block.call(Response.new(request_id, ex.message, -1, true)) if block
194
196
  end
195
197
 
196
198
  end
@@ -3,11 +3,13 @@ module TonClient
3
3
  class Abi
4
4
  include CommonInstanceHelpers
5
5
 
6
- attr_reader :context
6
+ attr_reader :context, :request_id, :requests
7
7
  MODULE = self.to_s.downcase.gsub(/^(.+::|)(\w+)$/, '\2').freeze
8
8
 
9
- def initialize(context: nil)
9
+ def initialize(context: nil, request_id: nil, requests: nil)
10
10
  @context = context
11
+ @request_id = request_id
12
+ @requests = requests
11
13
  end
12
14
 
13
15
  # INPUT: ParamsOfEncodeMessageBody
@@ -26,7 +28,7 @@ module TonClient
26
28
  # data_to_sign: String<Optional> - # # Optional data to sign. # # Encoded with `base64`.
27
29
  # # Presents when `message` is unsigned. Can be used for externalmessage signing. Is this case you need to sing this data andproduce signed message using `abi.attach_signature`.
28
30
  def encode_message_body(payload, &block)
29
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
31
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
30
32
  end
31
33
 
32
34
  # INPUT: ParamsOfAttachSignatureToMessageBody
@@ -37,7 +39,7 @@ module TonClient
37
39
  # RESPONSE: ResultOfAttachSignatureToMessageBody
38
40
  # body: String -
39
41
  def attach_signature_to_message_body(payload, &block)
40
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
42
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
41
43
  end
42
44
 
43
45
  # INPUT: ParamsOfEncodeMessage
@@ -58,7 +60,7 @@ module TonClient
58
60
  # address: String - # # Destination address.
59
61
  # message_id: String - # # Message id.
60
62
  def encode_message(payload, &block)
61
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
63
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
62
64
  end
63
65
 
64
66
  # INPUT: ParamsOfEncodeInternalMessage
@@ -76,7 +78,7 @@ module TonClient
76
78
  # address: String - # # Destination address.
77
79
  # message_id: String - # # Message id.
78
80
  def encode_internal_message(payload, &block)
79
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
81
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
80
82
  end
81
83
 
82
84
  # INPUT: ParamsOfAttachSignature
@@ -88,7 +90,7 @@ module TonClient
88
90
  # message: String - # # Signed message BOC
89
91
  # message_id: String - # # Message ID
90
92
  def attach_signature(payload, &block)
91
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
93
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
92
94
  end
93
95
 
94
96
  # INPUT: ParamsOfDecodeMessage
@@ -101,7 +103,7 @@ module TonClient
101
103
  # value: Value<Optional> - # # Parameters or result value.
102
104
  # header: FunctionHeader<Optional> - # # Function header.
103
105
  def decode_message(payload, &block)
104
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
106
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
105
107
  end
106
108
 
107
109
  # INPUT: ParamsOfDecodeMessageBody
@@ -115,7 +117,7 @@ module TonClient
115
117
  # value: Value<Optional> - # # Parameters or result value.
116
118
  # header: FunctionHeader<Optional> - # # Function header.
117
119
  def decode_message_body(payload, &block)
118
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
120
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
119
121
  end
120
122
 
121
123
  # INPUT: ParamsOfEncodeAccount
@@ -128,7 +130,7 @@ module TonClient
128
130
  # account: String - # # Account BOC encoded in `base64`.
129
131
  # id: String - # # Account ID encoded in `hex`.
130
132
  def encode_account(payload, &block)
131
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
133
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
132
134
  end
133
135
 
134
136
  # INPUT: ParamsOfDecodeAccountData
@@ -138,7 +140,7 @@ module TonClient
138
140
  # RESPONSE: ResultOfDecodeAccountData
139
141
  # data: Value - # # Decoded data as a JSON structure.
140
142
  def decode_account_data(payload, &block)
141
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
143
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
142
144
  end
143
145
 
144
146
  # INPUT: ParamsOfUpdateInitialData
@@ -150,7 +152,7 @@ module TonClient
150
152
  # RESPONSE: ResultOfUpdateInitialData
151
153
  # data: String - # # Updated data BOC or BOC handle
152
154
  def update_initial_data(payload, &block)
153
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
155
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
154
156
  end
155
157
 
156
158
  # INPUT: ParamsOfEncodeInitialData
@@ -161,7 +163,7 @@ module TonClient
161
163
  # RESPONSE: ResultOfEncodeInitialData
162
164
  # data: String - # # Updated data BOC or BOC handle
163
165
  def encode_initial_data(payload, &block)
164
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
166
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
165
167
  end
166
168
 
167
169
  # INPUT: ParamsOfDecodeInitialData
@@ -172,7 +174,7 @@ module TonClient
172
174
  # initial_data: Value<Optional> - # # List of initial values of contract's public variables. # # Initial data is decoded if `abi` input parameter is provided
173
175
  # initial_pubkey: String - # # Initial account owner's public key
174
176
  def decode_initial_data(payload, &block)
175
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
177
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
176
178
  end
177
179
 
178
180
  # INPUT: ParamsOfDecodeBoc
@@ -182,7 +184,7 @@ module TonClient
182
184
  # RESPONSE: ResultOfDecodeBoc
183
185
  # data: Value - # # Decoded data as a JSON structure.
184
186
  def decode_boc(payload, &block)
185
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
187
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
186
188
  end
187
189
 
188
190
  # INPUT: ParamsOfAbiEncodeBoc
@@ -192,7 +194,7 @@ module TonClient
192
194
  # RESPONSE: ResultOfAbiEncodeBoc
193
195
  # boc: String - # # BOC encoded as base64
194
196
  def encode_boc(payload, &block)
195
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
197
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
196
198
  end
197
199
 
198
200
  # INPUT: ParamsOfCalcFunctionId
@@ -202,7 +204,7 @@ module TonClient
202
204
  # RESPONSE: ResultOfCalcFunctionId
203
205
  # function_id: Number - # # Contract function ID
204
206
  def calc_function_id(payload, &block)
205
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
207
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
206
208
  end
207
209
 
208
210
  end
@@ -3,11 +3,13 @@ module TonClient
3
3
  class Boc
4
4
  include CommonInstanceHelpers
5
5
 
6
- attr_reader :context
6
+ attr_reader :context, :request_id, :requests
7
7
  MODULE = self.to_s.downcase.gsub(/^(.+::|)(\w+)$/, '\2').freeze
8
8
 
9
- def initialize(context: nil)
9
+ def initialize(context: nil, request_id: nil, requests: nil)
10
10
  @context = context
11
+ @request_id = request_id
12
+ @requests = requests
11
13
  end
12
14
 
13
15
  # INPUT: ParamsOfParse
@@ -15,7 +17,7 @@ module TonClient
15
17
  # RESPONSE: ResultOfParse
16
18
  # parsed: Value - # # JSON containing parsed BOC
17
19
  def parse_message(payload, &block)
18
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
20
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
19
21
  end
20
22
 
21
23
  # INPUT: ParamsOfParse
@@ -23,7 +25,7 @@ module TonClient
23
25
  # RESPONSE: ResultOfParse
24
26
  # parsed: Value - # # JSON containing parsed BOC
25
27
  def parse_transaction(payload, &block)
26
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
28
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
27
29
  end
28
30
 
29
31
  # INPUT: ParamsOfParse
@@ -31,7 +33,7 @@ module TonClient
31
33
  # RESPONSE: ResultOfParse
32
34
  # parsed: Value - # # JSON containing parsed BOC
33
35
  def parse_account(payload, &block)
34
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
36
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
35
37
  end
36
38
 
37
39
  # INPUT: ParamsOfParse
@@ -39,7 +41,7 @@ module TonClient
39
41
  # RESPONSE: ResultOfParse
40
42
  # parsed: Value - # # JSON containing parsed BOC
41
43
  def parse_block(payload, &block)
42
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
44
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
43
45
  end
44
46
 
45
47
  # INPUT: ParamsOfParseShardstate
@@ -49,7 +51,7 @@ module TonClient
49
51
  # RESPONSE: ResultOfParse
50
52
  # parsed: Value - # # JSON containing parsed BOC
51
53
  def parse_shardstate(payload, &block)
52
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
54
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
53
55
  end
54
56
 
55
57
  # INPUT: ParamsOfGetBlockchainConfig
@@ -57,7 +59,7 @@ module TonClient
57
59
  # RESPONSE: ResultOfGetBlockchainConfig
58
60
  # config_boc: String - # # Blockchain config BOC encoded as base64
59
61
  def get_blockchain_config(payload, &block)
60
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
62
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
61
63
  end
62
64
 
63
65
  # INPUT: ParamsOfGetBocHash
@@ -65,7 +67,7 @@ module TonClient
65
67
  # RESPONSE: ResultOfGetBocHash
66
68
  # hash: String - # # BOC root hash encoded with hex
67
69
  def get_boc_hash(payload, &block)
68
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
70
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
69
71
  end
70
72
 
71
73
  # INPUT: ParamsOfGetBocDepth
@@ -73,7 +75,7 @@ module TonClient
73
75
  # RESPONSE: ResultOfGetBocDepth
74
76
  # depth: Number - # # BOC root cell depth
75
77
  def get_boc_depth(payload, &block)
76
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
78
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
77
79
  end
78
80
 
79
81
  # INPUT: ParamsOfGetCodeFromTvc
@@ -81,7 +83,7 @@ module TonClient
81
83
  # RESPONSE: ResultOfGetCodeFromTvc
82
84
  # code: String - # # Contract code encoded as base64
83
85
  def get_code_from_tvc(payload, &block)
84
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
86
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
85
87
  end
86
88
 
87
89
  # INPUT: ParamsOfBocCacheGet
@@ -89,7 +91,7 @@ module TonClient
89
91
  # RESPONSE: ResultOfBocCacheGet
90
92
  # boc: String<Optional> - # # BOC encoded as base64.
91
93
  def cache_get(payload, &block)
92
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
94
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
93
95
  end
94
96
 
95
97
  # INPUT: ParamsOfBocCacheSet
@@ -98,14 +100,14 @@ module TonClient
98
100
  # RESPONSE: ResultOfBocCacheSet
99
101
  # boc_ref: String - # # Reference to the cached BOC
100
102
  def cache_set(payload, &block)
101
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
103
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
102
104
  end
103
105
 
104
106
  # INPUT: ParamsOfBocCacheUnpin
105
107
  # pin: String - # # Pinned name
106
108
  # boc_ref: String<Optional> - # # Reference to the cached BOC. # # If it is provided then only referenced BOC is unpinned
107
109
  def cache_unpin(payload, &block)
108
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
110
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
109
111
  end
110
112
 
111
113
  # INPUT: ParamsOfEncodeBoc
@@ -114,7 +116,7 @@ module TonClient
114
116
  # RESPONSE: ResultOfEncodeBoc
115
117
  # boc: String - # # Encoded cell BOC or BOC cache key.
116
118
  def encode_boc(payload, &block)
117
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
119
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
118
120
  end
119
121
 
120
122
  # INPUT: ParamsOfGetCodeSalt
@@ -123,7 +125,7 @@ module TonClient
123
125
  # RESPONSE: ResultOfGetCodeSalt
124
126
  # salt: String<Optional> - # # Contract code salt if present. # # BOC encoded as base64 or BOC handle
125
127
  def get_code_salt(payload, &block)
126
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
128
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
127
129
  end
128
130
 
129
131
  # INPUT: ParamsOfSetCodeSalt
@@ -133,7 +135,7 @@ module TonClient
133
135
  # RESPONSE: ResultOfSetCodeSalt
134
136
  # code: String - # # Contract code with salt set. # # BOC encoded as base64 or BOC handle
135
137
  def set_code_salt(payload, &block)
136
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
138
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
137
139
  end
138
140
 
139
141
  # INPUT: ParamsOfDecodeTvc
@@ -152,7 +154,7 @@ module TonClient
152
154
  # split_depth: Number<Optional> - # # Is present and non-zero only in instances of large smart contracts
153
155
  # compiler_version: String<Optional> - # # Compiler version, for example 'sol 0.49.0'
154
156
  def decode_tvc(payload, &block)
155
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
157
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
156
158
  end
157
159
 
158
160
  # INPUT: ParamsOfEncodeTvc
@@ -166,7 +168,7 @@ module TonClient
166
168
  # RESPONSE: ResultOfEncodeTvc
167
169
  # tvc: String - # # Contract TVC image BOC encoded as base64 or BOC handle of boc_cache parameter was specified
168
170
  def encode_tvc(payload, &block)
169
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
171
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
170
172
  end
171
173
 
172
174
  # INPUT: ParamsOfEncodeExternalInMessage
@@ -179,7 +181,7 @@ module TonClient
179
181
  # message: String - # # Message BOC encoded with `base64`.
180
182
  # message_id: String - # # Message id.
181
183
  def encode_external_in_message(payload, &block)
182
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
184
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
183
185
  end
184
186
 
185
187
  # INPUT: ParamsOfGetCompilerVersion
@@ -187,7 +189,7 @@ module TonClient
187
189
  # RESPONSE: ResultOfGetCompilerVersion
188
190
  # version: String<Optional> - # # Compiler version, for example 'sol 0.49.0'
189
191
  def get_compiler_version(payload, &block)
190
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
192
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
191
193
  end
192
194
 
193
195
  end
@@ -3,67 +3,74 @@ module TonClient
3
3
  class Client
4
4
  include CommonInstanceHelpers
5
5
 
6
- attr_reader :context, :context_config
6
+ attr_reader :context, :context_config, :request_id, :requests
7
7
  private_accessor :_crypto, :_abi, :_boc, :_processing, :_utils, :_tvm, :_net, :_debot, :_proofs
8
8
  MODULE = self.to_s.downcase.gsub(/^(.+::|)(\w+)$/, '\2').freeze
9
9
 
10
10
  def initialize(context_config: {})
11
11
  @context_config = context_config
12
+ @request_id = Concurrent::AtomicFixnum.new(1)
13
+ @requests = Concurrent::Hash.new()
12
14
  config = TonBinding.make_string(context_config.to_json)
13
15
  context_ptr = TonBinding.tc_create_context(config)
14
16
  @context = TonBinding.read_string_to_hash(context_ptr)['result']
17
+ ObjectSpace.define_finalizer(self, self.class.finalize(@context))
15
18
  end
16
19
 
17
- def destroy_context
18
- TonBinding.tc_destroy_context(context)
20
+ def self.finalize(ctx)
21
+ Proc.new do
22
+ if (ctx != nil) && (ctx > 0)
23
+ TonBinding.tc_destroy_context(ctx)
24
+ end
25
+ end
19
26
  end
20
27
 
21
28
  def crypto
22
- _crypto ||= Crypto.new(context: context)
29
+ _crypto ||= Crypto.new(context: context, request_id: request_id, requests: requests)
23
30
  end
24
31
 
25
32
  def abi
26
- _abi ||= Abi.new(context: context)
33
+ _abi ||= Abi.new(context: context, request_id: request_id, requests: requests)
27
34
  end
28
35
 
29
36
  def boc
30
- _boc ||= Boc.new(context: context)
37
+ _boc ||= Boc.new(context: context, request_id: request_id, requests: requests)
31
38
  end
32
39
 
33
40
  def processing
34
- _processing ||= Processing.new(context: context)
41
+ _processing ||= Processing.new(context: context, request_id: request_id, requests: requests)
35
42
  end
36
43
 
37
44
  def utils
38
- _utils ||= Utils.new(context: context)
45
+ _utils ||= Utils.new(context: context, request_id: request_id, requests: requests)
39
46
  end
40
47
 
41
48
  def tvm
42
- _tvm ||= Tvm.new(context: context)
49
+ _tvm ||= Tvm.new(context: context, request_id: request_id, requests: requests)
43
50
  end
44
51
 
45
52
  def net
46
- _net ||= Net.new(context: context)
53
+ _net ||= Net.new(context: context, request_id: request_id, requests: requests)
47
54
  end
48
55
 
49
56
  def debot
50
- _debot ||= Debot.new(context: context)
57
+ _debot ||= Debot.new(context: context, request_id: request_id, requests: requests)
51
58
  end
52
59
 
53
60
  def proofs
54
- _proofs ||= Proofs.new(context: context)
61
+ _proofs ||= Proofs.new(context: context, request_id: request_id, requests: requests)
55
62
  end
56
63
 
57
64
  # RESPONSE: ResultOfGetApiReference
58
65
  # api: Value -
59
66
  def get_api_reference(&block)
60
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)
67
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)
61
68
  end
62
69
 
63
70
  # RESPONSE: ResultOfVersion
64
71
  # version: String - # # Core Library version
65
72
  def version(&block)
66
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)
73
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)
67
74
  end
68
75
 
69
76
  # RESPONSE: ClientConfig
@@ -74,21 +81,21 @@ module TonClient
74
81
  # proofs: ProofsConfig<Optional> -
75
82
  # local_storage_path: String<Optional> - # # For file based storage is a folder name where SDK will store its data. For browser based is a browser async storage key prefix. Default (recommended) value is "~/.tonclient" for native environments and ".tonclient" for web-browser.
76
83
  def config(&block)
77
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)
84
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)
78
85
  end
79
86
 
80
87
  # RESPONSE: ResultOfBuildInfo
81
88
  # build_number: Number - # # Build number assigned to this build by the CI.
82
89
  # dependencies: Array - # # Fingerprint of the most important dependencies.
83
90
  def build_info(&block)
84
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)
91
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: {}, &block)
85
92
  end
86
93
 
87
94
  # INPUT: ParamsOfResolveAppRequest
88
95
  # app_request_id: Number - # # Request ID received from SDK
89
96
  # result: AppRequestResult - # # Result of request processing
90
97
  def resolve_app_request(payload, &block)
91
- TonBinding.requestLibrary(context: context, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
98
+ TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, method_name: full_method_name(MODULE, __method__.to_s), payload: payload, &block)
92
99
  end
93
100
 
94
101
  end