2
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:
- When I receive the TXO, it's actually an UTXO.
- 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?
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 – 2017-11-02T08:19:18.253
I implicitly implied
getrawtransactionin 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 – 2017-11-02T12:02:21.460sure? 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 – 2017-11-02T14:43:22.043
1) Yes, it shows the block. 2) While there is no identifier for the transaction output, the spender transaction identifies it with a
txid-indexpair. My point is, if I have a transaction, then based on thevin[]one can track all transaction down backwards all the way to the coinbase, sincevin[]has previous outputs (txid-indexpairs). While the reverse does not work: from thevout[]I cannot go forward, sincevout[]isamount-scriptPubKeypairs. – nopara73 – 2017-11-03T21:15:23.860ah, 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 – 2017-11-03T22:28:43.260
1have you solved this puzzle? – lzl124631x – 2018-10-04T06:58:40.130
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 – 2018-10-04T15:35:17.180