Bitcoin Forum
May 21, 2024, 02:22:35 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How can I automatically add all Bitcoin addresses ever used to a MySQL database?  (Read 1051 times)
SgtSpike (OP)
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
December 12, 2013, 11:16:42 PM
 #1

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

Activity: 1974
Merit: 1029



View Profile
December 13, 2013, 08:07:17 AM
 #2

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.
SgtSpike (OP)
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
December 13, 2013, 04:13:48 PM
 #3

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.
rabit
Member
**
Offline Offline

Activity: 62
Merit: 10


View Profile
December 13, 2013, 04:44:28 PM
Last edit: December 13, 2013, 05:07:39 PM by rabit
 #4

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

Activity: 1974
Merit: 1029



View Profile
December 13, 2013, 06:48:29 PM
 #5

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 Smiley. I have some Perl code for that if you're interested.
SgtSpike (OP)
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
December 15, 2013, 07:44:15 AM
 #6

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 Smiley. I have some Perl code for that if you're interested.
Oooh, nice!  Wink
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!