Class: WalletValidator::Eth

Inherits:
Object
  • Object
show all
Defined in:
lib/wallet_validator/eth.rb

Direct Known Subclasses

Bsc, Matic

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#addressObject (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

Returns:

  • (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