class EthereumContractABI::Decoders::FunctionDecoder

Public Class Methods

new(function_outputs) click to toggle source
# File lib/ethereum-contract-abi/decoders/function_decoder.rb, line 8
def initialize(function_outputs)
  @function_outputs = function_outputs
end

Public Instance Methods

decode_dynamic_output(encoded_output) click to toggle source
# File lib/ethereum-contract-abi/decoders/function_decoder.rb, line 12
def decode_dynamic_output(encoded_output)
  hex = Util.toHexByteString(encoded_output)
  @function_outputs.map.with_index  do |output, index|
    head = get_head_by_index(encoded_output, index)
    head_offset = IntDecoder.decode(head)
    output_bytes = hex.byteslice(head_offset, hex.bytesize)
    output.type.decode_value(Util.fromHexByteString(output_bytes, with_prefix: false))
  end
end
decode_static_output(encoded_output) click to toggle source
# File lib/ethereum-contract-abi/decoders/function_decoder.rb, line 22
def decode_static_output(encoded_output)
  @function_outputs.map.with_index  do |output, index|
    bytes = encoded_output.slice!(0, output.type.bytesize * 2)
    output.type.decode_value(bytes)
  end
end

Private Instance Methods

get_head_by_index(encoded_output, index) click to toggle source
# File lib/ethereum-contract-abi/decoders/function_decoder.rb, line 31
def get_head_by_index(encoded_output, index)
  first_byte = index * 64
  encoded_output.byteslice(first_byte, 64)
end