ncantu b5ad2a682d UTXO-list: paginate tables by 50 items per page
**Motivations:**
- Paginer les tableaux UTXO par 50 au lieu de 100

**Root causes:**
- N/A

**Correctifs:**
- ITEMS_PER_PAGE 100 → 50

**Evolutions:**
- Aucune

**Pages affectées:**
- signet-dashboard/public/utxo-list.html
2026-01-26 01:35:46 +01:00

969 lines
41 KiB
HTML

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Liste des UTXO - Bitcoin Ancrage Dashboard</title>
<link rel="stylesheet" href="styles.css">
<style>
.utxo-list-container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
}
.header-section {
margin-bottom: 30px;
}
.header-section h1 {
margin-bottom: 10px;
}
.header-section .back-link {
display: inline-block;
margin-bottom: 20px;
color: #007bff;
text-decoration: none;
}
.header-section .back-link:hover {
text-decoration: underline;
}
.info-section {
background: #f8f9fa;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.info-section p {
margin: 5px 0;
}
.category-section {
margin-bottom: 40px;
}
.category-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 15px 20px;
border-radius: 5px 5px 0 0;
margin-bottom: 0;
}
.category-header.bloc-rewards {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}
.category-header.ancrages {
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}
.category-header.changes {
background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}
.category-header.fees {
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}
.category-header h2 {
margin: 0;
font-size: 1.5em;
}
.category-stats {
background: rgba(255, 255, 255, 0.2);
padding: 10px;
margin-top: 10px;
border-radius: 3px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.category-stats span {
margin-right: 20px;
}
.table-container {
overflow-x: auto;
background: white;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background: #f8f9fa;
color: #333;
font-weight: bold;
position: sticky;
top: 0;
}
tr:hover {
background: #f5f5f5;
}
.txid-cell {
font-family: monospace;
font-size: 0.9em;
}
.txid-link {
color: #007bff;
text-decoration: none;
}
.txid-link:hover {
text-decoration: underline;
}
.address-cell {
font-family: monospace;
font-size: 0.9em;
word-break: break-all;
}
.amount-cell {
text-align: right;
font-weight: bold;
}
.loading {
text-align: center;
padding: 40px;
font-size: 1.2em;
color: #666;
}
.progress-section {
padding: 30px;
text-align: center;
background: #f8f9fa;
border-radius: 8px;
margin: 20px 0;
}
.progress-section p {
margin: 10px 0;
color: #333;
}
.progress-bar-container {
width: 100%;
max-width: 400px;
height: 24px;
background: #e9ecef;
border-radius: 12px;
overflow: hidden;
margin: 15px auto;
}
.progress-bar-fill {
height: 100%;
background: linear-gradient(90deg, #28a745, #20c997);
transition: width 0.15s ease;
}
.progress-stats {
font-size: 0.9em;
color: #666;
margin-top: 10px;
}
.source-note {
font-size: 0.9em;
color: #666;
margin-top: 10px;
font-style: italic;
}
.error {
background: #f8d7da;
color: #721c24;
padding: 15px;
border-radius: 5px;
margin: 20px 0;
}
.refresh-button {
background: #28a745;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
margin-top: 10px;
}
.refresh-button:hover {
background: #218838;
}
.refresh-button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.consolidate-button {
background: #ffc107;
color: #000;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
margin-top: 10px;
}
.consolidate-button:hover {
background: #e0a800;
}
.consolidate-button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.sortable-header {
cursor: pointer;
user-select: none;
position: relative;
}
.sortable-header:hover {
background: #e9ecef;
}
.sort-arrow {
display: inline-block;
margin-left: 5px;
font-size: 0.8em;
}
.pagination {
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
margin: 20px 0;
}
.pagination-button {
padding: 8px 16px;
background: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.pagination-button:hover:not(:disabled) {
background: #0056b3;
}
.pagination-button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.pagination-info {
font-weight: bold;
}
.total-amount {
font-size: 1.2em;
font-weight: bold;
color: #28a745;
}
.empty-message {
padding: 20px;
text-align: center;
color: #666;
background: #f8f9fa;
border-radius: 0 0 5px 5px;
}
.status-spent {
color: #dc3545;
font-weight: bold;
}
.status-locked {
color: #ffc107;
font-weight: bold;
}
.status-available {
color: #28a745;
font-weight: bold;
}
.navigation-bar {
background: #f8f9fa;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
}
.navigation-bar a {
padding: 10px 20px;
background: white;
color: #007bff;
text-decoration: none;
border-radius: 5px;
border: 2px solid #007bff;
transition: all 0.3s;
font-weight: bold;
}
.navigation-bar a:hover {
background: #007bff;
color: white;
}
.category-section {
scroll-margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="utxo-list-container">
<div class="header-section">
<a href="/" class="back-link">← Retour au dashboard</a>
<h1>Liste des UTXO</h1>
<div class="info-section">
<p><strong>Total d'UTXO :</strong> <span id="utxo-count">-</span></p>
<p><strong>Capacité d'ancrage restante :</strong> <span id="available-for-anchor">-</span> ancrages</p>
<button class="consolidate-button" id="consolidate-button" onclick="consolidateSmallUtxos()" style="margin-left: 10px; background: #ffc107; color: #000; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; font-size: 1em; margin-top: 10px;">Chargement...</button>
<p><strong>Montant total :</strong> <span id="total-amount" class="total-amount">-</span></p>
<p><strong>Dernière mise à jour :</strong> <span id="last-update">-</span></p>
<button class="refresh-button" onclick="loadUtxoList()">Actualiser</button>
<a href="/api/utxo/list.txt" download="utxo_list.txt" style="margin-left: 10px; color: #007bff; text-decoration: none;">📥 Télécharger le fichier texte</a>
</div>
</div>
<div id="navigation" class="navigation-bar" style="display: none;">
<a href="#bloc-rewards">💰 Bloc Rewards</a>
<a href="#ancrages">🔗 Ancrages</a>
<a href="#changes">🔄 Changes</a>
<a href="#fees">💸 Frais</a>
</div>
<div id="content">
<div class="loading">Chargement des UTXO...</div>
</div>
<div id="progress-section" class="progress-section" style="display: none;">
<p><strong>Chargement progressif depuis le fichier</strong></p>
<div class="progress-bar-container">
<div id="progress-bar-fill" class="progress-bar-fill" style="width: 0%;"></div>
</div>
<p id="progress-percent">0 %</p>
<p id="progress-stats" class="progress-stats">0 ligne(s) parsée(s)</p>
<p id="source-note" class="source-note">Source : fichier utxo_list.txt (peut ne pas être à jour)</p>
</div>
</div>
</div>
<script>
const API_BASE_URL = window.location.origin;
const ITEMS_PER_PAGE = 50;
// État de tri et pagination pour chaque catégorie
const tableState = {};
/** Données UTXO chargées (blocRewards, anchors, changes, fees) */
let currentUtxosData = {};
/** true si les données viennent du fichier (pas de Statut connu) */
let utxosFromFile = false;
// Charger la liste au chargement de la page
document.addEventListener('DOMContentLoaded', () => {
loadUtxoList();
loadSmallUtxosInfo();
});
function getSortState(categoryName) {
if (!tableState[categoryName]) {
tableState[categoryName] = {
sortColumn: null,
sortDirection: 'desc',
currentPage: 1,
};
}
return tableState[categoryName];
}
function sortUtxos(utxos, sortColumn, sortDirection) {
const sorted = [...utxos];
sorted.sort((a, b) => {
let aVal, bVal;
if (sortColumn === 'amount') {
aVal = a.amount;
bVal = b.amount;
} else if (sortColumn === 'confirmed') {
// Trier par confirmé/non confirmé (booléen)
aVal = (a.confirmations || 0) > 0 ? 1 : 0;
bVal = (b.confirmations || 0) > 0 ? 1 : 0;
} else {
return 0;
}
if (sortDirection === 'asc') {
return aVal - bVal;
} else {
return bVal - aVal;
}
});
return sorted;
}
function getSortArrow(sortColumn, currentSortColumn, sortDirection) {
if (sortColumn !== currentSortColumn) {
return '<span class="sort-arrow">↕</span>';
}
return sortDirection === 'asc'
? '<span class="sort-arrow">↑</span>'
: '<span class="sort-arrow">↓</span>';
}
function renderTable(utxos, categoryName, categoryLabel) {
if (utxos.length === 0) {
return `
<div class="category-section" id="${categoryName}">
<div class="category-header ${categoryName}">
<h2>${categoryLabel}</h2>
<div class="category-stats">
<span><strong>Nombre :</strong> 0</span>
<span><strong>Montant total :</strong> 0 🛡</span>
</div>
</div>
<div class="empty-message">Aucun UTXO dans cette catégorie.</div>
</div>
`;
}
const state = getSortState(categoryName);
// Trier les UTXOs
let sortedUtxos = utxos;
if (state.sortColumn) {
sortedUtxos = sortUtxos(utxos, state.sortColumn, state.sortDirection);
}
// Paginer les UTXOs
const totalPages = Math.ceil(sortedUtxos.length / ITEMS_PER_PAGE);
const startIndex = (state.currentPage - 1) * ITEMS_PER_PAGE;
const endIndex = startIndex + ITEMS_PER_PAGE;
const paginatedUtxos = sortedUtxos.slice(startIndex, endIndex);
const totalAmount = utxos.reduce((sum, utxo) => sum + utxo.amount, 0);
const totalSats = Math.round(totalAmount * 100000000);
const isAnchors = categoryName === 'ancrages';
const isBlocRewards = categoryName === 'bloc-rewards';
const isChanges = categoryName === 'changes';
// Pour les changes, compter les changes d'ancrage
let anchorChangesCount = 0;
let anchorChangesAmount = 0;
if (isChanges) {
const anchorChanges = utxos.filter(utxo => utxo.isAnchorChange);
anchorChangesCount = anchorChanges.length;
anchorChangesAmount = anchorChanges.reduce((sum, utxo) => sum + utxo.amount, 0);
}
let tableHTML = `
<div class="category-section" id="${categoryName}">
<div class="category-header ${categoryName}">
<h2>${categoryLabel}</h2>
<div class="category-stats">
<span><strong>Nombre :</strong> ${utxos.length.toLocaleString('fr-FR')}</span>
<span><strong>Montant total :</strong> ${formatBTC(totalAmount)} (${totalSats.toLocaleString('fr-FR')} ✅)</span>
${isChanges && anchorChangesCount > 0 ? `<span><strong>Changes d'ancrage :</strong> ${anchorChangesCount} (${formatBTC(anchorChangesAmount)})</span>` : ''}
</div>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>Transaction ID</th>
<th>Vout</th>
`;
if (isAnchors) {
tableHTML += `
<th>Numéro de bloc</th>
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (✅)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th>Date</th>
<th class="sortable-header" onclick="toggleSort('${categoryName}', 'confirmed')">Confirmé${getSortArrow('confirmed', state.sortColumn, state.sortDirection)}</th>
<th>Statut</th>
`;
} else if (isBlocRewards) {
tableHTML += `
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (🛡)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th>Date</th>
<th class="sortable-header" onclick="toggleSort('${categoryName}', 'confirmed')">Confirmé${getSortArrow('confirmed', state.sortColumn, state.sortDirection)}</th>
<th>Statut</th>
`;
} else {
// Pour la section changes, ajouter une colonne pour indiquer si c'est un change d'ancrage
if (categoryName === 'changes') {
tableHTML += `
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (🛡)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (✅)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th>Date</th>
<th class="sortable-header" onclick="toggleSort('${categoryName}', 'confirmed')">Confirmé${getSortArrow('confirmed', state.sortColumn, state.sortDirection)}</th>
<th>Type</th>
<th>Statut</th>
`;
} else {
tableHTML += `
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (🛡)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (✅)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th>Date</th>
<th class="sortable-header" onclick="toggleSort('${categoryName}', 'confirmed')">Confirmé${getSortArrow('confirmed', state.sortColumn, state.sortDirection)}</th>
<th>Statut</th>
`;
}
}
tableHTML += `
</tr>
</thead>
<tbody>
`;
paginatedUtxos.forEach((utxo) => {
const mempoolUrl = 'https://mempool.4nkweb.com/fr';
const txLink = `${mempoolUrl}/tx/${utxo.txid}`;
const amountSats = Math.round(utxo.amount * 100000000);
const amountBTC = Math.round(utxo.amount);
tableHTML += '<tr>';
tableHTML += `<td class="txid-cell"><a href="${txLink}" target="_blank" rel="noopener noreferrer" class="txid-link">${utxo.txid}</a></td>`;
tableHTML += `<td>${utxo.vout}</td>`;
if (isAnchors) {
tableHTML += `<td>${utxo.blockHeight !== null && utxo.blockHeight !== undefined ? utxo.blockHeight.toLocaleString('fr-FR') : '-'}</td>`;
tableHTML += `<td class="amount-cell">${amountSats.toLocaleString('fr-FR')} ✅</td>`;
// Date pour les ancrages
if (utxo.blockTime) {
const date = new Date(utxo.blockTime * 1000);
tableHTML += `<td>${date.toLocaleString('fr-FR', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })}</td>`;
} else {
tableHTML += '<td>-</td>';
}
} else if (isBlocRewards) {
tableHTML += `<td class="amount-cell">${amountBTC.toLocaleString('fr-FR')} 🛡</td>`;
if (utxo.blockTime) {
const date = new Date(utxo.blockTime * 1000);
tableHTML += `<td>${date.toLocaleString('fr-FR', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })}</td>`;
} else {
tableHTML += '<td>-</td>';
}
} else {
tableHTML += `<td class="amount-cell">${amountBTC.toLocaleString('fr-FR')} 🛡</td>`;
tableHTML += `<td class="amount-cell">${amountSats.toLocaleString('fr-FR')} ✅</td>`;
// Date pour les changes
if (utxo.blockTime) {
const date = new Date(utxo.blockTime * 1000);
tableHTML += `<td>${date.toLocaleString('fr-FR', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })}</td>`;
} else {
tableHTML += '<td>-</td>';
}
}
// Colonne Confirmé : coche si confirmé, sinon vide
const isConfirmed = (utxo.confirmations || 0) > 0;
tableHTML += `<td style="text-align: center;">${isConfirmed ? '✓' : ''}</td>`;
// Colonne Type (uniquement pour les changes)
if (categoryName === 'changes') {
const changeType = utxo.isAnchorChange ? '🔗 Transaction d\'ancrage' : '🔄 Transaction normale';
tableHTML += `<td>${changeType}</td>`;
}
// Colonne Statut (— si source fichier, pas de RPC)
let statusText = '';
let statusClass = '';
if (utxo.fromFile) {
statusText = '—';
statusClass = '';
} else if (utxo.isSpentOnchain) {
statusText = 'Dépensé onchain';
statusClass = 'status-spent';
} else if (utxo.isLockedInMutex) {
statusText = 'Verrouillé';
statusClass = 'status-locked';
} else {
statusText = 'Disponible';
statusClass = 'status-available';
}
tableHTML += `<td class="${statusClass}">${statusText}</td>`;
tableHTML += '</tr>';
});
tableHTML += `
</tbody>
</table>
</div>
`;
// Ajouter la pagination
if (totalPages > 1) {
tableHTML += `
<div class="pagination">
<button class="pagination-button" onclick="changePage('${categoryName}', ${state.currentPage - 1})" ${state.currentPage === 1 ? 'disabled' : ''}>← Précédent</button>
<span class="pagination-info">Page ${state.currentPage} / ${totalPages} (${sortedUtxos.length.toLocaleString('fr-FR')} UTXOs)</span>
<button class="pagination-button" onclick="changePage('${categoryName}', ${state.currentPage + 1})" ${state.currentPage === totalPages ? 'disabled' : ''}>Suivant →</button>
</div>
`;
}
tableHTML += `
</div>
`;
return tableHTML;
}
async function loadSmallUtxosInfo() {
const button = document.getElementById('consolidate-button');
if (!button) return;
try {
const response = await fetch(`${API_BASE_URL}/api/utxo/small-info`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
const count = data.count || 0;
if (count > 0) {
const anchorCount = Math.max(0, count - 1);
button.textContent = `Consolider la capacité d'ancrage résiduelle - ${anchorCount.toLocaleString('fr-FR')} ancrages)`;
button.disabled = false;
} else {
button.textContent = 'Aucun UTXO à consolider';
button.disabled = true;
}
} catch (error) {
console.error('Error loading small UTXOs info:', error);
button.textContent = 'Erreur de chargement';
button.disabled = true;
}
}
async function loadUtxoList() {
const contentDiv = document.getElementById('content');
const refreshButton = document.querySelector('.refresh-button');
const progressSection = document.getElementById('progress-section');
const progressBarFill = document.getElementById('progress-bar-fill');
const progressPercent = document.getElementById('progress-percent');
const progressStats = document.getElementById('progress-stats');
refreshButton.disabled = true;
contentDiv.innerHTML = '';
utxosFromFile = true;
progressSection.style.display = 'block';
progressBarFill.style.width = '0%';
progressPercent.textContent = '0 %';
progressStats.textContent = '0 ligne(s) parsée(s)';
loadSmallUtxosInfo();
try {
const response = await fetch(`${API_BASE_URL}/api/utxo/list.txt`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const contentLength = response.headers.get('Content-Length');
const totalBytes = contentLength ? parseInt(contentLength, 10) : 0;
const lastModified = response.headers.get('Last-Modified');
if (lastModified && document.getElementById('source-note')) {
document.getElementById('source-note').textContent =
'Source : fichier utxo_list.txt (peut ne pas être à jour). Dernière modif. : ' + new Date(lastModified).toLocaleString('fr-FR');
}
const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8');
let received = 0;
let buffer = '';
let lineCount = 0;
const blocRewards = [];
const anchors = [];
const changes = [];
const fees = [];
const minAnchorAmount = 2000 / 100000000;
for (;;) {
const { done, value } = await reader.read();
if (value && value.length) {
received += value.length;
buffer += decoder.decode(value, { stream: !done });
}
const lines = buffer.split('\n');
buffer = lines.pop() || '';
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed) continue;
const utxo = parseUtxoLine(trimmed);
if (!utxo) continue;
lineCount++;
if (utxo.category === 'bloc_rewards') blocRewards.push(utxo);
else if (utxo.category === 'anchor' || utxo.category === 'ancrages') anchors.push(utxo);
else if (utxo.category === 'change' || utxo.category === 'changes') changes.push(utxo);
else if (utxo.category === 'fee') fees.push(utxo);
}
const pct = totalBytes > 0 ? Math.min(100, Math.round((received / totalBytes) * 100)) : (done ? 100 : 0);
progressBarFill.style.width = pct + '%';
progressPercent.textContent = pct + ' %';
progressStats.textContent = lineCount.toLocaleString('fr-FR') + ' ligne(s) parsée(s)';
if (done) break;
}
if (buffer.trim()) {
const utxo = parseUtxoLine(buffer.trim());
if (utxo) {
lineCount++;
if (utxo.category === 'bloc_rewards') blocRewards.push(utxo);
else if (utxo.category === 'anchor' || utxo.category === 'ancrages') anchors.push(utxo);
else if (utxo.category === 'change' || utxo.category === 'changes') changes.push(utxo);
else if (utxo.category === 'fee') fees.push(utxo);
}
}
progressBarFill.style.width = '100%';
progressPercent.textContent = '100 %';
progressStats.textContent = lineCount.toLocaleString('fr-FR') + ' ligne(s) parsée(s)';
const total = blocRewards.length + anchors.length + changes.length + fees.length;
const availableForAnchor = anchors.filter(u =>
u.amount >= minAnchorAmount && (u.confirmations || 0) > 0
).length;
const totalAmount = blocRewards.reduce((s, u) => s + u.amount, 0) +
anchors.reduce((s, u) => s + u.amount, 0) +
changes.reduce((s, u) => s + u.amount, 0);
currentUtxosData = { blocRewards, anchors, changes, fees };
document.getElementById('utxo-count').textContent = total.toLocaleString('fr-FR');
document.getElementById('available-for-anchor').textContent = availableForAnchor.toLocaleString('fr-FR');
document.getElementById('total-amount').textContent = formatBTC(totalAmount);
updateLastUpdateTime();
progressSection.style.display = 'none';
document.getElementById('navigation').style.display = 'flex';
let html = '';
html += renderTable(blocRewards, 'bloc-rewards', '💰 Bloc Rewards (Récompenses de minage)');
html += renderTable(anchors, 'ancrages', '🔗 Ancrages (Transactions d\'ancrage)');
html += renderTable(changes, 'changes', '🔄 Changes (Monnaie de retour)');
html += renderFeesTable(fees, 'fees', '💸 Frais (Transactions d\'ancrage)');
contentDiv.innerHTML = html;
} catch (error) {
console.error('Error loading UTXO list:', error);
progressSection.style.display = 'none';
contentDiv.innerHTML = `<div class="error">Erreur lors du chargement de la liste des UTXO : ${error.message}</div>`;
} finally {
refreshButton.disabled = false;
loadSmallUtxosInfo();
}
}
function parseUtxoLine(line) {
const parts = line.split(';');
if (parts.length < 6) return null;
let category, txid, vout, amount, confirmations, isAnchorChange, blockTimeRaw;
if (parts.length >= 7 && !isNaN(parseFloat(parts[3]))) {
[category, txid, vout, amount, confirmations, isAnchorChange, blockTimeRaw] = parts;
} else {
[category, txid, vout, , amount, confirmations] = parts;
isAnchorChange = parts.length > 6 ? parts[6] === 'true' : false;
blockTimeRaw = parts.length > 7 ? parts[7] : null;
}
const c = (category || '').trim();
const allowed = ['bloc_rewards', 'anchor', 'ancrages', 'change', 'changes', 'fee'];
if (!allowed.includes(c)) return null;
const blockTime = (blockTimeRaw && blockTimeRaw.trim()) ? (parseInt(blockTimeRaw, 10) || null) : null;
return {
txid: (txid || '').trim(),
vout: parseInt(vout, 10) || 0,
amount: parseFloat(amount) || 0,
confirmations: parseInt(confirmations, 10) || 0,
blockHeight: null,
blockTime,
isAnchorChange: isAnchorChange === 'true' || isAnchorChange === true,
category: c,
isSpentOnchain: false,
isLockedInMutex: false,
fromFile: true,
};
}
function formatBTC(btc) {
if (btc === 0) return '0 🛡';
// Arrondir sans décimales
const roundedBTC = Math.round(btc);
if (roundedBTC === 0 && btc > 0) {
// Si arrondi à 0 mais qu'il y a un montant, afficher en sats
const sats = Math.round(btc * 100000000);
return `${sats.toLocaleString('fr-FR')}`;
}
return `${roundedBTC.toLocaleString('fr-FR')} 🛡`;
}
function renderFeesTable(fees, categoryName, categoryLabel) {
if (fees.length === 0) {
return `
<div class="category-section" id="${categoryName}">
<div class="category-header ${categoryName}">
<h2>${categoryLabel}</h2>
<div class="category-stats">
<span><strong>Nombre :</strong> 0</span>
<span><strong>Total des frais :</strong> 0 ✅</span>
</div>
</div>
<div class="empty-message">Aucune transaction avec frais onchain enregistrée.</div>
</div>
`;
}
const state = getSortState(categoryName);
// Paginer les fees
const totalPages = Math.ceil(fees.length / ITEMS_PER_PAGE);
const startIndex = (state.currentPage - 1) * ITEMS_PER_PAGE;
const endIndex = startIndex + ITEMS_PER_PAGE;
const paginatedFees = fees.slice(startIndex, endIndex);
const totalFees = fees.reduce((sum, fee) => sum + fee.fee, 0);
const totalFeesSats = Math.round(totalFees * 100000000);
let tableHTML = `
<div class="category-section" id="${categoryName}">
<div class="category-header ${categoryName}">
<h2>${categoryLabel}</h2>
<div class="category-stats">
<span><strong>Nombre :</strong> ${fees.length.toLocaleString('fr-FR')}</span>
<span><strong>Total des frais :</strong> ${formatBTC(totalFees)} (${totalFeesSats.toLocaleString('fr-FR')} ✅)</span>
</div>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>Transaction ID</th>
<th>Frais (BTC)</th>
<th>Frais (✅)</th>
<th>Change Amount</th>
<th>Bloc</th>
<th>Date</th>
<th>Confirmé</th>
</tr>
</thead>
<tbody>
`;
paginatedFees.forEach((fee) => {
const mempoolUrl = 'https://mempool.4nkweb.com/fr';
const txLink = `${mempoolUrl}/tx/${fee.txid}`;
const feeSats = fee.fee_sats || Math.round(fee.fee * 100000000);
tableHTML += '<tr>';
tableHTML += `<td class="txid-cell"><a href="${txLink}" target="_blank" rel="noopener noreferrer" class="txid-link">${fee.txid}</a></td>`;
tableHTML += `<td class="amount-cell">${fee.fee.toFixed(8)}</td>`;
tableHTML += `<td class="amount-cell">${feeSats.toLocaleString('fr-FR')} ✅</td>`;
tableHTML += `<td class="amount-cell">${fee.changeAmount ? formatBTC(fee.changeAmount) : '-'}</td>`;
tableHTML += `<td>${fee.blockHeight !== null && fee.blockHeight !== undefined ? fee.blockHeight.toLocaleString('fr-FR') : '-'}</td>`;
if (fee.blockTime) {
const date = new Date(fee.blockTime * 1000);
tableHTML += `<td>${date.toLocaleString('fr-FR', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })}</td>`;
} else {
tableHTML += '<td>-</td>';
}
// Colonne Confirmé : coche si confirmé, sinon vide
const isConfirmed = (fee.confirmations || 0) > 0;
tableHTML += `<td style="text-align: center;">${isConfirmed ? '✓' : ''}</td>`;
tableHTML += '</tr>';
});
tableHTML += `
</tbody>
</table>
</div>
</div>
`;
return tableHTML;
}
function updateLastUpdateTime() {
const now = new Date();
document.getElementById('last-update').textContent = now.toLocaleString('fr-FR');
}
function toggleSort(categoryName, column) {
const state = getSortState(categoryName);
if (state.sortColumn === column) {
state.sortDirection = state.sortDirection === 'asc' ? 'desc' : 'asc';
} else {
state.sortColumn = column;
state.sortDirection = 'desc';
}
state.currentPage = 1; // Reset to first page when sorting
loadUtxoList();
}
function changePage(categoryName, page) {
const state = getSortState(categoryName);
let items = [];
if (categoryName === 'fees') {
items = currentUtxosData.fees || [];
} else {
items = getCurrentUtxos(categoryName);
}
const totalPages = Math.ceil(items.length / ITEMS_PER_PAGE);
if (page >= 1 && page <= totalPages) {
state.currentPage = page;
loadUtxoList();
}
}
function getCurrentUtxos(categoryName) {
if (categoryName === 'bloc-rewards') return currentUtxosData.blocRewards || [];
if (categoryName === 'ancrages') return currentUtxosData.anchors || [];
if (categoryName === 'changes') return currentUtxosData.changes || [];
if (categoryName === 'fees') return currentUtxosData.fees || [];
return [];
}
async function consolidateSmallUtxos() {
const button = document.querySelector('.consolidate-button');
const originalText = button.textContent;
button.disabled = true;
button.textContent = '⏳ Consolidation en cours...';
try {
const response = await fetch(`${API_BASE_URL}/api/utxo/consolidate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
}
const result = await response.json();
if (result.success) {
alert(`Consolidation réussie!\n\nTransaction ID: ${result.txid}\nUTXOs consolidés: ${result.inputCount}\nMontant total: ${formatBTC(result.totalInputAmount)}\nChange: ${formatBTC(result.changeAmount)}\nFrais estimés: ${formatBTC(result.estimatedFee)}`);
// Recharger la liste après consolidation
setTimeout(() => {
loadUtxoList();
}, 2000);
} else {
throw new Error(result.error || 'Consolidation échouée');
}
} catch (error) {
console.error('Error consolidating UTXOs:', error);
alert(`Erreur lors de la consolidation: ${error.message}`);
} finally {
button.disabled = false;
button.textContent = originalText;
}
}
</script>
<footer>
<p>Bitcoin Ancrage Dashboard - Équipe 4NK</p>
<a href="https://git.4nkweb.com/4nk/anchorage_layer_simple.git" target="_blank" rel="noopener noreferrer" class="git-link" title="Voir le code source sur Git">
<svg class="git-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<path d="M23.546 10.93L13.067.452c-.604-.603-1.582-.603-2.188 0L8.708 2.627l2.76 2.76c.645-.215 1.379-.07 1.889.441.516.515.658 1.258.438 1.9l2.658 2.66c.645-.223 1.387-.083 1.9.435.721.72.721 1.884 0 2.604-.719.719-1.881.719-2.6 0-.539-.541-.674-1.337-.404-1.996L12.86 8.955v6.525c.176.086.342.203.488.348.713.721.713 1.883 0 2.6-.719.721-1.884.721-2.599 0-.72-.719-.72-1.879 0-2.598.182-.18.387-.316.605-.406V8.835c-.217-.091-.424-.222-.6-.401-.545-.545-.676-1.342-.396-2.011L7.636 3.7.45 10.881c-.6.605-.6 1.584 0 2.189l10.48 10.477c.604.604 1.582.604 2.186 0l10.43-10.43c.605-.603.605-1.582 0-2.187"/>
</svg>
</a>
</footer>
</body>
</html>