Class: Veto::IsPkeyCheck

Inherits:
AttributeCheck
  • Object
show all
Defined in:
lib/veto_checks.rb

Constant Summary collapse

MSG =
"is not a public key"

Instance Method Summary collapse

Instance Method Details

#anynet_valid_address?(addr) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/veto_checks.rb', line 39

def anynet_valid_address?(addr)
  start_network = Bitcoin.network_name

  begin
    Bitcoin.network = (/\A1/.match addr) ? :bitcoin : :testnet3

    return Bitcoin.valid_address?(addr)
  ensure
    Bitcoin.network = start_network
  end
end

#call(cco) ⇒ Object



27
28
29
30
# File 'lib/veto_checks.rb', line 27

def call(cco)
  @blockchain = cco.entity.blockchain
  super(cco)
end

#check(attribute, value, errors, options = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/veto_checks.rb', line 32

def check(attribute, value, errors, options={})
  on = options.fetch(:on, attribute)
  unless value == 0 || anynet_valid_address?(value)
    errors.add(on, options[:message] || MSG) 
  end
end