Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: SgtSpike on December 12, 2013, 11:16:42 PM



Title: How can I automatically add all Bitcoin addresses ever used to a MySQL database?
Post by: SgtSpike on December 12, 2013, 11:16:42 PM
How can I automatically add all Bitcoin addresses ever used to a MySQL database in realtime?

I need to move firstbits.net away from using blockchain.info's API, since the firstbits no longer appear to be working at blockchain.info and haven't been for some time.  I'm no expert programmer, but I know enough about PHP and MySQL querying to get the website job done.  My problem comes in getting the data from bitcoin-qt (or another source) in the first place.

I'd like to set up some sort of cron job that looks for new addresses in the latest blocks coming through, and adds said addresses to the MySQL DB after 6 confirmations.  What's the best way to accomplish this?


Title: Re: How can I automatically add all Bitcoin addresses ever used to a MySQL database?
Post by: dserrano5 on December 13, 2013, 08:07:17 AM
My problem comes in getting the data from bitcoin-qt (or another source) in the first place.

I'd like to set up some sort of cron job that looks for new addresses in the latest blocks coming through, and adds said addresses to the MySQL DB after 6 confirmations.  What's the best way to accomplish this?

I'd do a getblock and for each transaction in it, do a decoderawtransaction and iterate the vouts in it.


Title: Re: How can I automatically add all Bitcoin addresses ever used to a MySQL database?
Post by: SgtSpike on December 13, 2013, 04:13:48 PM
My problem comes in getting the data from bitcoin-qt (or another source) in the first place.

I'd like to set up some sort of cron job that looks for new addresses in the latest blocks coming through, and adds said addresses to the MySQL DB after 6 confirmations.  What's the best way to accomplish this?

I'd do a getblock and for each transaction in it, do a decoderawtransaction and iterate the vouts in it.
Thanks, that makes sense.  I was hoping to not have to deal with JSON-RPC because I am so unfamiliar with it, but perhaps it is time to force myself to learn more about it.


Title: Re: How can I automatically add all Bitcoin addresses ever used to a MySQL database?
Post by: rabit on December 13, 2013, 04:44:28 PM
I wrote some time ago a bash script which analyzes all transactions in a block. You could just go through all blocks with
bitcoind getblockhash and start the script with the blockhash as a parameter (you would need to add some stuff to the script like the SQL stuff but maybe its anyway helpful).
Here is the relevant part of the bash script:

#!/bin/bash
#Search for transactions in block
#INPUT:Blockhash

txlist=$(bitcoind getblock $1)
txlist="${txlist%]*}"
txlist="${txlist#*[}"
txlist2=""
while [ "$txlist" != "$txlist2" ]; do
   txlist2=$txlist
   tx="${txlist%%,*}"
   tx="${tx#*'"'}"
   tx="${tx%'"'*}"
   txlist="${txlist#*,}"
   test=$(bitcoind gettransaction $tx 2> /dev/null)
   if [ "$test" != "" ]; then
      #Here you need to add code to get the relevant data from the transaction like output addresses
                #and add it to the SQL DB
   fi
done


EDIT: I just realized that gettransaction only works with transaction which you made yourself so for analyzing all transactions you would need to use something like
a=$(bitcoind getrawtransaction $tx)
b=$(bitcoind decoderawtransaction $a)


Title: Re: How can I automatically add all Bitcoin addresses ever used to a MySQL database?
Post by: dserrano5 on December 13, 2013, 06:48:29 PM
Thanks, that makes sense.  I was hoping to not have to deal with JSON-RPC because I am so unfamiliar with it, but perhaps it is time to force myself to learn more about it.

Hey you can always parse the raw blockchain files :). I have some Perl code (https://bitcointalk.org/index.php?topic=226243.msg2411404#msg2411404) for that if you're interested.


Title: Re: How can I automatically add all Bitcoin addresses ever used to a MySQL database?
Post by: SgtSpike on December 15, 2013, 07:44:15 AM
Thanks for the bash rabit, I'll consider it..!

Thanks, that makes sense.  I was hoping to not have to deal with JSON-RPC because I am so unfamiliar with it, but perhaps it is time to force myself to learn more about it.

Hey you can always parse the raw blockchain files :). I have some Perl code (https://bitcointalk.org/index.php?topic=226243.msg2411404#msg2411404) for that if you're interested.
Oooh, nice!  ;)