Module: MixinBot::Monitor

Defined in:
lib/mixin_bot/monitor.rb

Overview

Monitoring helpers (parity with Go monitor package).

Defined Under Namespace

Classes: AppMessage

Class Method Summary collapse

Class Method Details

.check_retryable_error(error) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mixin_bot/monitor.rb', line 63

def check_retryable_error(error)
  return false if error.nil?

  reason = error.message.to_s.downcase
  return true if reason.include?('timeout')
  return true if reason.include?('internal server')
  return true if reason.include?('insufficient')
  return true if reason.include?('inputs locked by')
  return true if reason.include?('by other transaction')

  false
end

.report_to_monitor(api, asset:, amount:, receivers:, threshold:, message:, trace: nil, **transfer_opts) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mixin_bot/monitor.rb', line 40

def report_to_monitor(api, asset:, amount:, receivers:, threshold:, message:, trace: nil, **transfer_opts)
  memo = message.is_a?(AppMessage) ? message.marshal : message.to_s
  mix = MixinBot::MixAddress.from_members(members: receivers, threshold:)
  trace ||= MixinBot.utils.unique_object_id(mix.address, asset, amount, api.config.app_id, memo,
                                            (Time.now.to_i / 60).to_s)
  existing = begin
    api.safe_transaction(trace)
  rescue StandardError
    nil
  end
  return existing if existing.present? && existing['data'].present?

  api.create_safe_transfer(
    members: receivers,
    threshold:,
    asset_id: asset,
    amount:,
    trace_id: trace,
    memo:,
    **transfer_opts
  )
end

.unmarshal_app_message(bytes) ⇒ Object



36
37
38
# File 'lib/mixin_bot/monitor.rb', line 36

def unmarshal_app_message(bytes)
  AppMessage.load(bytes)
end