Skip to content

fix(rest): return 404 from /tx/:txid/outspend/:vout for unknown outputs - #269

Open
theluckystrike wants to merge 2 commits into
Blockstream:new-indexfrom
theluckystrike:fix-outspend-404
Open

theluckystrike wants to merge 2 commits into
Blockstream:new-indexfrom
theluckystrike:fix-outspend-404

Conversation

@theluckystrike

@theluckystrike theluckystrike commented Nov 15, 2026 •

Copy link
Copy Markdown

Fixes #266

GET /tx/:txid/outspend/:vout returned 200 {"spent":false} for a txid that doesn't exist, and for a vout past the end of a real tx, so callers couldn't tell those apart from a real unspent output. It now returns 404 Transaction not found / Output not found, like GET /tx/:txid.

This is an API behaviour change: nonexistent outputs now get a 404 instead of a 200. mempool/electrs still returns 200 here, so the two backends would differ. If you'd rather keep compatibility, I can put the 404 behind a flag.

On the unspent path the check is a point lookup of the TxOut row (mempool first, then chain). The full tx is only read from the local store on a miss. It never calls bitcoind, so in light mode a daemon error can't turn into a 404, and a DB error returns a 503.

Tests cover mempool and confirmed unspent outputs (200), an unknown txid and an out-of-range vout (404), an OP_RETURN output (200), and light mode with no getrawtransaction call.

cargo test --test rest (macOS arm64), before:

test result: ok. 29 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

after:

test test_rest_tx_outspends ... ok
test test_rest_tx_outspend_light_mode ... ok
test test_rest_tx_outspend ... ok
test result: ok. 30 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

The new light-mode test fails on the previous version of this PR (1 extra getrawtransaction call).

An unknown txid or an out-of-range vout returned 200 {"spent":false},
the same response as a real unspent output. Look the tx up when the
output has no spend and return 404, like GET /tx/:txid does.

Fixes Blockstream#266
Use the TxOut row (mempool, then chain) to confirm an unspent output
exists, and only read the full tx from the local store on a miss. Never
query bitcoind on this path, so a daemon error in light mode can't become
a 404, and DB errors return 503.

Add tests for mempool and OP_RETURN outputs, and for light mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET /tx/:txid/outspend/:vout returns 200 status for transactions which do not exist

1 participant