- snip -
Second approach.
1-Setup bitcoind.
2-Set txindex=1 and rescan the blockchain.
3-Get latest block with getblockcount.
4-Use getblockhash block_number to get it's hash.
5-Use getblock hash to get that block transactions.
6-Parse every transaction with getrawtransaction hash 1 (1 for verbose).
7-Get the vout address of each transaction and add to sql.
8-Run a query to delete duplicates.
9-Use blockchain.info api to get each address balance.
10-If balance > desired_amount drop the address from the new sql table.
11-Done.
- snip -
- snip -Btw isn't there a way to calculate the Balance somehow with your second option? (without doing blockchain.info API requests)
Yes.
Step 6 and 7 are incorrect.
getrawtransaction will return a hex representation of the raw transaction. Here's an example of transaction ID 62886d0b5e7e88981839afb6996010d149f934f30a04f428456cd5e10a772846
010000000102651693fc8811883bd5f4a90d9825f1bc18a55ad9026264bcfc1e63a6b7f089000000006a4730440220673be38060c769b260ba9b0d0bee89fc0f9db1a3dbf09060c43adc499c082d7a02202aabd0eea4ee119c04234dee43c3543426fbd23547252e52fd4496d06b2e1fd4012102bc2af3ca047923b71f4e1d2aae0564ea97d0ec86f1aa7f4c2d4fb2acc3f9fe75ffffffff02411fc605000000001976a914c08407401f334b9e936391fee7753ea9bb45613688aca4688e00000000001976a914892f2d2752a0dc59f59be9ddffe56bccdd0440bc88ac00000000
Then if you run decoderawtransaction on that raw data, you'll get a json object with the data parsed out. Here's an example of that same transaction:
{
"txid" : "cc4aa7b2a873515edf55167126fb18919a67abb5f3cac35cd48c1e2b834c3edc",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "89f0b7a6631efcbc646202d95aa518bcf125980da9f4d53b881188fc93166502",
"vout" : 0,
"scriptSig" : {
"asm" : "30440220673be38060c769b260ba9b0d0bee89fc0f9db1a3dbf09060c43adc499c082d7a02202aabd0eea4ee119c04234dee43c3543426fbd23547252e52fd4496d06b2e1fd401 02bc2af3ca047923b71f4e1d2aae0564ea97d0ec86f1aa7f4c2d4fb2acc3f9fe75",
"hex" : "4730440220673be38060c769b260ba9b0d0bee89fc0f9db1a3dbf09060c43adc499c082d7a02202aabd0eea4ee119c04234dee43c3543426fbd23547252e52fd4496d06b2e1fd4012102bc2af3ca047923b71f4e1d2aae0564ea97d0ec86f1aa7f4c2d4fb2acc3f9fe75"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.96870209,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 c08407401f334b9e936391fee7753ea9bb456136 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914c08407401f334b9e936391fee7753ea9bb45613688ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1JYvuKZmqyyn8MTaTSwCQ6CrcJfcLGAruM"
]
}
},
{
"value" : 0.09332900,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 892f2d2752a0dc59f59be9ddffe56bccdd0440bc OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914892f2d2752a0dc59f59be9ddffe56bccdd0440bc88ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1DWN69tNjUQJv3QeJMHVLSJfHXXr2QusST"
]
}
}
]
}
You can see here that the transaction defines an array inputs that are being spent "vin" and an array of new unspent of outputs that are being created "vout".
This particular transaction creates 2 outputs identified by "n".
Output 0 contains 0.96870209 BTC (identified by "value") and is associated with address 1JYvuKZmqyyn8MTaTSwCQ6CrcJfcLGAruM.
Output 1 contains 0.09332900 BTC and is associated with address 1DWN69tNjUQJv3QeJMHVLSJfHXXr2QusST.
This particular transaction also spends 1 previously unspent output from transaction 89f0b7a6631efcbc646202d95aa518bcf125980da9f4d53b881188fc93166502. The "vout" in the "vin" indicates that it was the output from the transaction that had "n":0
Therefore, your program can remove output 0 of transaction 89f0b7a6631efcbc646202d95aa518bcf125980da9f4d53b881188fc93166502 from it's list of unspent outputs. And can add two new outputs (0 and 1) of transaction cc4aa7b2a873515edf55167126fb18919a67abb5f3cac35cd48c1e2b834c3edc to it's list of unspent outputs.
Once your program is done running, it can just dump the list of addresses from it's list of unspent outputs and remove any duplicate addresses.