Class: EthereumContractABI::Decoders::FunctionDecoder
- Inherits:
-
Object
- Object
- EthereumContractABI::Decoders::FunctionDecoder
- Defined in:
- lib/ethereum-contract-abi/decoders/function_decoder.rb
Instance Method Summary collapse
- #decode_dynamic_output(encoded_output) ⇒ Object
- #decode_static_output(encoded_output) ⇒ Object
-
#initialize(function_outputs) ⇒ FunctionDecoder
constructor
A new instance of FunctionDecoder.
Constructor Details
#initialize(function_outputs) ⇒ FunctionDecoder
8 9 10 |
# File 'lib/ethereum-contract-abi/decoders/function_decoder.rb', line 8 def initialize(function_outputs) @function_outputs = function_outputs end |
Instance Method Details
#decode_dynamic_output(encoded_output) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Object
22 23 24 25 26 27 |
# 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 |