Class: EverSdk::Processing::ProcessingEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/ever_sdk_client/processing.rb

Constant Summary collapse

TYPES =
%i[
  will_fetch_first_block
  fetch_first_block_failed
  will_send
  did_send
  send_failed
  will_fetch_next_block
  fetch_next_block_failed
  message_expired
  remp_sent_to_validators
  remp_included_into_block
  remp_included_into_accepted_block
  remp_other
  remp_error
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_:, error: nil, shard_block_id: nil, message_id: nil, message: nil, **args) ⇒ ProcessingEvent

Returns a new instance of ProcessingEvent.



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ever_sdk_client/processing.rb', line 105

def initialize(type_:, error: nil, shard_block_id: nil, message_id: nil, message: nil, **args)
  unless TYPES.include?(type_)
    raise ArgumentError.new("type #{type_} is unknown; known types: #{TYPES}")
  end
  @type_ = type_
  @error = error
  @shard_block_id = shard_block_id
  @message_id = message_id
  @message = message
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



103
104
105
# File 'lib/ever_sdk_client/processing.rb', line 103

def args
  @args
end

#errorObject (readonly)

Returns the value of attribute error.



103
104
105
# File 'lib/ever_sdk_client/processing.rb', line 103

def error
  @error
end

#messageObject (readonly)

Returns the value of attribute message.



103
104
105
# File 'lib/ever_sdk_client/processing.rb', line 103

def message
  @message
end

#message_idObject (readonly)

Returns the value of attribute message_id.



103
104
105
# File 'lib/ever_sdk_client/processing.rb', line 103

def message_id
  @message_id
end

#shard_block_idObject (readonly)

Returns the value of attribute shard_block_id.



103
104
105
# File 'lib/ever_sdk_client/processing.rb', line 103

def shard_block_id
  @shard_block_id
end

#type_Object (readonly)

Returns the value of attribute type_.



103
104
105
# File 'lib/ever_sdk_client/processing.rb', line 103

def type_
  @type_
end

Instance Method Details

#to_hObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ever_sdk_client/processing.rb', line 117

def to_h
  h1 = {
    type: @type
  }

  h2 = case @type_
       when :will_fetch_first_block
         { }
       when :fetch_first_block_failed
         {
           error: @error
         }
       when :will_send, :did_send, :will_fetch_next_block
         {
           shard_block_id: @shard_block_id,
           message_id: @message_id,
           message: @message
         }
       when :send_failed, :fetch_next_block_failed
         {
           shard_block_id: @shard_block_id,
           message_id: @message_id,
           message: @message,
           error: @error
         }
       when :message_expired
         {
           message_id: @message_id,
           message: @message,
           error: @error
         }
       when :remp_sent_to_validators, :remp_included_into_block, :remp_included_into_accepted_block, :remp_other, :remp_error
         {
           message_id: message_id,
           timestamp: args[:timestamp],
           json: args[:json]
         }
       else
         raise ArgumentError.new("unsupported type: #{@type_}")
       end

  h1.merge(h2)
end