Skip to content

Commit 287ea00

Browse files
authored
Merge pull request #9 from janb84/5
Improve block display in mempool tab
2 parents 0dacf2d + 25ada25 commit 287ea00

File tree

7 files changed

+34
-6
lines changed

7 files changed

+34
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to bitcoin-tui are documented here.
44

5+
## [0.6.0] - 2026-03-04
6+
7+
### Added
8+
- **Block age** - each block column in the Mempool tab now shows how long ago the block was mined (e.g. `14m ago`), fetched via the `time` field from `getblockstats`
9+
- **Adaptive block count** - the Mempool tab now fills the available terminal width with block columns (up to 20 blocks fetched), rather than always showing 7
10+
511
## [0.5.0] - 2026-03-04
612

713
### Added

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.14)
2-
project(bitcoin-tui VERSION 0.5.0 LANGUAGES CXX)
2+
project(bitcoin-tui VERSION 0.6.0 LANGUAGES CXX)
33

44
set(CMAKE_CXX_STANDARD 20)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Connects to a local or remote Bitcoin Core node via JSON-RPC and displays live b
1818
## Features
1919

2020
- **Dashboard** - blockchain height, difficulty, sync progress, network status, and mempool summary at a glance
21-
- **Mempool** - transaction count, virtual size, total fees, min relay fee, memory usage gauge, and animated recent block fill visualization (newest first, colored green/yellow/orange by weight - blocks slide right when a new block arrives)
21+
- **Mempool** - transaction count, virtual size, total fees, min relay fee, memory usage gauge, and animated recent block fill visualization (newest first, colored green/yellow/orange by weight - blocks slide right when a new block arrives; block age shown per column; number of columns adapts to terminal width)
2222
- **Search** - press `/` to search mempool or confirmed transactions (txid); drill into blocks, inputs, and outputs (`txindex=1` required for confirmed lookups)
2323
- **Network** - connection counts (inbound/outbound), client version, protocol version, relay fee
2424
- **Peers** - live peer table with address, network type, direction, ping, bytes sent/received, and tip height; navigate with `↑/↓` and press `Enter` to open a detail overlay for any peer

src/format.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <chrono>
34
#include <cstdint>
45
#include <cstdlib>
56
#include <ctime>
@@ -109,6 +110,22 @@ inline std::string fmt_age(int64_t secs) {
109110
return std::to_string(secs / 3600) + "h " + std::to_string((secs % 3600) / 60) + "m";
110111
}
111112

113+
inline std::string fmt_time_ago(int64_t timestamp) {
114+
int64_t now_secs = std::chrono::duration_cast<std::chrono::seconds>(
115+
std::chrono::system_clock::now().time_since_epoch())
116+
.count();
117+
int64_t diff = now_secs - timestamp;
118+
if (diff < 0)
119+
return "just now";
120+
if (diff < 60)
121+
return std::to_string(diff) + "s ago";
122+
if (diff < 3600)
123+
return std::to_string(diff / 60) + "m ago";
124+
if (diff < 86400)
125+
return std::to_string(diff / 3600) + "h ago";
126+
return std::to_string(diff / 86400) + "d ago";
127+
}
128+
112129
inline std::string trimmed(std::string s) {
113130
while (!s.empty() && (s.front() == ' ' || s.front() == '\t'))
114131
s.erase(s.begin());

src/poll.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,20 @@ void poll_rpc(RpcClient& rpc, AppState& state, std::mutex& mtx,
128128
if (on_core_ready)
129129
on_core_ready();
130130

131-
// ── Phase 2: per-block stats (slow — 7 sequential calls) ────────────
131+
// ── Phase 2: per-block stats (slow — up to 20 sequential calls) ────────────
132132
if (new_tip != cached_tip && new_tip > 0) {
133133
std::vector<BlockStat> fresh_blocks;
134-
for (int i = 0; i < 7 && (new_tip - i) >= 0; ++i) {
134+
for (int i = 0; i < 20 && (new_tip - i) >= 0; ++i) {
135135
try {
136136
json params = {new_tip - i,
137-
json({"height", "txs", "total_size", "total_weight"})};
137+
json({"height", "txs", "total_size", "total_weight", "time"})};
138138
auto bs = rpc.call("getblockstats", params)["result"];
139139
BlockStat blk;
140140
blk.height = bs.value("height", 0LL);
141141
blk.txs = bs.value("txs", 0LL);
142142
blk.total_size = bs.value("total_size", 0LL);
143143
blk.total_weight = bs.value("total_weight", 0LL);
144+
blk.time = bs.value("time", 0LL);
144145
fresh_blocks.push_back(blk);
145146
} catch (...) {
146147
break;

src/render.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <ftxui/dom/elements.hpp>
88
#include <ftxui/screen/color.hpp>
9+
#include <ftxui/screen/terminal.hpp>
910

1011
#include "format.hpp"
1112
#include "render.hpp"
@@ -147,7 +148,8 @@ Element render_mempool(const AppState& s) {
147148
// During slide: render old blocks minus the last (it slides off the right edge).
148149
const std::vector<BlockStat>& src = anim_slide ? s.block_anim_old : s.recent_blocks;
149150
int num = static_cast<int>(src.size());
150-
int max_render = anim_slide ? std::max(0, num - 1) : num;
151+
int max_cols = std::max(1, (Terminal::Size().dimx - 4) / (COL_WIDTH + 1));
152+
int max_render = std::min(anim_slide ? std::max(0, num - 1) : num, max_cols);
151153

152154
// Slide offset grows from 0 → (COL_WIDTH+1) chars over SLIDE_FRAMES frames.
153155
int left_pad = 0;
@@ -185,6 +187,7 @@ Element render_mempool(const AppState& s) {
185187
text(fmt_height(b.height)) | center,
186188
text(fmt_int(b.txs) + " tx") | center | color(Color::GrayDark),
187189
text(fmt_bytes(b.total_size)) | center | color(Color::GrayDark),
190+
text(b.time > 0 ? fmt_time_ago(b.time) : "") | center | color(Color::GrayDark),
188191
}) |
189192
size(WIDTH, EQUAL, COL_WIDTH));
190193
}

src/state.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct BlockStat {
2020
int64_t txs = 0;
2121
int64_t total_size = 0;
2222
int64_t total_weight = 0;
23+
int64_t time = 0;
2324
};
2425

2526
struct PeerInfo {

0 commit comments

Comments
 (0)