4

I suspect there is no good way to do it. However is there any sub-optimal way to find the transaction that spends a transaction output (knowing the txid and index) with Bitcoin RPC?
Assuming txindex=1 and prune=0.

This was the more general question. In my case:

  1. When I receive the TXO, it's actually an UTXO.
  2. I am only interested in confirmed transactions.

The only way I can come up with to answer both questions is iterating through all the transactions of all the blocks from the TXO's block to the last received block and the mempool. Or in my case, I don't mind the mempool.
Nevertheless this is cumbersome and likely I'd be better off with some kind of indexer. Is there better way to do it with RPC?

nopara73
  • 816
  • 6
  • 21
  • not sure on the question, when you have your tx ID, then you can list the tx details with "bitcoin-cli getrawtransaction". I don't see if you want to search all transactions in blockchain (then you don't need a tx ID), or if you have a tx ID and search for details of it... – pebwindkraft Nov 02 '17 at 08:19
  • I implicitly implied getrawtransaction in my sub-optimal solution. It doesn't tell you which tx spends the txos of the transaction, but it tells you which block contains the transaction. – nopara73 Nov 02 '17 at 12:02
  • sure? I think it does not show the block. The "vin[]" structure contains a link to the previous tx ID, and the previous tx vout number. I wonder what you mean by txo of "the" transaction. I am not aware of an identifier for a transaction output. In a tx we have usually the vin[] structure, from where to move Satoshis, and a vout[] structure, where the Satoshis shall go to. Can you perhaps rephrase with vin, vout, or previous transaction, previous input? So we can better follow your idea? – pebwindkraft Nov 02 '17 at 14:43
  • Yes, it shows the block. 2) While there is no identifier for the transaction output, the spender transaction identifies it with a txid-index pair. My point is, if I have a transaction, then based on the vin[] one can track all transaction down backwards all the way to the coinbase, since vin[] has previous outputs (txid-index pairs). While the reverse does not work: from the vout[] I cannot go forward, since vout[] is amount-scriptPubKey pairs.
  • – nopara73 Nov 03 '17 at 21:15
  • ah, ok, got it. I am not aware on an easy solution. You would have to take a vout[], decompose the scriptPubKey and it's address, search for this address in the blockchain (or a block explorer) within the time frame of the tx (or block height), take this tx number, take the vout[], decompose... This is tough work, basically your own block explorer. What comes to my mind is this: what happens when a bitcoin tumbler, a cross chain tx, or an exchange comes into the game - then the tracks with their attributes loose their meaning... but certainly a funny experience... – pebwindkraft Nov 03 '17 at 22:28
  • 1
    have you solved this puzzle? – lzl124631x Oct 04 '18 at 06:58
  • You can't with Bitcoin Core. I hacked around by parsing the whole chain and build an index table for my specific purpose, (I don't need mempool, nor non-bech32 addresses) which makes things much faster (only a few weeks to build this intex table) so I doubt it'd be useful to you, but here's the code: https://github.com/zkSNACKs/WalletWasabi/blob/master/WalletWasabi/Services/IndexBuilderService.cs You can do it with libbitcoin though. At the end of this presentation I asked questions regarding it and the presenter discusses the pros and cons: https://www.youtube.com/watch?v=QtB4YUneiEE – nopara73 Oct 04 '18 at 15:35
  • on blockchain.info you can get the spending transaction with: spending_outpoints.tx_index on https://blockchain.info/tx/$tx_index_or_txid?format=json – Ciro Santilli OurBigBook.com Mar 25 '24 at 20:46