**Motivations:** - Fix insufficient UTXO amount error in anchor API - Ensure continuous availability of usable UTXOs for anchor transactions - Improve anchor transaction reliability and efficiency **Root causes:** - UTXO selection logic was too restrictive, rejecting UTXOs larger than needed - No automatic provisioning of new usable UTXOs when existing ones were not suitable - Algorithm prevented efficient use of available UTXOs **Correctifs:** - Refactored createAnchorTransaction() to provision 7 UTXOs of 2500 sats on each anchor - Use single large UTXO to create 1 anchor output + 7 provisioning outputs + change - Simplified UTXO selection: single large UTXO per transaction instead of multiple small ones - Added UTXO provisioning logic in signet-dashboard - Enhanced Bitcoin RPC methods in both api-anchorage and signet-dashboard - Added documentation in fixKnowledge/api-anchorage-utxo-provisioning.md **Evolutions:** - Enhanced signet-dashboard with new pages (hash-list, utxo-list, join-signet, api-docs) - Improved Bitcoin RPC client with better error handling and UTXO management - Added cache files for hash and UTXO lists - Updated api-faucet with improved server configuration - Enhanced anchor count tracking **Pages affectées:** - api-anchorage/src/bitcoin-rpc.js: Complete refactor of createAnchorTransaction() - api-anchorage/src/routes/anchor.js: Enhanced anchor route - api-anchorage/src/server.js: Server configuration updates - signet-dashboard/src/bitcoin-rpc.js: Added comprehensive Bitcoin RPC client - signet-dashboard/src/server.js: Enhanced server with new routes - signet-dashboard/public/: Added new HTML pages and updated app.js - api-faucet/src/server.js: Server improvements - api-faucet/README.md: Documentation updates - fixKnowledge/api-anchorage-utxo-provisioning.md: New documentation - anchor_count.txt, hash_list.txt, utxo_list.txt: Tracking files
540 lines
21 KiB
HTML
540 lines
21 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;
|
|
}
|
|
.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;
|
|
}
|
|
.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>
|
|
<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>
|
|
</div>
|
|
|
|
<script>
|
|
const API_BASE_URL = window.location.origin;
|
|
|
|
// Charger la liste au chargement de la page
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
loadUtxoList();
|
|
});
|
|
|
|
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 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>
|
|
<th>Adresse</th>
|
|
`;
|
|
|
|
if (isAnchors) {
|
|
tableHTML += `
|
|
<th>Numéro de bloc</th>
|
|
<th style="text-align: right;">Montant (✅)</th>
|
|
<th>Confirmations</th>
|
|
<th>Statut</th>
|
|
`;
|
|
} else if (isBlocRewards) {
|
|
tableHTML += `
|
|
<th style="text-align: right;">Montant (🛡)</th>
|
|
<th>Date</th>
|
|
<th>Confirmations</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 style="text-align: right;">Montant (🛡)</th>
|
|
<th style="text-align: right;">Montant (✅)</th>
|
|
<th>Confirmations</th>
|
|
<th>Type</th>
|
|
<th>Statut</th>
|
|
`;
|
|
} else {
|
|
tableHTML += `
|
|
<th style="text-align: right;">Montant (🛡)</th>
|
|
<th style="text-align: right;">Montant (✅)</th>
|
|
<th>Confirmations</th>
|
|
<th>Statut</th>
|
|
`;
|
|
}
|
|
}
|
|
|
|
tableHTML += `
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
utxos.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>`;
|
|
tableHTML += `<td class="address-cell">${utxo.address || '-'}</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>`;
|
|
} 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>`;
|
|
}
|
|
|
|
tableHTML += `<td>${utxo.confirmations.toLocaleString('fr-FR')}</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
|
|
let statusText = '';
|
|
let statusClass = '';
|
|
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>
|
|
</div>
|
|
`;
|
|
|
|
return tableHTML;
|
|
}
|
|
|
|
async function loadUtxoList() {
|
|
const contentDiv = document.getElementById('content');
|
|
const refreshButton = document.querySelector('.refresh-button');
|
|
|
|
refreshButton.disabled = true;
|
|
contentDiv.innerHTML = '<div class="loading">Chargement des UTXO...</div>';
|
|
|
|
try {
|
|
const response = await fetch(`${API_BASE_URL}/api/utxo/list`);
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
const counts = data.counts || {};
|
|
const blocRewards = data.blocRewards || [];
|
|
const anchors = data.anchors || [];
|
|
const changes = data.changes || [];
|
|
const fees = data.fees || [];
|
|
|
|
document.getElementById('utxo-count').textContent = counts.total.toLocaleString('fr-FR');
|
|
document.getElementById('available-for-anchor').textContent = (counts.availableForAnchor || 0).toLocaleString('fr-FR');
|
|
|
|
// Calculer le montant total
|
|
const totalAmount = blocRewards.reduce((sum, utxo) => sum + utxo.amount, 0) +
|
|
anchors.reduce((sum, utxo) => sum + utxo.amount, 0) +
|
|
changes.reduce((sum, utxo) => sum + utxo.amount, 0);
|
|
document.getElementById('total-amount').textContent = formatBTC(totalAmount);
|
|
|
|
updateLastUpdateTime();
|
|
|
|
// Afficher la barre de navigation
|
|
document.getElementById('navigation').style.display = 'flex';
|
|
|
|
// Afficher les 4 listes
|
|
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);
|
|
contentDiv.innerHTML = `<div class="error">Erreur lors du chargement de la liste des UTXO : ${error.message}</div>`;
|
|
} finally {
|
|
refreshButton.disabled = false;
|
|
}
|
|
}
|
|
|
|
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 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 Address</th>
|
|
<th>Change Amount</th>
|
|
<th>Bloc</th>
|
|
<th>Date</th>
|
|
<th>Confirmations</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
fees.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="address-cell">${fee.changeAddress || '-'}</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>';
|
|
}
|
|
tableHTML += `<td>${fee.confirmations.toLocaleString('fr-FR')}</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');
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|