`GET /tx/:txid` in regtest returns HTML instead of JSON

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

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
api, backend

Research direction

Start by tracing the GET /regtest/api/tx/:txid entry point and reproduce the request with Accept: application/json. Check where the endpoint selects its response and verify that a valid transaction response is returned as JSON rather than the HTML explorer shell.

Written by the indexing model from the issue text.

Description

I've defined a Rust struct that matches the specified transaction format. It appropriately derives an implementation of serde::Deserialize.

The URL for my request is defined as

let url = format!("http://127.0.0.1:5000/regtest/api/tx/{txid}");

The headers are set to Accept application/json.

The call returns a 200 response status, however, because the returned body is HTML, the following deserialization effort fails:

let tx: TxInfo = serde_json::from_slice(&response.body)?;

ERROR:
"Error(\"expected value\", line: 1, column: 1)"

Here's the full response from the API call:

STATUS:
200

HEADERS:
[HttpHeader { name: "x-powered-by", value: "Express" }, HttpHeader { name: "content-type", value: "text/html; charset=utf-8" }, HttpHeader { name: "content-length", value: "519" }, HttpHeader { name: "etag", value: "--" }, HttpHeader { name: "date", value: "Mon, 06 May 2024 --" }, HttpHeader { name: "connection", value: "close" }]

BODY:
<!DOCTYPE html><head><meta charset="utf-8"><title>Block Explorer</title><meta property="og:title" content="Block explorer"><meta name="description" content="Esplora Block Explorer"><base href="/"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="shortcut icon" type="image/png" href="img/favicon.png"><link rel="stylesheet" href="bootstrap.min.css"><link rel="stylesheet" href="style.css"></head><body lang="en" dir="ltr"><div id="explorer"></div><script src="app.js" async></script></body>
Dominant language
JavaScript
Stars
1.3k
Forks
527
Avg merge
2d 5h
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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 Blockstream/esplora

All issues in Blockstream/esplora

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.