ncantu fe7f49b6cd Update API anchorage, services, and website skeleton
**Motivations:**
- Synchronisation des modifications sur l'API anchorage, les services et le website skeleton
- Ajout de scripts de monitoring et de diagnostic pour l'API anchorage
- Documentation des problèmes de mutex et de provisioning UTXO

**Root causes:**
- N/A (commit de synchronisation)

**Correctifs:**
- N/A (commit de synchronisation)

**Evolutions:**
- Ajout de scripts de monitoring et de diagnostic pour l'API anchorage
- Amélioration de la gestion des mutex et des UTXOs
- Mise à jour de la documentation

**Pages affectées:**
- api-anchorage/src/bitcoin-rpc.js
- api-anchorage/src/routes/anchor.js
- api-anchorage/src/routes/health.js
- api-anchorage/src/server.js
- api-anchorage/README-MONITORING.md
- api-anchorage/cleanup-stale-locks.mjs
- api-anchorage/diagnose.mjs
- api-anchorage/unlock-utxos.mjs
- service-login-verify/src/persistentNonceCache.ts
- signet-dashboard/src/server.js
- signet-dashboard/public/*
- userwallet/src/hooks/useChannel.ts
- userwallet/src/services/relayNotificationService.ts
- userwallet/src/utils/defaultContract.ts
- website-skeleton/src/*
- docs/DOMAINS_AND_PORTS.md
- docs/INTERFACES.md
- features/*
- fixKnowledge/*
2026-01-28 15:11:59 +01:00

569 lines
22 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 Hash Ancrés - Bitcoin Ancrage Dashboard</title>
<link rel="stylesheet" href="styles.css">
<style>
.hash-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: #6ec6ff;
text-decoration: none;
}
.header-section .back-link:hover {
text-decoration: underline;
}
.info-section {
background: var(--card-background);
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
border: 1px solid var(--border-color);
}
.info-section p {
margin: 5px 0;
}
.table-container {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
background: var(--card-background);
box-shadow: 0 2px 4px rgba(0,0,0,0.3);
border: 1px solid var(--border-color);
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid var(--border-color);
}
th {
background: var(--card-background);
color: var(--text-color);
font-weight: bold;
position: sticky;
top: 0;
}
tr:hover {
background: rgba(255, 255, 255, 0.05);
}
.hash-cell {
font-family: monospace;
font-size: 0.9em;
word-break: break-all;
}
.txid-cell {
font-family: monospace;
font-size: 0.9em;
}
.txid-link {
color: #6ec6ff;
text-decoration: none;
}
.txid-link:hover {
text-decoration: underline;
}
.loading {
text-align: center;
padding: 40px;
font-size: 1.2em;
color: var(--text-color);
}
.error {
background: rgba(220, 53, 69, 0.2);
color: #ff6b6b;
padding: 15px;
border-radius: 5px;
margin: 20px 0;
border: 1px solid #dc3545;
}
.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;
}
.search-section {
margin-bottom: 20px;
padding: 15px;
background: var(--card-background);
border-radius: 5px;
border: 1px solid var(--border-color);
}
.search-input {
width: 100%;
max-width: 500px;
padding: 10px;
font-size: 1em;
border: 1px solid var(--border-color);
border-radius: 5px;
font-family: monospace;
background-color: var(--card-background);
color: var(--text-color);
}
.pagination {
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
margin-top: 20px;
padding: 15px;
}
.pagination button {
background: #007bff;
color: white;
border: none;
padding: 8px 15px;
border-radius: 5px;
cursor: pointer;
font-size: 0.9em;
}
.pagination button:hover:not(:disabled) {
background: #0056b3;
}
.pagination button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.pagination-info {
padding: 0 15px;
color: var(--text-color);
}
.confirmed-check {
text-align: center;
font-size: 1.2em;
}
.confirmed-check.yes {
color: #28a745;
}
.confirmed-check.no {
color: #dc3545;
}
.health-section {
background: var(--card-background);
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
border: 1px solid var(--border-color);
}
.health-status {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 15px;
}
.health-item {
padding: 10px;
background: rgba(255, 255, 255, 0.05);
border-radius: 5px;
border: 1px solid var(--border-color);
}
.health-item label {
display: block;
font-weight: bold;
margin-bottom: 5px;
color: var(--text-color);
}
.health-item .value {
font-size: 1.1em;
}
.health-item .value.ok {
color: #28a745;
}
.health-item .value.warning {
color: #ffc107;
}
.health-item .value.error {
color: #dc3545;
}
.unlock-button {
background: #dc3545;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
}
.unlock-button:hover {
background: #c82333;
}
.unlock-button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.stale-locks-list {
margin-top: 10px;
padding: 10px;
background: rgba(220, 53, 69, 0.1);
border-radius: 5px;
border: 1px solid #dc3545;
}
.stale-locks-list h4 {
margin-top: 0;
color: #dc3545;
}
.stale-lock-item {
padding: 5px;
font-family: monospace;
font-size: 0.9em;
}
</style>
</head>
<body>
<div class="container">
<div class="hash-list-container">
<div class="header-section">
<a href="/" class="back-link">← Retour au dashboard</a>
<h1>Liste des Hash Ancrés</h1>
<div class="info-section">
<p><strong>Total de hash ancrés :</strong> <span id="hash-count">-</span></p>
<p><strong>Dernière mise à jour :</strong> <span id="last-update">-</span></p>
<button class="refresh-button" onclick="loadHashList()">Actualiser</button>
</div>
</div>
<div class="search-section">
<label for="hash-search" style="display: block; margin-bottom: 8px; font-weight: bold;">Rechercher un hash :</label>
<input type="text" id="hash-search" class="search-input" placeholder="Entrez un hash (64 caractères hexadécimaux)..." oninput="filterHashList()">
</div>
<div class="health-section" style="background: var(--card-background); padding: 15px; border-radius: 5px; margin-bottom: 20px; border: 1px solid var(--border-color);">
<h2 style="margin-top: 0; margin-bottom: 15px;">État de l'API d'Ancrage</h2>
<div id="health-status">Chargement de l'état...</div>
<div style="margin-top: 15px;">
<button id="unlock-utxos-button" class="unlock-button" onclick="unlockUtxos()" style="display: none;">Déverrouiller les UTXOs</button>
<button id="refresh-health-button" class="refresh-button" onclick="loadHealthStatus()" style="margin-left: 10px;">Actualiser l'état</button>
</div>
</div>
<div id="content">
<div class="loading">Chargement des hash...</div>
</div>
<div id="pagination" class="pagination" style="display: none;"></div>
</div>
</div>
<script>
const API_BASE_URL = window.location.origin;
const ITEMS_PER_PAGE = 50;
let allHashes = [];
let filteredHashes = [];
let currentPage = 1;
// Charger la liste au chargement de la page
document.addEventListener('DOMContentLoaded', () => {
loadHashList();
loadHealthStatus();
});
async function loadHashList() {
const contentDiv = document.getElementById('content');
const refreshButton = document.querySelector('.refresh-button');
refreshButton.disabled = true;
contentDiv.innerHTML = '<div class="loading">Chargement des hash...</div>';
try {
// Charger tous les hashes avec pagination (limite de 10000 pour compatibilité)
let allHashesLoaded = [];
let currentPage = 1;
const limit = 1000;
let hasMore = true;
while (hasMore) {
const response = await fetch(`${API_BASE_URL}/api/hash/list?page=${currentPage}&limit=${limit}`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
allHashesLoaded = allHashesLoaded.concat(data.hashes || []);
if (data.hashes.length < limit || currentPage >= data.totalPages) {
hasMore = false;
} else {
currentPage++;
}
}
allHashes = allHashesLoaded;
document.getElementById('hash-count').textContent = allHashes.length.toLocaleString('fr-FR');
updateLastUpdateTime();
// Appliquer le filtre de recherche s'il existe
filterHashList();
} catch (error) {
console.error('Error loading hash list:', error);
contentDiv.innerHTML = `<div class="error">Erreur lors du chargement de la liste des hash : ${error.message}</div>`;
} finally {
refreshButton.disabled = false;
}
}
function filterHashList() {
const searchInput = document.getElementById('hash-search');
const searchTerm = searchInput ? searchInput.value.trim().toLowerCase() : '';
if (searchTerm === '') {
filteredHashes = allHashes;
} else {
// Filtrer par hash (recherche partielle)
filteredHashes = allHashes.filter((item) => {
return item.hash.toLowerCase().includes(searchTerm);
});
}
currentPage = 1;
renderTable();
}
function renderTable() {
const contentDiv = document.getElementById('content');
const paginationDiv = document.getElementById('pagination');
if (filteredHashes.length === 0) {
contentDiv.innerHTML = '<div class="info-section"><p>Aucun hash trouvé.</p></div>';
paginationDiv.style.display = 'none';
return;
}
// Calculer la pagination
const totalPages = Math.ceil(filteredHashes.length / ITEMS_PER_PAGE);
const startIndex = (currentPage - 1) * ITEMS_PER_PAGE;
const endIndex = Math.min(startIndex + ITEMS_PER_PAGE, filteredHashes.length);
const paginatedHashes = filteredHashes.slice(startIndex, endIndex);
// Générer le tableau
let tableHTML = '<div class="table-container"><table><thead><tr>';
tableHTML += '<th>Hash</th>';
tableHTML += '<th>Transaction ID</th>';
tableHTML += '<th>Hauteur du Bloc</th>';
tableHTML += '<th>Confirmé</th>';
tableHTML += '</tr></thead><tbody>';
paginatedHashes.forEach((item) => {
const mempoolUrl = 'https://mempool.4nkweb.com/fr';
const txLink = `${mempoolUrl}/tx/${item.txid}`;
const isConfirmed = (item.confirmations || 0) > 0;
tableHTML += '<tr>';
tableHTML += `<td class="hash-cell">${item.hash}</td>`;
tableHTML += `<td class="txid-cell"><a href="${txLink}" target="_blank" rel="noopener noreferrer" class="txid-link">${item.txid}</a></td>`;
tableHTML += `<td>${item.blockHeight !== null ? item.blockHeight.toLocaleString('fr-FR') : '-'}</td>`;
tableHTML += `<td class="confirmed-check ${isConfirmed ? 'yes' : 'no'}">${isConfirmed ? '✓' : '✗'}</td>`;
tableHTML += '</tr>';
});
tableHTML += '</tbody></table></div>';
contentDiv.innerHTML = tableHTML;
// Générer la pagination
if (totalPages > 1) {
let paginationHTML = '';
// Bouton précédent
paginationHTML += `<button onclick="changePage(${currentPage - 1})" ${currentPage === 1 ? 'disabled' : ''}>Précédent</button>`;
// Informations de pagination
paginationHTML += `<span class="pagination-info">Page ${currentPage} sur ${totalPages} (${filteredHashes.length.toLocaleString('fr-FR')} hash${filteredHashes.length > 1 ? 'es' : ''})</span>`;
// Bouton suivant
paginationHTML += `<button onclick="changePage(${currentPage + 1})" ${currentPage === totalPages ? 'disabled' : ''}>Suivant</button>`;
paginationDiv.innerHTML = paginationHTML;
paginationDiv.style.display = 'flex';
} else {
paginationDiv.style.display = 'none';
}
}
function changePage(page) {
const totalPages = Math.ceil(filteredHashes.length / ITEMS_PER_PAGE);
if (page >= 1 && page <= totalPages) {
currentPage = page;
renderTable();
// Scroller en haut du tableau
document.getElementById('content').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
function updateLastUpdateTime() {
const now = new Date();
document.getElementById('last-update').textContent = now.toLocaleString('fr-FR');
}
async function loadHealthStatus() {
const healthDiv = document.getElementById('health-status');
const unlockButton = document.getElementById('unlock-utxos-button');
const refreshButton = document.getElementById('refresh-health-button');
refreshButton.disabled = true;
healthDiv.innerHTML = '<div style="text-align: center; padding: 20px; font-size: 1em; color: var(--text-color);">Chargement de l\'état...</div>';
try {
// Utiliser l'endpoint proxy du dashboard
const response = await fetch(`${API_BASE_URL}/api/anchor/health/detailed`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const health = await response.json();
let html = '<div class="health-status">';
// État général
const statusClass = health.ok ? 'ok' : 'error';
html += `<div class="health-item">
<label>État général</label>
<div class="value ${statusClass}">${health.ok ? '✓ OK' : '✗ Problème'}</div>
</div>`;
// Mutex
const mutexClass = health.mutex.locked ? 'warning' : 'ok';
html += `<div class="health-item">
<label>Mutex</label>
<div class="value ${mutexClass}">
${health.mutex.locked ? '🔒 Verrouillé' : '✓ Libre'}
${health.mutex.waiting > 0 ? `(${health.mutex.waiting} en attente)` : ''}
</div>
</div>`;
// UTXOs verrouillés
const utxosClass = health.utxos.locked === 0 ? 'ok' : (health.utxos.locked > 10 ? 'error' : 'warning');
html += `<div class="health-item">
<label>UTXOs verrouillés</label>
<div class="value ${utxosClass}">${health.utxos.locked}</div>
</div>`;
// UTXOs stale
if (health.utxos.stale_locks > 0) {
html += `<div class="health-item">
<label>UTXOs stale (>10 min)</label>
<div class="value error">${health.utxos.stale_locks}</div>
</div>`;
}
// Bitcoin
const bitcoinClass = health.bitcoin.connected ? 'ok' : 'error';
html += `<div class="health-item">
<label>Bitcoin</label>
<div class="value ${bitcoinClass}">
${health.bitcoin.connected ? '✓ Connecté' : '✗ Déconnecté'}
${health.bitcoin.blocks > 0 ? ` (${health.bitcoin.blocks.toLocaleString('fr-FR')} blocs)` : ''}
</div>
</div>`;
html += '</div>';
// Afficher les détails des UTXOs stale
if (health.utxos.stale_locks > 0 && health.utxos.stale_locks_details.length > 0) {
html += '<div class="stale-locks-list">';
html += '<h4>UTXOs verrouillés depuis plus de 10 minutes :</h4>';
health.utxos.stale_locks_details.forEach(utxo => {
html += `<div class="stale-lock-item">${utxo.txid} vout:${utxo.vout} (${utxo.minutes_locked.toFixed(1)} min)</div>`;
});
html += '</div>';
}
// Afficher le timestamp
html += `<div style="margin-top: 10px; font-size: 0.9em; color: var(--text-color); opacity: 0.7;">
Dernière mise à jour : ${new Date(health.timestamp).toLocaleString('fr-FR')}
</div>`;
healthDiv.innerHTML = html;
// Afficher le bouton de déverrouillage si des UTXOs sont verrouillés
if (health.utxos.locked > 0) {
unlockButton.style.display = 'inline-block';
} else {
unlockButton.style.display = 'none';
}
} catch (error) {
console.error('Error loading health status:', error);
healthDiv.innerHTML = `<div class="error">Erreur lors du chargement de l'état : ${error.message}</div>`;
unlockButton.style.display = 'none';
} finally {
refreshButton.disabled = false;
}
}
async function unlockUtxos() {
const unlockButton = document.getElementById('unlock-utxos-button');
const originalText = unlockButton.textContent;
if (!confirm('Êtes-vous sûr de vouloir déverrouiller tous les UTXOs ? Cette action libère le mutex et peut affecter les opérations en cours.')) {
return;
}
unlockButton.disabled = true;
unlockButton.textContent = 'Déverrouillage en cours...';
try {
const response = await fetch(`${API_BASE_URL}/api/anchor/unlock-utxos`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.message || `HTTP error! status: ${response.status}`);
}
const result = await response.json();
alert(`${result.unlocked || 0} UTXO(s) déverrouillé(s) avec succès.`);
// Recharger l'état de santé
loadHealthStatus();
} catch (error) {
console.error('Error unlocking UTXOs:', error);
alert(`❌ Erreur lors du déverrouillage : ${error.message}`);
} finally {
unlockButton.disabled = false;
unlockButton.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>