Class: EvmTxInput::Encoder
- Inherits:
-
Object
- Object
- EvmTxInput::Encoder
- Defined in:
- lib/evm_tx_input/encoder.rb
Overview
A class containing a set of helpers to encode human-readable values to binary transactions input data
Class Method Summary collapse
-
.encode_function_signature(function_name, types = []) ⇒ String
Encodes function into binary representation (first 8 symbols at input data).
-
.encode_input(function_name, types = [], args = []) ⇒ String
Encodes function, types and arguments into binary input data.
-
.encode_parameters(types = [], args = []) ⇒ String
Encodes arguments into binary input data.
Class Method Details
.encode_function_signature(function_name, types = []) ⇒ String
Encodes function into binary representation (first 8 symbols at input data)
26 27 28 29 |
# File 'lib/evm_tx_input/encoder.rb', line 26 def encode_function_signature(function_name, types = []) function_signature = "#{function_name}(#{types.join(",")})" Eth::Util.bin_to_hex(Eth::Util.keccak256(function_signature)[0...4]) end |
.encode_input(function_name, types = [], args = []) ⇒ String
Encodes function, types and arguments into binary input data
14 15 16 17 18 19 |
# File 'lib/evm_tx_input/encoder.rb', line 14 def encode_input(function_name, types = [], args = []) encoded_function_signature = encode_function_signature(function_name, types) encoded_params = encode_parameters(types, args) "0x#{encoded_function_signature}#{encoded_params}" end |
.encode_parameters(types = [], args = []) ⇒ String
Encodes arguments into binary input data
36 37 38 |
# File 'lib/evm_tx_input/encoder.rb', line 36 def encode_parameters(types = [], args = []) Eth::Abi.encode(types, args).unpack1('H*') end |