-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
129 lines (124 loc) · 4.94 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lightning Network Channel ID Decoder</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: white;
padding: 30px; /* Increased padding for a larger box */
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 500px; /* Increased max-width for a larger box */
text-align: center;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
padding: 10px;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #218838;
}
.result {
margin-top: 20px;
padding: 10px;
border: 1px solid #007bff;
border-radius: 5px;
background-color: #e9f7ff;
}
.explanation {
margin-top: 20px;
font-size: 14px;
color: #555;
text-align: left; /* Align text to the left for better readability */
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>Lightning Channel ID Decoder</h1>
<p class="explanation">
The Lightning Network (LN) uses short channel IDs as unique identifiers for payment channels.
This converter helps you transform a short channel ID into its corresponding components:
</p>
<ul class="explanation">
<li><strong>Block:</strong> The block height where the funding transaction of the channel was confirmed.</li>
<li><strong>Transaction:</strong> The transaction index within that block.</li>
<li><strong>Output:</strong> The output index of the funding transaction.</li>
</ul>
<p class="explanation">
For example, the short channel ID
<a href="https://mempool.space/lightning/channel/880174451395198976" target="_blank">880174451395198976</a>
is an identifier of a channel in LN gossip data. By using this converter, you can extract the block, transaction, and output information. This is what we see in various LN explorers.
</p>
<p class="explanation">
The result will be displayed in the format: <strong>(Block x Transaction x Output)</strong>, for example: <strong>(800514 x 3017 x 0)</strong>.
</p>
<p class="explanation">
For more details, refer to the <a href="https://github.com/lightning/bolts/blob/master/07-routing-gossip.md" target="_blank">Lightning Network documentation</a>.
</p>
<label for="channelId">Enter Channel ID (Decimal):</label>
<input type="text" id="channelId" placeholder="e.g., 880174451395198976">
<button onclick="convertChannelId()">Convert</button>
<div class="result" id="result" style="display:none;"></div>
</div>
<script>
function extractBlockTxOutput(idValue) {
const block = idValue >> 40n; // Extract block using BigInt
const tx = (idValue >> 16n) & 0xFFFFFFn; // Extract transaction using BigInt
const output = idValue & 0xFFFFn; // Extract output using BigInt
console.log(`ID Value: ${idValue}, Block: ${block}, Transaction: ${tx}, Output: ${output}`); // Debugging log
return { block, tx, output };
}
function convertChannelId() {
const input = document.getElementById('channelId').value.trim();
const idValue = BigInt(input); // Convert string to BigInt
// Check if the input is a valid number
if (!/^\d+$/.test(input)) {
alert("Please enter a valid decimal channel ID.");
return;
}
const { block, tx, output } = extractBlockTxOutput(idValue);
const resultDiv = document.getElementById('result');
resultDiv.style.display = 'block';
resultDiv.innerHTML = `
<strong>Results:</strong><br>
Block: ${block}<br>
Transaction: ${tx}<br>
Output: ${output}<br>
Block-TX-Output: (${block} x ${tx} x ${output})
`;
}
</script>
</body>
</html>