Module: EverSdk::Processing

Defined in:
lib/ever_sdk_client/processing.rb

Defined Under Namespace

Modules: ErrorCode Classes: ParamsOfSendMessage, ParamsOfWaitForTransaction, ProcessingEvent, ResultOfProcessMessage

Constant Summary collapse

ResultOfSendMessage =
KwStruct.new(:shard_block_id)
DecodedOutput =
KwStruct.new(:out_messages, :output) do
  def initialize(out_messages:, output: nil)
    super
  end
end
ParamsOfProcessMessage =
KwStruct.new(:message_encode_params, :send_events) do
  def initialize(message_encode_params:, send_events:)
    super
  end

  def to_h
    {
      message_encode_params: message_encode_params.to_h,
      send_events: send_events
    }
  end
end

Class Method Summary collapse

Class Method Details

.process_message(ctx, params, client_callback = nil) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/ever_sdk_client/processing.rb', line 238

def self.process_message(ctx, params, client_callback = nil)
  if (params.send_events == true) && client_callback.nil?
    raise ArgumentError.new("with `send_events` set to true `client_callback` may not be nil")
  end

  Interop::request_to_native_lib(
    ctx,
    "processing.process_message",
    params,
    client_callback: client_callback,
    is_single_thread_only: false
  ) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfProcessMessage.new(
          transaction: resp.result["transaction"],
          out_messages: resp.result["out_messages"],
          decoded: DecodedOutput.new(
            out_messages: resp.result.dig("decoded", "out_messages"),
            output: resp.result.dig("decoded", "output")
          ),
          fees: Tvm::TransactionFees.new(**resp.result["fees"].transform_keys(&:to_sym))
        )
      )
    else
      yield resp
    end
  end
end

.send_message(ctx, params, client_callback = nil) ⇒ Object

functions



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/ever_sdk_client/processing.rb', line 186

def self.send_message(ctx, params, client_callback = nil)
  if (params.send_events == true) && client_callback.nil?
    raise ArgumentError.new("with `send_events` set to true, `client_callback` may not be nil")
  end

  Interop::request_to_native_lib(
    ctx,
    "processing.send_message",
    params,
    client_callback: client_callback,
    is_single_thread_only: false
  ) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfSendMessage.new(shard_block_id: resp.result["shard_block_id"])
      )
    else
      yield resp
    end
  end
end

.wait_for_transaction(ctx, params, client_callback = nil) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/ever_sdk_client/processing.rb', line 208

def self.wait_for_transaction(ctx, params, client_callback = nil)
  if (params.send_events == true) && client_callback.nil?
    raise ArgumentError.new("with `send_events` set to true, `client_callback` may not be nil")
  end

  Interop::request_to_native_lib(
    ctx,
    "processing.wait_for_transaction",
    params,
    client_callback: client_callback,
    is_single_thread_only: false
  ) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: ResultOfProcessMessage.new(
          transaction: resp.result["transaction"],
          out_messages: resp.result["out_messages"],
          decoded: DecodedOutput.new(
            out_messages: resp.result.dig("decoded", "out_messages"),
            output: resp.result.dig("decoded", "output")
          ),
          fees: Tvm::TransactionFees.new(**resp.result["fees"].transform_keys(&:to_sym))
        )
      )
    else
      yield resp
    end
  end
end