Method: Eth::Abi::Encoder#primitive_type

Defined in:
lib/eth/abi/encoder.rb

#primitive_type(type, arg) ⇒ String

Encodes primitive types.

Parameters:

  • type (Eth::Abi::Type)

    type to be encoded.

  • arg (String|Number)

    value to be encoded.

Returns:

  • (String)

    the encoded primitive type.

Raises:

  • (EncodingError)

    if value does not match type.

  • (ValueOutOfBounds)

    if value is out of bounds for type.

  • (ArgumentError)

    if encoding fails for type.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/eth/abi/encoder.rb', line 85

def primitive_type(type, arg)
  case type.base_type
  when "uint"
    uint arg, type
  when "int"
    int arg, type
  when "bool"
    bool arg
  when "ureal", "ufixed"
    ufixed arg, type
  when "real", "fixed"
    fixed arg, type
  when "string", "bytes"
    bytes arg, type
  when "tuple"
    tuple arg, type
  when "hash"
    hash arg, type
  when "address"
    address arg
  else
    raise EncodingError, "Unhandled type: #{type.base_type} #{type.sub_type}"
  end
end