Class: Nem::Unit::Address
- Inherits:
-
Object
- Object
- Nem::Unit::Address
- Defined in:
- lib/nem/unit/address.rb
Instance Attribute Summary collapse
-
#value ⇒ String
The current value of value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize(value) ⇒ Address
constructor
A new instance of Address.
- #mainnet? ⇒ Boolean
- #mijin? ⇒ Boolean
- #testnet? ⇒ Boolean
- #to_hexadecimal ⇒ String
- #to_s ⇒ String
- #valid? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ Address
Returns a new instance of Address.
11 12 13 14 |
# File 'lib/nem/unit/address.rb', line 11 def initialize(value) @value = value @first_char = @value[0] end |
Instance Attribute Details
#value ⇒ String
Returns the current value of value.
8 9 10 |
# File 'lib/nem/unit/address.rb', line 8 def value @value end |
Class Method Details
.from_public_key(public_key, network = :testnet) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nem/unit/address.rb', line 51 def self.from_public_key(public_key, network = :testnet) bin_public_key = Nem::Util::Convert.hex2bin(public_key) public_key_hash = Digest::SHA3.digest(bin_public_key, 256) ripe = OpenSSL::Digest::RIPEMD160.digest(public_key_hash) if network == :testnet version = "\x98".force_encoding('ASCII-8BIT') << ripe elsif network == :mijin version = "\x60" << ripe else version = "\x68" << ripe end checksum = Digest::SHA3.digest(version, 256)[0...4] # self.new(Base32.encode(version + checksum)) Base32.encode(version + checksum) end |
Instance Method Details
#==(other) ⇒ Boolean
47 48 49 |
# File 'lib/nem/unit/address.rb', line 47 def ==(other) @value == other.value end |
#mainnet? ⇒ Boolean
22 23 24 |
# File 'lib/nem/unit/address.rb', line 22 def mainnet? @first_char == 'N' end |
#mijin? ⇒ Boolean
32 33 34 |
# File 'lib/nem/unit/address.rb', line 32 def mijin? @first_char == 'M' end |
#testnet? ⇒ Boolean
27 28 29 |
# File 'lib/nem/unit/address.rb', line 27 def testnet? @first_char == 'T' end |
#to_hexadecimal ⇒ String
42 43 44 |
# File 'lib/nem/unit/address.rb', line 42 def to_hexadecimal @value.each_byte.inject('') { |memo, b| memo << b.to_s(16) } end |
#to_s ⇒ String
37 38 39 |
# File 'lib/nem/unit/address.rb', line 37 def to_s @value end |
#valid? ⇒ Boolean
17 18 19 |
# File 'lib/nem/unit/address.rb', line 17 def valid? !!(@value =~ /[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]{40}/) end |