Class: Veto::IsPkeyCheck
- Inherits:
-
AttributeCheck
- Object
- AttributeCheck
- Veto::IsPkeyCheck
- Defined in:
- lib/veto_checks.rb
Constant Summary collapse
- MSG =
"is not a public key"
Instance Method Summary collapse
- #anynet_valid_address?(addr) ⇒ Boolean
- #call(cco) ⇒ Object
- #check(attribute, value, errors, options = {}) ⇒ Object
Instance Method Details
#anynet_valid_address?(addr) ⇒ 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, ={}) on = .fetch(:on, attribute) unless value == 0 || anynet_valid_address?(value) errors.add(on, [:message] || MSG) end end |