Module: Etheruby

Defined in:
lib/etheruby/client.rb,
lib/etheruby/railtie.rb,
lib/etheruby/configuration.rb,
lib/etheruby/encoders/base.rb,
lib/etheruby/type_matchers.rb,
lib/etheruby/treat_variable.rb,
lib/etheruby/response_parser.rb,
lib/etheruby/arguments_generator.rb,
lib/etheruby/contract_method_dsl.rb

Defined Under Namespace

Modules: Contract, ContractBase, ContractInstance, Encoders, TypeMatchers Classes: ArgumentsCountError, ArgumentsGenerator, Client, ClientHolder, Configuration, ContractMethodDSL, Railtie, ResponseHolder, ResponseParser

Class Method Summary collapse

Class Method Details

.is_array?(param) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/etheruby/treat_variable.rb', line 16

def is_array?(param)
  TypeMatchers.is_static_array_type(param) || TypeMatchers.is_dynamic_array_type(param)
end

.is_static_type?(param) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/etheruby/treat_variable.rb', line 12

def is_static_type?(param)
  !(%w(string bytes).include?(param.to_s) || TypeMatchers.is_dynamic_array_type(param))
end

.treat_variable(param, arg, direction) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/etheruby/treat_variable.rb', line 20

def treat_variable(param, arg, direction)
  if match = TypeMatchers.is_sized_type(param)
    klass = Etheruby::Encoders.const_get(match[1].capitalize)
    if match[1] == 'bytes'
      Encoders::Byte.new(match[2].to_i, arg)
    else
      klass.new(arg)
    end.send(direction)

  elsif match = TypeMatchers.is_dualsized_type(param)
    # Parameter is a dual sized array type, e.g. fixed16x16, ufixed128x128
    return Etheruby::Encoders.const_get(match[1].capitalize).
           new(match[2].to_i, match[3].to_i, arg).send(direction)

  elsif match = TypeMatchers.is_static_array_type(param)
    # Parameter is a staticly sized array type, e.g. uint256[24]
    Etheruby::Encoders::StaticArray.new(match[1], match[2].to_i, arg)

  elsif match = TypeMatchers.is_dynamic_array_type(param)
    # Parameter is a dynamicaly sized array type, e.g. uint256[]
    Etheruby::Encoders::DynamicArray.new(match[1], arg).send(direction)

  else
    # Parameter is a single-word type : string, bytes, address, function etc...
    Etheruby::Encoders.const_get(param.capitalize).new(arg).send(direction)

  end
end