Class: WalletValidator::Eth
- Inherits:
-
Object
- Object
- WalletValidator::Eth
- Defined in:
- lib/wallet_validator/eth.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
Instance Method Summary collapse
-
#initialize(address, is_testnet) ⇒ Eth
constructor
A new instance of Eth.
- #valid? ⇒ Boolean
Constructor Details
#initialize(address, is_testnet) ⇒ Eth
Returns a new instance of Eth.
7 8 9 10 |
# File 'lib/wallet_validator/eth.rb', line 7 def initialize(address, is_testnet) @address = address @is_testnet = is_testnet end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
5 6 7 |
# File 'lib/wallet_validator/eth.rb', line 5 def address @address end |
Instance Method Details
#valid? ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/wallet_validator/eth.rb', line 12 def valid? # 不 match/無法 vaild 但成功/可 vaild 且成功/可 vaild 但失敗 prefix_address = prefix_hex(address) return false if !prefix_address.match?(/\A(?:0[xX])[a-fA-F0-9]{40}\z/) checksumed_address = checksummed(prefix_address) return true if prefix_address.match(/\A(?:0[xX])[A-F0-9]{40}\z/) || address.match(/\A(?:0[xX])[a-f0-9]{40}\z/) prefix_address == checksumed_address end |