Bitcoin Forum
May 02, 2024, 03:01:56 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to efficiently parse the blockchain for ANY random address or txid?  (Read 1210 times)
RingMaster (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 2


View Profile
March 24, 2015, 09:25:11 AM
 #1

How do API services or block explorers like blockr.io, bchain.info, blockchain.info, blocktrail.com and so on, efficiently parse the blockchain for *any* address or transaction?

I've got some full nodes running. And especially since Bitcoin Core 0.10 where you can import watch only addresses, it's relatively easy to import a random address and watch its balance and history. It's not clear to me how people did this before 0.10 - I understand the data is in the blockchain obviously, but I wouldn't know how to parse it.

But in order to come up with any address' balance or tx history in a matter of seconds, how is that done? Is there a script or library of sorts to efficiently traverse the raw blockchain data for any particular address or txid? Does it require a special version of Bitcoin Core with extra tracking information or something? Do they actually keep a dedicated database for this, explicitly listing ALL addresses and txids?

Note that this is not related to any 'wallet', or specific addresses I already own or know. I'm trying to understand how this is done for random addresses or txs. That includes non-existent addresses or txids (where the result is 'does not exist' or 'never used' or balance zero).
1714618916
Hero Member
*
Offline Offline

Posts: 1714618916

View Profile Personal Message (Offline)

Ignore
1714618916
Reply with quote  #2

1714618916
Report to moderator
1714618916
Hero Member
*
Offline Offline

Posts: 1714618916

View Profile Personal Message (Offline)

Ignore
1714618916
Reply with quote  #2

1714618916
Report to moderator
1714618916
Hero Member
*
Offline Offline

Posts: 1714618916

View Profile Personal Message (Offline)

Ignore
1714618916
Reply with quote  #2

1714618916
Report to moderator
Once a transaction has 6 confirmations, it is extremely unlikely that an attacker without at least 50% of the network's computation power would be able to reverse it.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714618916
Hero Member
*
Offline Offline

Posts: 1714618916

View Profile Personal Message (Offline)

Ignore
1714618916
Reply with quote  #2

1714618916
Report to moderator
1714618916
Hero Member
*
Offline Offline

Posts: 1714618916

View Profile Personal Message (Offline)

Ignore
1714618916
Reply with quote  #2

1714618916
Report to moderator
shorena
Copper Member
Legendary
*
Offline Offline

Activity: 1498
Merit: 1499


No I dont escrow anymore.


View Profile WWW
March 24, 2015, 09:54:27 AM
 #2

How do API services or block explorers like blockr.io, bchain.info, blockchain.info, blocktrail.com and so on, efficiently parse the blockchain for *any* address or transaction?

They start with the first block and keep track via an external database.

I've got some full nodes running. And especially since Bitcoin Core 0.10 where you can import watch only addresses, it's relatively easy to import a random address and watch its balance and history. It's not clear to me how people did this before 0.10 - I understand the data is in the blockchain obviously, but I wouldn't know how to parse it.

getbalance was added in 0.10.0 but it does not return correct values for arbitrary addresses on none of my nodes. I suspect this is because the node running 24/7 has no wallet and the other one does not maintain a full transaction index. I suspect that getbalance is only working on address you imported (whether watch only or via private key) and that 0.10.0 isnt keeping track of all balances in the background.

But in order to come up with any address' balance or tx history in a matter of seconds, how is that done?

You have to trade calculation time for storage. If you expect to make these requests on a regular basis it makes sense to create a database that does the work once for all addresses, stores the results and gets updated with every new block found.

Is there a script or library of sorts to efficiently traverse the raw blockchain data for any particular address or txid?

AFAIK the best you can get from bitcoin core is to enable txindex which allows you to get information on any TX.

Does it require a special version of Bitcoin Core with extra tracking information or something? Do they actually keep a dedicated database for this, explicitly listing ALL addresses and txids?

Note that this is not related to any 'wallet', or specific addresses I already own or know. I'm trying to understand how this is done for random addresses or txs. That includes non-existent addresses or txids (where the result is 'does not exist' or 'never used' or balance zero).

Due to the amount of possible addresses I suspect that addresses that have never appeared on the blockchain have no database entry.

Im not really here, its just your imagination.
RingMaster (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 2


View Profile
March 24, 2015, 11:32:39 AM
 #3

What is a "full transaction index"? I've read that term before and sort of can imagine how to interpret that, but is there something "official" in Bitcoin jargon that defines full transaction index?

shorena
Copper Member
Legendary
*
Offline Offline

Activity: 1498
Merit: 1499


No I dont escrow anymore.


View Profile WWW
March 24, 2015, 12:36:27 PM
 #4

What is a "full transaction index"? I've read that term before and sort of can imagine how to interpret that, but is there something "official" in Bitcoin jargon that defines full transaction index?

Full transaction index as in: an index of all transactions (recorded in the blockchain). The default behaviour is to only keep an index of transactions that are related to your wallet.

Im not really here, its just your imagination.
spin
Sr. Member
****
Offline Offline

Activity: 362
Merit: 261


View Profile
March 24, 2015, 12:42:50 PM
 #5

What is a "full transaction index"? I've read that term before and sort of can imagine how to interpret that, but is there something "official" in Bitcoin jargon that defines full transaction index?
It allows you to pull the details of ANY tx by the tx hash.  Default as stated before only allows this for tx in your wallet.

If you liked this post buy me a beer.  Beers are quite cheap where I live!
bc1q707guwp9pc73r08jw23lvecpywtazjjk399daa
RingMaster (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 2


View Profile
March 24, 2015, 02:09:35 PM
 #6

I see, thanks. Is this a default feature of Bitcoin Core? And should I have done this right from the start, when initially downloading/parsing the blockchain, or is this something I can also enable on an existing default (i.e. non full tx indexed) Bitcoin Core instance?
spin
Sr. Member
****
Offline Offline

Activity: 362
Merit: 261


View Profile
March 24, 2015, 02:13:07 PM
 #7

You need to add the info to bitcoin.conf i.e. add txindex=1
Then you need to reindex (once only) by running bitcoin with the -reindex option from the command line.  This needs to be done once (and will take some time).


If you liked this post buy me a beer.  Beers are quite cheap where I live!
bc1q707guwp9pc73r08jw23lvecpywtazjjk399daa
coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1179



View Profile WWW
March 24, 2015, 06:59:08 PM
 #8

A lot of these services need to use a block parser/broswer like ABE. Have you looked into bitcoin abe? https://github.com/bitcoin-abe/bitcoin-abe


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!