Bitcoin Forum
September 28, 2016, 03:23:01 PM *
News: Due to DDoS attacks, there may be periodic downtime.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: How check address for validity?  (Read 3513 times)
bitcoinex
Sr. Member
****
Offline Offline

Activity: 350


probiwon.com


View Profile WWW
September 23, 2010, 04:38:29 AM
 #1

Is there a way? If not then it should be added, I think.
(I would have been easier to do it in CLI)

Why is it necessary:

Working with a database requires send queue to send coins to someone else. (You can not call the bitcoin client directly from the database - transactions can be ROLLBACKed, but sending coins is not.) Hence, the need to address customers' pre-checked against the address format.

Implement this functionality for every developer separately fraught with errors (for example, many languages not contains base58 functions ), better code to test the validity of addresses was one - in bitcoin client (or library). Besides, it gives an opportunity to make small changes to the format of the address in the future if needed.

New bitcoin lottery: probiwon.com
- Может, ты ещё и в Невидимую Руку Рынка веруешь? - Зачем же веровать в то, что можно наблюдать непосредственно?
1475076181
Hero Member
*
Offline Offline

Posts: 1475076181

View Profile Personal Message (Offline)

Ignore
1475076181
Reply with quote  #2

1475076181
Report to moderator
1475076181
Hero Member
*
Offline Offline

Posts: 1475076181

View Profile Personal Message (Offline)

Ignore
1475076181
Reply with quote  #2

1475076181
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1475076181
Hero Member
*
Offline Offline

Posts: 1475076181

View Profile Personal Message (Offline)

Ignore
1475076181
Reply with quote  #2

1475076181
Report to moderator
LZ
Staff
Legendary
*
Offline Offline

Activity: 1470


Satoshi everywhere!


View Profile WWW
September 23, 2010, 02:30:13 PM
 #2

What about this? You need Python, Django and PyCrypto.

"Never invest unless you can afford to lose your entire investment." © S3052
nelisky
Legendary
*
Offline Offline

Activity: 1554


View Profile
September 23, 2010, 02:46:46 PM
 #3

What about this? You need Python, Django and PyCrypto.

And what about this, which is a slightly tweaked version of that, to just depend on Python 2.5+?
Code:
#
# Stolen from gavinandresen's django field validator
#  http://bitcointalk.org/index.php?topic=1026.0
#

import re
from hashlib import sha256
import math

__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
__b58base = len(__b58chars)

def b58encode(v):
  """ encode v, which is a little-endian 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

  # Pad front with Base58-encoded-0 for leading zeros:
  nPad = int((len(v)*8 / (math.log(58,2))) - len(result))

  return (__b58chars[0]*nPad) + result

def b58decode(v, length):
  """ decode v into a little-endian 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
  if len(result) < length:
    n_pad = length-len(result)
    result = chr(0)*n_pad + result
  return result

def get_bcaddress_version(strAddress):
  """ Returns None if strAddress is invalid.  Otherwise returns integer version of address. """
  addr = b58decode(strAddress,25)
  version = addr[0]
  checksum = addr[-4:]
  vh160 = addr[:-4] # Version plus hash160 is what is checksummed
  h3=sha256(sha256(vh160).digest()).digest()
  if h3[0:4] == checksum:
    return ord(version)
  return None

def isvalid(value):
  value = value.strip()
  if re.match(r"[a-zA-Z1-9]{33,35}$", value) is None:
    return False
  return get_bcaddress_version(value) is not None
bitcoinex
Sr. Member
****
Offline Offline

Activity: 350


probiwon.com


View Profile WWW
September 23, 2010, 03:26:20 PM
 #4

you misunderstood me

the client has already been implemented check, need just the appropriate option
besides, it gives an opportunity to make small changes to the format of the address in the future if needed
and users also need address check without sending coins to make sure that the address they were told the correct

New bitcoin lottery: probiwon.com
- Может, ты ещё и в Невидимую Руку Рынка веруешь? - Зачем же веровать в то, что можно наблюдать непосредственно?
bitcoinex
Sr. Member
****
Offline Offline

Activity: 350


probiwon.com


View Profile WWW
September 23, 2010, 03:27:09 PM
 #5

What about this? You need Python, Django and PyCrypto.

What about pgplsql? Smiley

New bitcoin lottery: probiwon.com
- Может, ты ещё и в Невидимую Руку Рынка веруешь? - Зачем же веровать в то, что можно наблюдать непосредственно?
nelisky
Legendary
*
Offline Offline

Activity: 1554


View Profile
September 23, 2010, 04:51:21 PM
 #6

you misunderstood me

the client has already been implemented check, need just the appropriate option
besides, it gives an opportunity to make small changes to the format of the address in the future if needed
and users also need address check without sending coins to make sure that the address they were told the correct

Now I don't understand you Smiley

So, how does the above pieces of code not do what you want? You don't need to send coins to check an address, you don't even need bitcoin at all, just the address. And python being very readable you can easily port that to any other language you need and know (yes, including pgplsql, assuming you have the appropriate crypto calls available)
LZ
Staff
Legendary
*
Offline Offline

Activity: 1470


Satoshi everywhere!


View Profile WWW
September 23, 2010, 05:27:56 PM
 #7

the client has already been implemented check, need just the appropriate option
As far as I understand, you want to use a switch which will return true or false...
Something like -checkaddress=bitcoin_address. We need a patch for that switch.

2nelisky, thanks for tweaked version. Wink

"Never invest unless you can afford to lose your entire investment." © S3052
bitcoinex
Sr. Member
****
Offline Offline

Activity: 350


probiwon.com


View Profile WWW
September 24, 2010, 01:21:07 AM
 #8

the client has already been implemented check, need just the appropriate option
As far as I understand, you want to use a switch which will return true or false...
Something like -checkaddress=bitcoin_address. We need a patch for that switch.

yes, we need Smiley
I can not write a patch, so I just tried to justify it need

New bitcoin lottery: probiwon.com
- Может, ты ещё и в Невидимую Руку Рынка веруешь? - Зачем же веровать в то, что можно наблюдать непосредственно?
theymos
Administrator
Legendary
*
Offline Offline

Activity: 2422


View Profile
September 24, 2010, 01:58:11 AM
 #9

I would be trivial to add a JSON-RPC command to do that. Just use the IsValidBitcoinAddress function.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
Gavin Andresen
Legendary
*
Offline Offline

Activity: 1652


Chief Scientist


View Profile WWW
September 24, 2010, 01:28:43 PM
 #10

I would be trivial to add a JSON-RPC command to do that. Just use the IsValidBitcoinAddress function.

For extra credit, give an Object as the return value:

{
  'isvalid' : true,
  'ismine' : true,  # true if isvalid and you have the private key (can spend coins sent to this address)
  'version' : 0,  # ADDRESSVERSION
  'address' : '1frt6531....'    # might as well echo back the address...
}


How often do you get the chance to work on a potentially world-changing project?
bitcoinex
Sr. Member
****
Offline Offline

Activity: 350


probiwon.com


View Profile WWW
September 25, 2010, 08:12:18 AM
 #11

I would be trivial to add a JSON-RPC command to do that. Just use the IsValidBitcoinAddress function.

For extra credit, give an Object as the return value:

{
  'isvalid' : true,
  'ismine' : true,  # true if isvalid and you have the private key (can spend coins sent to this address)
  'version' : 0,  # ADDRESSVERSION
  'address' : '1frt6531....'    # might as well echo back the address...
}



Yes, that's option would be cool!

New bitcoin lottery: probiwon.com
- Может, ты ещё и в Невидимую Руку Рынка веруешь? - Зачем же веровать в то, что можно наблюдать непосредственно?
bradford1Merrill
Newbie
*
Offline Offline

Activity: 2


View Profile
October 02, 2010, 07:51:18 AM
 #12

In my work I am asking my self is there way to check    e-mail address validity. so please help.

Enhance the look of your kitchen with Ready to assemble cabinets (http://www.thertastore.com/RTA_Kitchen_Cabinets_Ready_to_Assemble_s/223.htm)
LZ
Staff
Legendary
*
Offline Offline

Activity: 1470


Satoshi everywhere!


View Profile WWW
October 02, 2010, 08:51:51 AM
 #13

And what are you answering yourself? Smiley

1. Validate e-mail using regular expressions.
2. Then check domain exists for that e-mail.
Say "helo" to 25 port and you should get "250".
3. Then check that user exists at that domain.
Say "rcpt to" and you should get "550" if exists.

"Never invest unless you can afford to lose your entire investment." © S3052
mizerydearia
Hero Member
*****
Offline Offline

Activity: 574



View Profile
October 04, 2010, 02:03:34 AM
 #14

I will offer 5btc reward for this patch to be produced.

+5btc from me
bitcoinex
Sr. Member
****
Offline Offline

Activity: 350


probiwon.com


View Profile WWW
October 04, 2010, 05:21:51 AM
 #15

I will offer 5btc reward for this patch to be produced.

+5btc from me

New bitcoin lottery: probiwon.com
- Может, ты ещё и в Невидимую Руку Рынка веруешь? - Зачем же веровать в то, что можно наблюдать непосредственно?
Gavin Andresen
Legendary
*
Offline Offline

Activity: 1652


Chief Scientist


View Profile WWW
October 20, 2010, 07:33:12 PM
 #16

I implemented "validateaddress" in svn r169:


$ ./bitcoind validateaddress '1P3rpbSybuGgeL1bRwCJFWbn4yBjRNQrbY'
{
    "isvalid" : true,
    "address" : "1P3rpbSybuGgeL1bRwCJFWbn4yBjRNQrbY",
    "ismine" : true
}
$ ./bitcoind validateaddress '1111111111111111111114oLvT2'
{
    "isvalid" : true,
    "address" : "1111111111111111111114oLvT2",
    "ismine" : false
}
$ ./bitcoind validateaddress 'mwFzbfqePwXUyT28e1kFVVh48uMHDsRzbi'
{
    "isvalid" : false
}

No address version number; that wasn't trivial to do, so I didn't do it.

How often do you get the chance to work on a potentially world-changing project?
bitcoinex
Sr. Member
****
Offline Offline

Activity: 350


probiwon.com


View Profile WWW
October 20, 2010, 09:24:23 PM
 #17

I implemented "validateaddress" in svn r169:


$ ./bitcoind validateaddress '1P3rpbSybuGgeL1bRwCJFWbn4yBjRNQrbY'


Who bitcoind instead of bitcoin?


Please write bitcoin address for the payment of this work.

New bitcoin lottery: probiwon.com
- Может, ты ещё и в Невидимую Руку Рынка веруешь? - Зачем же веровать в то, что можно наблюдать непосредственно?
LZ
Staff
Legendary
*
Offline Offline

Activity: 1470


Satoshi everywhere!


View Profile WWW
October 21, 2010, 02:26:11 AM
 #18

Please write bitcoin address for the payment of this work.
I think you can send him BitMail. Smiley

"Never invest unless you can afford to lose your entire investment." © S3052
Gavin Andresen
Legendary
*
Offline Offline

Activity: 1652


Chief Scientist


View Profile WWW
October 21, 2010, 03:33:58 AM
 #19

RE: payment:
If you really feel compelled to pay, send coins to the Faucet: 15VjRaDX9zpbA8LVnbrCAFzrVzN7ixHNsC

How often do you get the chance to work on a potentially world-changing project?
bradford1Merrill
Newbie
*
Offline Offline

Activity: 2


View Profile
October 23, 2010, 07:45:41 AM
 #20

Hi,
 I am new here. wish everybody have a good time.


How to check address validity in my sql server. i am for got my address can any one help me please.

Enhance the look of your kitchen with Ready to assemble cabinets (http://www.thertastore.com/RTA_Kitchen_Cabinets_Ready_to_Assemble_s/223.htm)
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!