Skip to content

Commit cbbbeef

Browse files
committed
version 1.1.60
1 parent 50e7d89 commit cbbbeef

File tree

18 files changed

+994
-43
lines changed

18 files changed

+994
-43
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Ruby Client for Free TON SDK
33

44
[![GEM](https://img.shields.io/badge/ruby-gem-orange)](https://rubygems.org/gems/everscale-client-ruby)
5-
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.37.2-green)](https://github.com/tonlabs/TON-SDK)
5+
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.38.0-green)](https://github.com/tonlabs/TON-SDK)
66

77
## Install
88

@@ -172,12 +172,12 @@ end
172172

173173

174174
- #### NetworkConfig
175-
**This field is deprecated, but left for backward-compatibility.** DApp Server public address.
175+
**This field is deprecated, but left for backward-compatibility.** Evernode endpoint.
176176
- server_address: String<Optional>
177177

178-
List of DApp Server addresses.
178+
List of Evernode endpoints.
179179
Any correct URL format can be specified, including IP addresses. This parameter is prevailing over `server_address`.
180-
Check the full list of [supported network endpoints](../ton-os-api/networks.md).
180+
Check the full list of [supported network endpoints](https://docs.everos.dev/ever-sdk/reference/ever-os-api/networks).
181181
- endpoints: Array<Optional>
182182

183183
Deprecated.
@@ -242,9 +242,7 @@ end
242242
Must be specified in milliseconds. Default is 5000 (5 sec).
243243
- next_remp_status_timeout: Number<Optional>
244244

245-
Access key to GraphQL API.
246-
You can specify here Basic Auth secret (Evercloud project secret) in hex stringor serialized JWT in base64 string.
247-
Will be passed on as Authorization: Basic ... or Authorization: Bearer ... header.
245+
Access key to GraphQL API (Project secret)
248246
- access_key: String<Optional>
249247

250248

@@ -2546,6 +2544,8 @@ end
25462544

25472545
- case NetworkModuleResumed = 614
25482546

2547+
- case Unauthorized = 615
2548+
25492549

25502550
- #### SortDirection
25512551
- case ASC =

lib/code_generator/code_generator.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def customTypes
248248
content << "#{TAB}#{TAB}#{TAB}@monitor = Monitor.new\n"
249249
content << "#{TAB}#{TAB}#{TAB}config = TonBinding.make_string(context_config.to_json)\n"
250250
content << "#{TAB}#{TAB}#{TAB}context_ptr = TonBinding.tc_create_context(config)\n"
251-
content << "#{TAB}#{TAB}#{TAB}@context = TonBinding.read_string_to_hash(context_ptr)['result']\n"
251+
content << "#{TAB}#{TAB}#{TAB}context_response = TonBinding.read_string_data_ref(context_ptr)\n"
252+
content << "#{TAB}#{TAB}#{TAB}@context = TonBinding.read_string_to_hash(context_response)['result']\n"
252253
content << "#{TAB}#{TAB}#{TAB}ObjectSpace.define_finalizer(self, self.class.finalize(@context))\n"
253254
content << "#{TAB}#{TAB}end\n\n"
254255
content << "#{TAB}#{TAB}def self.finalize(ctx)\n"
@@ -298,6 +299,7 @@ def customTypes
298299

299300
private def gen_function(function, types)
300301
content = getFunctionComment(function, types)
302+
content << "#{TAB}#{TAB}# Async\n"
301303
content << "#{TAB}#{TAB}def #{function.name}"
302304
if function.arguments.empty?
303305
content << "(&block)\n"
@@ -309,6 +311,18 @@ def customTypes
309311
content << "#{TAB}#{TAB}#{TAB}TonBinding.requestLibrary(context: context, request_id: request_id, requests: requests, monitor: monitor, method_name: full_method_name(MODULE, __method__.to_s), payload: #{payload}, &block)\n"
310312
content << "#{TAB}#{TAB}end\n\n"
311313

314+
content << "#{TAB}#{TAB}# Sync\n"
315+
content << "#{TAB}#{TAB}def #{function.name}_sync"
316+
if function.arguments.empty?
317+
content << "()\n"
318+
payload = "{}"
319+
else
320+
content << "(payload)\n"
321+
payload = "payload"
322+
end
323+
content << "#{TAB}#{TAB}#{TAB}TonBinding.send_request_sync(context: context, method_name: full_method_name(MODULE, __method__.to_s).sub(/_sync$/, ''), payload: #{payload})\n"
324+
content << "#{TAB}#{TAB}end\n\n"
325+
312326
content
313327
end
314328

lib/everscale-client-ruby/Binding/binding.rb

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def update(request_id, string_data, response_type, finished)
1818
return self
1919
end
2020

21-
response_hash = TonBinding.read_string_to_hash(string_data)
21+
response_hash = TonBinding.read_string_to_hash(TonBinding.read_string_data(string_data))
2222
@finished = finished
2323
@request_id = request_id
2424
@response_type = response_type
@@ -48,15 +48,15 @@ module TonClient
4848

4949
module TonBinding
5050
extend FFI::Library
51-
# ffi_lib FFI::Library::LIBC
52-
# ffi_lib 'ruby'
51+
ffi_lib FFI::Library::LIBC
52+
ffi_lib 'ruby'
5353

5454
# memory allocators
55-
# attach_function :malloc, [:size_t], :pointer
55+
attach_function :malloc, [:size_t], :pointer
5656
# attach_function :calloc, [:size_t], :pointer
5757
# attach_function :valloc, [:size_t], :pointer
5858
# attach_function :realloc, [:pointer, :size_t], :pointer
59-
# attach_function :free, [:pointer], :void
59+
attach_function :free, [:pointer], :void
6060

6161
# # memory movers
6262
# attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
@@ -65,7 +65,7 @@ module TonBinding
6565
def self.setup_bindings
6666

6767
# tc_string_handle_t* tc_create_context(tc_string_data_t config);
68-
# attach_function :tc_create_context, [TcStringDataT.by_value], TcStringHandleT.by_ref
68+
# attach_function :tc_create_context, [TcStringDataT.by_value], TcStringDataT.by_ref
6969
attach_function :tc_create_context, [TcStringDataT.by_value], :pointer
7070

7171
# fn tc_destroy_context(context: InteropContext)
@@ -75,7 +75,7 @@ def self.setup_bindings
7575
# uint32_t context,
7676
# tc_string_data_t function_name,
7777
# tc_string_data_t function_params_json);
78-
# attach_function :tc_request_sync, [:uint32, TcStringDataT.by_value, TcStringDataT.by_value], TcStringHandleT.by_ref
78+
# attach_function :tc_request_sync, [:uint32, TcStringDataT.by_value, TcStringDataT.by_value], TcStringDataT.by_ref
7979
attach_function :tc_request_sync, [:uint32, TcStringDataT.by_value, TcStringDataT.by_value], :pointer
8080

8181
# enum tc_response_types_t {
@@ -100,43 +100,50 @@ def self.setup_bindings
100100
attach_function :tc_request, [:uint32, TcStringDataT.by_value, TcStringDataT.by_value, :uint32, :tc_response_handler_t], :void
101101

102102
# tc_string_data_t tc_read_string(const tc_string_handle_t* handle);
103-
# attach_function :tc_read_string, [TcStringHandleT.by_ref], TcStringDataT.by_value
103+
# attach_function :tc_read_string, [TcStringDataT.by_ref], TcStringDataT.by_value
104104
attach_function :tc_read_string, [:pointer], TcStringDataT.by_value
105105

106106
# void tc_destroy_string(const tc_string_handle_t* handle)
107-
# attach_function :tc_destroy_string, [TcStringHandleT.by_ref], :void
107+
# attach_function :tc_destroy_string, [TcStringDataT.by_ref], :void
108108
attach_function :tc_destroy_string, [:pointer], :void
109109
end
110110

111111
def self.make_string(string)
112+
string = string.encode("utf-8").freeze
112113
result = TonBinding::TcStringDataT.new
113114
result[:content] = FFI::MemoryPointer.from_string(string)
114115
result[:len] = string.bytesize
115116
result
116117
end
117118

118-
def self.read_string(tc_string_handle)
119-
is_ref = tc_string_handle.class == FFI::Pointer
120-
if is_ref
121-
string = tc_read_string(tc_string_handle)
122-
else
123-
string = tc_string_handle
124-
end
119+
def self.read_string_data_ref(tc_string_handle_ref)
120+
string = tc_read_string(tc_string_handle_ref)
125121

126122
if string[:len] > 0
127-
result = string[:content].read_string(string[:len])
128-
if is_ref
129-
tc_destroy_string(tc_string_handle)
130-
# free(tc_string_handle)
123+
result = string[:content].read_string(string[:len]).freeze
124+
if tc_string_handle_ref
125+
tc_destroy_string(tc_string_handle_ref)
126+
else
127+
p "NOOOOOOOOOOOO"
131128
end
129+
# free(tc_string_handle_ref)
130+
result
131+
else
132+
nil
133+
end
134+
end
135+
136+
def self.read_string_data(tc_string_data)
137+
if tc_string_data[:len] > 0
138+
result = tc_string_data[:content].read_string(tc_string_data[:len]).freeze
139+
# free(tc_string_data)
132140
result
133141
else
134142
nil
135143
end
136144
end
137145

138-
def self.read_string_to_hash(tc_string_handle_t_ref)
139-
json_string = read_string(tc_string_handle_t_ref)
146+
def self.read_string_to_hash(json_string)
140147
JSON.parse(json_string, {max_nesting: false}) if json_string
141148
end
142149

@@ -148,10 +155,9 @@ def self.send_request_sync(context: 1, method_name: '', payload: {})
148155
payload_string = make_string(payload.to_json)
149156

150157
sdk_json_response = tc_request_sync(context, method_name_string, payload_string)
151-
response = read_string_to_hash(sdk_json_response)
152-
153-
return response['result'] if response['result']
154-
return response['error'] if response['error']
158+
response = read_string_to_hash(read_string_data_ref(sdk_json_response))
159+
160+
response
155161
end
156162

157163
# block = { |response| }

lib/everscale-client-ruby/Binding/struct.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ module TonBinding
88
class TcStringDataT < FFI::Struct
99
layout :content, :pointer,
1010
:len, :uint32
11+
12+
# def initialize(*args)
13+
# super
14+
# ObjectSpace.define_finalizer(self, self.class.finalize(@content))
15+
# end
16+
#
17+
# def self.finalize(ctx)
18+
# Proc.new do
19+
# if ctx != nil
20+
# TonBinding.free(ctx)
21+
# end
22+
# end
23+
# end
1124
end
1225
end
1326
end

0 commit comments

Comments
 (0)