user44941: I'm trying to get the raw transaction hex string of a transaction that I know the id from.
I would like to do that without using txindex=1.
As I assume the transaction is unspent (and confirmed) I'm doing the following steps:
bitcoin-cli gettxout 'txid'
bitcoin-cli getblockcount
bitcoin-cli getblockhash 'blockcount - txout.confirmations + 1'
bitcoin-cli getrawtransaction 'txid' 0 'blockhash'
I have a race condition when getting the blockcount.
Is there a better way to do that?

user48884: To avoid a race condition with getblockcount, you could use getblockheader with the bestblock result from gettxout and get its height. Then do the height calculation with the number of confirmations to get the block hash to pass to getrawtransaction.

44941: <p>I'm trying to get the raw transaction hex string of a transaction that I know the id from.</p>
<p>I would like to do that without using txindex=1.</p>
<p>As I assume the transaction is unspent (and confirmed) I'm doing the following steps:</p>
<p><code>bitcoin-cli gettxout 'txid'</code></p>
<p><code>bitcoin-cli getblockcount</code></p>
<p><code>bitcoin-cli getblockhash 'blockcount - txout.confirmations + 1'</code></p>
<p><code>bitcoin-cli getrawtransaction 'txid' 0 'blockhash'</code></p>
<p>I have a race condition when getting the blockcount.</p>
<p>Is there a better way to do that?</p>
 48884: <p>To avoid a race condition with <code>getblockcount</code>, you could use <code>getblockheader</code> with the <code>bestblock</code> result from <code>gettxout</code> and get its height. Then do the height calculation with the number of confirmations to get the block hash to pass to <code>getrawtransaction</code>.</p>
