8

I might be over thinking this, but I'm trying to figure out the best way to build an unspent output pool. Should I just naively parse every block? Every input gets removed from the hash set, and every output gets added back in? Seems terribly inefficient. The thing is it doesn't seem like there is anyway to accurately build this utxo pool without traversing the block chain at least once and constructing it. Is there a well defined short-cut I should be aware of? Pointers welcome.

I guess I can iterate through the on-disk blocks first, and then update as blocks come in.

Matt
  • 540
  • 3
  • 10
  • That doesn't sound inefficient at all. What seems inefficient about it to you? – David Schwartz Jun 03 '14 at 05:15
  • I think I was just thinking that there might be a more efficient way. I thought the official client stored the utxo pool in some kind of tree structure, just trying to get more insight into this. – Matt Jun 03 '14 at 14:42
  • You can just use RPC to get the unspent outputs pool straight from bitcoind. – user13413 Jun 03 '14 at 21:06
  • @goatse Which command? – T9b Jul 21 '14 at 22:20
  • GREAT question. This is exactly the kind of details the BITS don't think are important and most do not understand themselves. bitcoin.org labelled bitcoin core as experimental. If the UTXO pool ever got out of sync with with the ledger even if just one SAT there is no central authority to initiate a recovery. – Richard Jan 01 '22 at 16:24

5 Answers5

4

There is already a pool with the information that you are willing to build: the UTXO set. You can access it by querying the LevelDB located in .bitcoin/chainstate of a full node.

However, there is no easy way of doing so by using RPC commands, you should extract the information by yourself.

I can provide a way to do so if you needed, and an extensive explanation of what are you going to find in each entry of the LevelDB.

sr_gi
  • 3,220
  • 1
  • 13
  • 37
3

You can directly get UTXO set from bitcoind using listunspent RPC call.

0

I have already built the utxo set parser but I need to know when the leveldb records is updated. I need something like cursor that will let me be aware if anything has changed on the network.

Topman
  • 11
  • 4
0

There is no simple way to get what you want except that way you try to describe.

RPC did not support any command of what you want.

If you need UTXOs, you must disassemble every *.dat binary file in series from the first and keep each output for checking on spending in future.

Denis Leonov
  • 945
  • 12
  • 28
  • Sorry but not true, what @Matt is willing to build is already part of the Bitcoin core client, he just need to check the UTXO set. It is indeed no easy to access, since there is no RPC command available, so he would need to access the LevelDB stores in /chainstate and most likely code his own parser. However, it is way easier than disassembling every .dat file and checking when every UTXO has been spend over the years. – sr_gi Apr 12 '17 at 09:26
  • @sr-gi I made it without of any client. UTXO database from raw dat files. – Denis Leonov Jun 02 '18 at 03:34
0

The following worked for me on a Bash command window:

curl https://blockchain.info/unspent?active=place_bitcoin_address_here