6

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.

5
  • That doesn't sound inefficient at all. What seems inefficient about it to you? Jun 3, 2014 at 5: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 3, 2014 at 14:42
  • You can just use RPC to get the unspent outputs pool straight from bitcoind.
    – user13413
    Jun 3, 2014 at 21:06
  • @goatse Which command?
    – T9b
    Jul 21, 2014 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 1, 2022 at 16:24

5 Answers 5

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.

4
  • chainstate is only the index of full chain Apr 14, 2017 at 1:38
  • In the chainstate you can find all the data you may need to know about the UTXOs, such as the id, out index, amount, scriptPubKey, block in which it has been included, and whether it is coinbase or not.
    – sr_gi
    Apr 14, 2017 at 13:36
  • So could you tell about '*.ldb' file format? Apr 14, 2017 at 13:49
  • 1
    Sure, you can check this answer: bitcoin.stackexchange.com/a/52167/30668
    – sr_gi
    Apr 14, 2017 at 16:05
3

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

1
  • 6
    Only for UTXOs that are yours (or otherwise contribute to your own wallet's balance). Jan 9, 2018 at 9:00
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.

2
  • 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, 2017 at 9:26
  • @sr-gi I made it without of any client. UTXO database from raw dat files. Jun 2, 2018 at 3:34
0

The following worked for me on a Bash command window:

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

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.

2
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Saxtheowl
    Oct 21 at 7:04
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context.
    – Hannah Vernon
    Oct 22 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.