Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: Tycek on December 06, 2019, 04:03:42 PM



Title: Traversing Bitcoin by bitcoin-cli
Post by: Tycek on December 06, 2019, 04:03:42 PM
Hello.

I would like to ask, if it is possible with the help of bitcoin-cli to discover, if output of some transaction is spent, and if it is, which transaction it was. If it is not possible directly with bitcoin-cli, is there any other way, how to extract this information from Bitcoin blockchain?

Edit: Noticed I am maybe in a wrong category. Bitcoin Technical Support might be better place to put this question.


Title: Re: Traversing Bitcoin by bitcoin-cli
Post by: achow101 on December 06, 2019, 04:45:44 PM
If you can  create  a transaction spending the output, then  you can create a transaction and use testmempoolaccept.

Otherwise, there is no way to check whether an output was spent. It wouldn't be terribly hard to add an RPC for that, but I'm not sure of the  usefulness of this.

With a spent output, you definitely cannot find the transaction it was spent in. Bitcoin Core does not store this information because it is not useful to it. To extract that information, you would have to go through every transaction in the blockchain and store  which outpoints are spent in which transaction.


Title: Re: Traversing Bitcoin by bitcoin-cli
Post by: Tycek on December 06, 2019, 07:47:13 PM
OK. How do blockexplorers work then? Because I found one API, which has this feature. Do they have any backend on the server, that tries to connect every input of a new transaction to its previous output?


Title: Re: Traversing Bitcoin by bitcoin-cli
Post by: achow101 on December 07, 2019, 12:20:35 AM
OK. How do blockexplorers work then? Because I found one API, which has this feature. Do they have any backend on the server, that tries to connect every input of a new transaction to its previous output?
They don't  use Bitcoin Core, or at the very least, not stock Bitcoin Core. Instead they have their own custom  software and databases which parse and index the blockchain data so that lookups are fast. They also do other things which link together things that aren't actually linked in the blockchain, such as "input addresses".


Title: Re: Traversing Bitcoin by bitcoin-cli
Post by: Tycek on December 07, 2019, 10:56:07 AM
I see. So my problem is, that I would like to get the flow of transactions somehow from the Bitcoin blockchain. I tried some blockexplorer APIs, but they seemed to be pretty unstable sometimes. What would be the good way to do it?