Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/api/src/routes/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ use crate::serialise::{WireLog, WireTransaction};
use axum::extract::{Path, State};
use axum::routing::get;
use axum::{Json, Router};
use indexer_db::{logs, transactions};
use indexer_db::{blocks, logs, transactions};
use serde::Serialize;

#[derive(Debug, Serialize)]
struct TxResponse {
tx: WireTransaction,
logs: Vec<WireLog>,
/// Unix-seconds chain time of the tx's block. The per-tx row carries no
/// timestamp (it lives on `blocks`), so the detail view joins it here —
/// otherwise the explorer can't show when an indexed tx happened. 0 if the
/// block row is somehow missing (shouldn't occur for an indexed tx).
block_timestamp: i64,
}

async fn detail(
Expand All @@ -26,9 +31,14 @@ async fn detail(
.await?
.ok_or_else(|| ApiError::NotFound("tx".into()))?;
let log_rows = logs::for_tx(&state.pool, &hash).await?;
let block_timestamp = blocks::get_by_height(&state.pool, tx.block_height)
.await?
.map(|b| b.timestamp)
.unwrap_or(0);
Ok(Json(TxResponse {
tx: (&tx).into(),
logs: log_rows.iter().map(WireLog::from).collect(),
block_timestamp,
}))
}

Expand Down
5 changes: 4 additions & 1 deletion scripts/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ v=$(curl -fsS "$API_BASE/tx/0xtxcccc00000000000000000000000000000000000000000000
[[ "$v" == "0xfeedfacefeedfacefeedfacefeedfacefeedface" ]] || fail "/tx.from rename broken (got '$v')"
v=$(curl -fsS "$API_BASE/tx/0xtxcccc00000000000000000000000000000000000000000000000000000000cc" | jq -r '.logs | length')
[[ "$v" == "2" ]] || fail "/tx logs count != 2 (got $v)"
ok "/tx/:hash (from_addr->from, logs[2])"
# block_timestamp joined from blocks (tx cccc is in block 2 @ ts 1700086400)
v=$(curl -fsS "$API_BASE/tx/0xtxcccc00000000000000000000000000000000000000000000000000000000cc" | jq -r '.block_timestamp')
[[ "$v" == "1700086400" ]] || fail "/tx block_timestamp != 1700086400 (got '$v')"
ok "/tx/:hash (from_addr->from, logs[2], block_timestamp)"

# /tx/<unknown> -> 404
code=$(curl -s -o /dev/null -w '%{http_code}' "$API_BASE/tx/0xdeadbeef")
Expand Down
Loading