Skip to content

Commit

Permalink
verify address version
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmike committed Feb 15, 2014
1 parent 7e61a4c commit 41e62cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/config.yml.sample
Expand Up @@ -38,3 +38,7 @@ min_payout: 1.0 # in PPC
our_fee: 0.05
tipper_delay: "1.hour"

address_versions: # 55/117 for peercoin, 111/196 for testnet, see base58.h
- 111
- 196

10 changes: 9 additions & 1 deletion lib/bitcoin_address_validator.rb
Expand Up @@ -13,7 +13,15 @@ def validate_each(record, field, value)
B58Base = B58Chars.length

def valid_bitcoin_address?(address)
(address =~ /^[a-zA-Z1-9]{33,35}$/) and version(address)
if (address =~ /^[a-zA-Z1-9]{33,35}$/) and version = version(address)
if (expected_versions = CONFIG["address_versions"]).present?
expected_versions.include?(version.ord)
else
true
end
else
false
end
end

def version(address)
Expand Down

0 comments on commit 41e62cb

Please sign in to comment.