Class: EverSdk::Abi::DecodedMessageBody

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

Constant Summary collapse

MESSAGE_BODY_TYPE_VALUES =
[:input, :output, :internal_output, :event]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body_type:, name:, value: nil, header: nil) ⇒ DecodedMessageBody

Returns a new instance of DecodedMessageBody.



356
357
358
359
360
361
362
363
364
365
# File 'lib/ever_sdk_client/abi.rb', line 356

def initialize(body_type:, name:, value: nil, header: nil)
  unless MESSAGE_BODY_TYPE_VALUES.include?(body_type)
    raise ArgumentError.new("unknown body_type: #{body_type}; known ones: #{MESSAGE_BODY_TYPE_VALUES}")
  end

  @body_type = body_type
  @name = name
  @value = value
  @header = header
end

Instance Attribute Details

#body_typeObject (readonly)

Returns the value of attribute body_type.



354
355
356
# File 'lib/ever_sdk_client/abi.rb', line 354

def body_type
  @body_type
end

#headerObject (readonly)

Returns the value of attribute header.



354
355
356
# File 'lib/ever_sdk_client/abi.rb', line 354

def header
  @header
end

#nameObject (readonly)

Returns the value of attribute name.



354
355
356
# File 'lib/ever_sdk_client/abi.rb', line 354

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



354
355
356
# File 'lib/ever_sdk_client/abi.rb', line 354

def value
  @value
end

Class Method Details

.from_json(j) ⇒ Object



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/ever_sdk_client/abi.rb', line 376

def self.from_json(j)
  return nil if j.nil?

  hdr = if !j["header"].nil?
    FunctionHeader.new(
      expire: j["header"]["expire"],
      time: j["header"]["time"],
      pubkey: j["header"]["pubkey"]
    )
  else
    nil
  end

  self.new(
    body_type: self.parse_body_type(j["body_type"]),
    name: j["name"],
    value: j["value"],
    header: hdr
  )
end

Instance Method Details

#to_hObject



367
368
369
370
371
372
373
374
# File 'lib/ever_sdk_client/abi.rb', line 367

def to_h
  {
    body_type: Helper.sym_to_capitalized_case_str(@body_type),
    name: @name,
    value: @value,
    header: @header
  }
end