Bitcoin Forum
May 04, 2024, 12:28:14 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How check address for validity?  (Read 4010 times)
bitcoinex (OP)
Sr. Member
****
Offline Offline

Activity: 350
Merit: 252


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
- Moжeт, ты eщё и в Heвидимyю Pyкy Pынкa вepyeшь? - Зaчeм жe вepoвaть в тo, чтo мoжнo нaблюдaть нeпocpeдcтвeннo?
1714825694
Hero Member
*
Offline Offline

Posts: 1714825694

View Profile Personal Message (Offline)

Ignore
1714825694
Reply with quote  #2

1714825694
Report to moderator
1714825694
Hero Member
*
Offline Offline

Posts: 1714825694

View Profile Personal Message (Offline)

Ignore
1714825694
Reply with quote  #2

1714825694
Report to moderator
"Bitcoin: mining our own business since 2009" -- Pieter Wuille
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714825694
Hero Member
*
Offline Offline

Posts: 1714825694

View Profile Personal Message (Offline)

Ignore
1714825694
Reply with quote  #2

1714825694
Report to moderator
LZ
Legendary
*
Offline Offline

Activity: 1722
Merit: 1072


P2P Cryptocurrency


View Profile
September 23, 2010, 02:30:13 PM
Last edit: January 22, 2018, 06:14:40 AM by LZ
 #2

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

My OpenPGP fingerprint: 5099EB8C0F2E68C63B4ECBB9A9D0993E04143362
nelisky
Legendary
*
Offline Offline

Activity: 1540
Merit: 1001


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 (OP)
Sr. Member
****
Offline Offline

Activity: 350
Merit: 252


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
- Moжeт, ты eщё и в Heвидимyю Pyкy Pынкa вepyeшь? - Зaчeм жe вepoвaть в тo, чтo мoжнo нaблюдaть нeпocpeдcтвeннo?
bitcoinex (OP)
Sr. Member
****
Offline Offline

Activity: 350
Merit: 252


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
- Moжeт, ты eщё и в Heвидимyю Pyкy Pынкa вepyeшь? - Зaчeм жe вepoвaть в тo, чтo мoжнo нaблюдaть нeпocpeдcтвeннo?
nelisky
Legendary
*
Offline Offline

Activity: 1540
Merit: 1001


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
Legendary
*
Offline Offline

Activity: 1722
Merit: 1072


P2P Cryptocurrency


View Profile
September 23, 2010, 05:27:56 PM
Last edit: September 23, 2010, 05:39:07 PM by lzsaver
 #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

My OpenPGP fingerprint: 5099EB8C0F2E68C63B4ECBB9A9D0993E04143362
bitcoinex (OP)
Sr. Member
****
Offline Offline

Activity: 350
Merit: 252


probiwon.com


View Profile WWW
September 24, 2010, 01:21:07 AM
Last edit: November 23, 2010, 02:10:56 AM by bitcoinex
 #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
- Moжeт, ты eщё и в Heвидимyю Pyкy Pынкa вepyeшь? - Зaчeм жe вepoвaть в тo, чтo мoжнo нaблюдaть нeпocpeдcтвeннo?
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5194
Merit: 12972


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
Merit: 2216


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 (OP)
Sr. Member
****
Offline Offline

Activity: 350
Merit: 252


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
- Moжeт, ты eщё и в Heвидимyю Pyкy Pынкa вepyeшь? - Зaчeм жe вepoвaть в тo, чтo мoжнo нaблюдaть нeпocpeдcтвeннo?
bradford1Merrill
Newbie
*
Offline Offline

Activity: 2
Merit: 0


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.
LZ
Legendary
*
Offline Offline

Activity: 1722
Merit: 1072


P2P Cryptocurrency


View Profile
October 02, 2010, 08:51:51 AM
Last edit: October 02, 2010, 09:10:44 AM by lzsaver
 #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.

My OpenPGP fingerprint: 5099EB8C0F2E68C63B4ECBB9A9D0993E04143362
mizerydearia
Hero Member
*****
Offline Offline

Activity: 574
Merit: 507



View Profile
October 04, 2010, 02:03:34 AM
Last edit: October 04, 2010, 07:25:28 AM by mizerydearia
 #14

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

+5btc from me
bitcoinex (OP)
Sr. Member
****
Offline Offline

Activity: 350
Merit: 252


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
- Moжeт, ты eщё и в Heвидимyю Pyкy Pынкa вepyeшь? - Зaчeм жe вepoвaть в тo, чтo мoжнo нaблюдaть нeпocpeдcтвeннo?
Gavin Andresen
Legendary
*
Offline Offline

Activity: 1652
Merit: 2216


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 (OP)
Sr. Member
****
Offline Offline

Activity: 350
Merit: 252


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
- Moжeт, ты eщё и в Heвидимyю Pyкy Pынкa вepyeшь? - Зaчeм жe вepoвaть в тo, чтo мoжнo нaблюдaть нeпocpeдcтвeннo?
LZ
Legendary
*
Offline Offline

Activity: 1722
Merit: 1072


P2P Cryptocurrency


View Profile
October 21, 2010, 02:26:11 AM
Last edit: January 22, 2018, 08:42:49 AM by LZ
 #18

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

My OpenPGP fingerprint: 5099EB8C0F2E68C63B4ECBB9A9D0993E04143362
Gavin Andresen
Legendary
*
Offline Offline

Activity: 1652
Merit: 2216


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
Merit: 0


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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!