Class: HexFormatter::DigixGold
- Inherits:
-
Object
- Object
- HexFormatter::DigixGold
- Defined in:
- lib/hex_formatter.rb
Instance Method Summary collapse
Instance Method Details
#decode(data) ⇒ Object
37 38 39 40 |
# File 'lib/hex_formatter.rb', line 37 def decode(data) payload = data.gsub("Dg", "") return "0x#{::Eth::Utils.bin_to_hex(::Base58.base58_to_binary(payload, :bitcoin))[2..-1]}" end |
#encode(data) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hex_formatter.rb', line 26 def encode(data) payload = data.gsub("0x", "").scan(/../).map(&:hex) raise ArgumentError if payload.length != 32 if payload[0] > 60 new_payload = "01" + data.gsub("0x", "") else new_payload = "02" + data.gsub("0x", "") end return "Dg#{::Base58.int_to_base58(new_payload.hex, :bitcoin)}" end |