Class: Etherlite::Contract::Function::EncodeArguments

Inherits:
Object
  • Object
show all
Defined in:
lib/etherlite/commands/contract/function/encode_arguments.rb

Instance Method Summary collapse

Instance Method Details

#performObject

rubocop:disable Metrics/MethodLength



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/etherlite/commands/contract/function/encode_arguments.rb', line 3

def perform # rubocop:disable Metrics/MethodLength
  if @values.length != @subtypes.count
    raise ArgumentError, "Expected #{@subtypes.count} arguments, got #{@values.length} "
  end

  head = []
  tail = []
  tail_offset = calculate_head_offset

  @subtypes.each_with_index do |type, i|
    content = type.encode @values[i]
    if type.dynamic?
      head << Etherlite::Utils.uint_to_hex(tail_offset)
      tail << content
      tail_offset += content.length / 2 # hex string, 2 characters per byte
    else
      head << content
    end
  end

  head.join + tail.join
end