module TonSdk::Interop
Constants
- DEFAULT_LIB_NAME
Attributes
logger[R]
Public Class Methods
request_to_native_lib( ctx, function_name, function_params = nil, client_callback: nil, is_single_thread_only: true ) { |native_lib_responset_result(result: tc_data_json_content)| ... }
click to toggle source
# File lib/ton_sdk_client/interop.rb, line 132 def self.request_to_native_lib( ctx, function_name, function_params = nil, client_callback: nil, is_single_thread_only: true ) function_name_tc_str = TcStringData.from_string(function_name) function_params_json_str = function_params&.to_h.to_json || "" function_params_json_tc_str = TcStringData.from_string(function_params_json_str) @sm = Concurrent::Semaphore.new(1) if is_single_thread_only == true @sm.acquire() end # using @@request_counter here to pass a @@request_counter and handlers and then retrieve them # is probably isn't needed. # Thanks to the way Ruby is, the same affect can be achived by a block which is an easier way. # Nonetheless, @@request_counter is incremented with each request and then sent out to a server # in order to keep a server happy, # because otherwise a server will, probably, reply in a wrong way. self.tc_request( ctx, function_name_tc_str, function_params_json_tc_str, @@request_counter.value ) do |req_id, params_json, response_type, is_finished| tc_data_json_content = if params_json[:len] > 0 res = params_json[:content].read_string(params_json[:len]) JSON.parse(res) else '' end begin case response_type when TcResponseCodes::SUCCESS if block_given? yield NativeLibResponsetResult.new(result: tc_data_json_content) end when TcResponseCodes::ERROR if block_given? yield NativeLibResponsetResult.new(error: tc_data_json_content) end when TcResponseCodes::NOP nil when TcResponseCodes::APP_REQUEST if !client_callback.nil? client_callback.call(:request, tc_data_json_content) end when TcResponseCodes::APP_NOTIFY if !client_callback.nil? client_callback.call(:notify, tc_data_json_content) end when TcResponseCodes::CUSTOM..TcResponseCodes::MAX if !client_callback.nil? client_callback.call(:custom, tc_data_json_content) end else raise ArgumentError.new("unsupported response type: #{response_type}") end rescue => e @logger.error(e) ensure if is_single_thread_only == true @sm.release() end end end if is_single_thread_only == true @sm.acquire() end @@request_counter.increment() nil end
request_to_native_lib_sync(ctx, function_name, function_params_json)
click to toggle source
# File lib/ton_sdk_client/interop.rb, line 224 def self.request_to_native_lib_sync(ctx, function_name, function_params_json) function_name_tc_str = TcStringData.from_string(function_name) function_params_json_tc_str = TcStringData.from_string(function_params_json) self.tc_request_sync(ctx, function_name_tc_str, function_params_json_tc_str) end