Class: EvmTxInput::Decoder
- Inherits:
-
Object
- Object
- EvmTxInput::Decoder
- Defined in:
- lib/evm_tx_input/decoder.rb
Overview
A class containing a set of helpers to decode transactions input data into human-readable values by provided contract’s ABI
Instance Attribute Summary collapse
-
#abi ⇒ Hash
readonly
parsed contract ABI.
-
#method_definition ⇒ Hash
readonly
parsed contract ABI.
-
#method_definitions ⇒ Object
readonly
Returns the value of attribute method_definitions.
Instance Method Summary collapse
-
#decode_input(input_data) ⇒ EvmTxInput::Function
Decodes transaction input data.
-
#initialize(abi = []) ⇒ Decoder
constructor
Constructor of EvmTxInput::Decoder.
Constructor Details
#initialize(abi = []) ⇒ Decoder
Constructor of EvmTxInput::Decoder
15 16 17 18 |
# File 'lib/evm_tx_input/decoder.rb', line 15 def initialize(abi = []) @abi = abi @method_definitions = method_definitions_by_id(abi) end |
Instance Attribute Details
#abi ⇒ Hash (readonly)
parsed contract ABI
9 10 11 |
# File 'lib/evm_tx_input/decoder.rb', line 9 def abi @abi end |
#method_definition ⇒ Hash (readonly)
parsed contract ABI
9 10 11 |
# File 'lib/evm_tx_input/decoder.rb', line 9 def method_definition @method_definition end |
#method_definitions ⇒ Object (readonly)
Returns the value of attribute method_definitions.
10 11 12 |
# File 'lib/evm_tx_input/decoder.rb', line 10 def method_definitions @method_definitions end |
Instance Method Details
#decode_input(input_data) ⇒ EvmTxInput::Function
Decodes transaction input data
24 25 26 27 28 29 30 31 |
# File 'lib/evm_tx_input/decoder.rb', line 24 def decode_input(input_data) input_data = input_data[2..] if input_data.start_with?('0x') method_id = input_data[0...8] definition = method_definitions[method_id] raise Error, "ABI does not contain method with #{method_id} ID" unless definition Function.new(method_id, definition['name'], extract_arguments(input_data, definition)) end |