Module: Eth::Utils
- Defined in:
- lib/ethruby/utils.rb
Class Method Summary collapse
- .big_endian_decode(input) ⇒ Object
- .big_endian_encode(n) ⇒ Object
- .data_to_hex(data) ⇒ Object
- .hex_to_data(hex) ⇒ Object
- .sha3(text) ⇒ Object
Class Method Details
.big_endian_decode(input) ⇒ Object
19 20 21 |
# File 'lib/ethruby/utils.rb', line 19 def big_endian_decode(input) input.each_byte.reduce(0) {|s, i| s * 256 + i} end |
.big_endian_encode(n) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/ethruby/utils.rb', line 11 def big_endian_encode(n) if n == 0 '' else big_endian_encode(n / 256) + (n % 256).chr end end |
.data_to_hex(data) ⇒ Object
27 28 29 |
# File 'lib/ethruby/utils.rb', line 27 def data_to_hex(data) data.unpack("H*").first end |
.hex_to_data(hex) ⇒ Object
23 24 25 |
# File 'lib/ethruby/utils.rb', line 23 def hex_to_data(hex) [hex].pack("H*") end |
.sha3(text) ⇒ Object
7 8 9 |
# File 'lib/ethruby/utils.rb', line 7 def sha3(text) Digest::SHA3.new(256).digest text end |