api: reject a /tx response that has no txid field

Open
#103 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@pkray2012 is already working on this.

Since Dec 3, 2026.

  • #115 by @pkray2012 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
api, backend, testing

Research direction

Read btc_toolkit/opreturn.py around lines 69–79, then inspect tests/test_opreturn.py and fuzz/fuzz_parsers.py. Add the missing-txid case to the tests, update the fuzzer inputs and add a [Unreleased] entry in CHANGELOG.md. Done means the missing field raises MempoolAPIError and the stated test, lint, type-check and full suite pass; an open linked pull request (#115) indicates work is already underway.

Written by the indexing model from the issue text.

Description

enhancement good first issue

What

fetch_transaction in opreturn.py, which tx, opreturn and inscription all use, checks that the API's answer describes the transaction that was asked for. It only does so when the answer has a txid field: data.get("txid", txid) falls back to the requested txid, so a response with no txid at all is accepted (opreturn.py L69-L79).

Mempool.space and Esplora always include txid, so a missing field means the response is not the one that was asked for. Other modules already read their fields with the helpers in btc_toolkit/api.py, where a field is required unless a default is given.

What to do

  • Require the field: a missing txid raises MempoolAPIError with "Unexpected response from /tx: ...", like the existing mismatch check (a non-string one is already rejected).
  • Add a test to tests/test_opreturn.py for a response without txid.
  • In fuzz/fuzz_parsers.py, set the txid field to the requested txid for part of the inputs that are JSON objects: today the fuzzer gets past the check mostly by leaving txid out (a random txid value rarely equals TXID), and after the change it would rarely get past it.
  • Add a line to CHANGELOG.md under [Unreleased].

Acceptance

  • The new test fails on the current main and passes with the change.
  • The full test suite passes; today no other test relies on a missing txid.

See CONTRIBUTING.md for the test, lint and type-check commands. Comment below before starting, so two people don't take the same issue.

Dominant language
Python
Stars
2
Forks
1
Avg merge
1h 45m
Merged PRs (30d)
23

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from devdavidejesus/btc-toolkit

All issues in devdavidejesus/btc-toolkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.