It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
(address =~ /^[a-zA-Z1-9]{33,35}$/)
require 'digest'
class BitcoinAddressValidator < ActiveModel::EachValidator
def validate(record, field, value)
unless valid_bitcoin_address?(value)
record.errors[field] << "Bitcoin address is invalid"
end
end
private
B58Chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
B58Base = B58Chars.length
def self.valid_bitcoin_address?(address)
(address =~ /^[a-zA-Z1-9]{33,35}$/) and version(address)
end
def self.version(address)
decoded = b58_decode(address, 25)
version = decoded[0, 1]
checksum = decoded[-4, decoded.length]
vh160 = decoded[0, decoded.length - 4]
hashed = (Digest::SHA2.new << (Digest::SHA2.new << vh160).digest).digest
hashed[0, 4] == checksum ? version[0] : nil
end
def self.b58_decode(value, length)
long_value = 0
index = 0
result = ""
value.reverse.each_char do |c|
long_value += B58Chars.index(c) * (B58Base ** index)
index += 1
end
while long_value >= 256 do
div, mod = long_value.divmod 256
result = mod.chr + result
long_value = div
end
result = long_value.chr + result
if result.length < length
result = 0.chr * (length - result.length) + result
end
result
end
end
#
# DJango field type for a Bitcoin Address
#
import re
from django import forms
from django.forms.util import ValidationError
from Crypto.Hash import SHA256
class BCAddressField(forms.CharField):
default_error_messages = {
'invalid': 'Invalid Bitcoin address.',
}
def __init__(self, *args, **kwargs):
super(BCAddressField, self).__init__(*args, **kwargs)
def clean(self, value):
value = value.strip()
if re.match(r"[a-zA-Z1-9]{27,35}$", value) is None:
raise ValidationError(self.error_messages['invalid'])
version = get_bcaddress_version(value)
if version is None:
raise ValidationError(self.error_messages['invalid'])
return value
import math
__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
__b58base = len(__b58chars)
def b58encode(v):
""" encode v, which is a string of bytes, to base58.
"""
long_value = 0L
for (i, c) in enumerate(v[::-1]):
long_value += (256**i) * ord(c)
result = ''
while long_value >= __b58base:
div, mod = divmod(long_value, __b58base)
result = __b58chars[mod] + result
long_value = div
result = __b58chars[long_value] + result
# Bitcoin does a little leading-zero-compression:
# leading 0-bytes in the input become leading-1s
nPad = 0
for c in v:
if c == '\0': nPad += 1
else: break
return (__b58chars[0]*nPad) + result
def b58decode(v, length):
""" decode v into a string of len bytes
"""
long_value = 0L
for (i, c) in enumerate(v[::-1]):
long_value += __b58chars.find(c) * (__b58base**i)
result = ''
while long_value >= 256:
div, mod = divmod(long_value, 256)
result = chr(mod) + result
long_value = div
result = chr(long_value) + result
nPad = 0
for c in v:
if c == __b58chars[0]: nPad += 1
else: break
result = chr(0)*nPad + result
if length is not None and len(result) != length:
return None
return result
def get_bcaddress_version(strAddress):
""" Returns None if strAddress is invalid. Otherwise returns integer version of address. """
addr = b58decode(strAddress,25)
if addr is None: return None
version = addr[0]
checksum = addr[-4:]
vh160 = addr[:-4] # Version plus hash160 is what is checksummed
h3=SHA256.new(SHA256.new(vh160).digest()).digest()
if h3[0:4] == checksum:
return ord(version)
return None