#0
0.00000001 BSV
v© t²}®k/En<Ë̱A¬ cordQ text/html Mõ<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>(B)Lock Time Calculator</title>
<style>
body {
font-family: 'Courier New', Courier, monospace, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
text-align: center;
background-color: #f2f2f2;
padding: 5%
}
input,
button {
margin-top: 10px;
padding: 8px;
font-size: 16px;
}
#resultContainer {
margin-top: 20px;
font-size: 1.25em;
font-weight: bold;
}
#usdValueResult {
font-size: 1em;
color: green;
white-space: pre-line;
font-weight: lighter;
}
</style>
</head>
<body>
<div class="container">
<h1>(B)Lock Time Calculator</h1>
<input type="radio" id="blocks" name="timeFormat" value="blocks" checked />
<label for="blocks">Number of Blocks</label>
<input type="radio" id="minutes" name="timeFormat" value="minutes" />
<label for="minutes">Time in Days</label>
<div>
<input type="number" id="timeInput" min="0" placeholder="How long?" />
<button onclick="calculate()">Calculate</button>
</div>
<div id="resultContainer">
<p id="blocksResult"></p>
<p id="futureDateResult"></p>
<p id="timeResult"></p>
<p id="usdValueResult"></p>
</div>
</div>
<script>
let exchangeRate = 0;
let currentBlockHeight = 0;
window.onload = function () {
preload();
};
// Fetch the exchange rate and current block height when the page loads
function preload() {
getExchangeRate();
getCurrentBlockHeight();
}
async function getExchangeRate() {
const url = 'https://api.whatsonchain.com/v1/bsv/main/exchangerate';
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
const data = await response.json();
exchangeRate = parseFloat(data.rate);
console.log("Exchange rate fetched: ", exchangeRate);
} catch (error) {
console.error("Fetching exchange rate failed: ", error);
}
}
async function getCurrentBlockHeight() {
const url = 'https://api.whatsonchain.com/v1/bsv/main/chain/info';
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
const data = await response.json();
currentBlockHeight = parseInt(data.blocks, 10);
console.log("Current block height fetched: ", currentBlockHeight);
} catch (error) {
console.error("Fetching block height failed: ", error);
}
}
function calculate() {
const timeInput = document.getElementById('timeInput').value;
const format = document.querySelector('input[name="timeFormat"]:checked').value;
const blockDuration = 10;
if (format === 'blocks') {
calculateTimeFromBlocks(timeInput, blockDuration);
} else {
calculateBlocksFromTime(timeInput, blockDuration);
}
}
function calculateTimeFromBlocks(blocks, blockDuration) {
const minutes = blocks * blockDuration;
displayResults(blocks, minutes);
}
function calculateBlocksFromTime(days, blockDurationInMinutes) {
const minutes = days * 1440; // Convert days to minutes
const blocks = Math.ceil(minutes / blockDurationInMinutes);
displayResults(blocks, minutes);
}
function displayResults(blocks, minutes) {
const blocksResult = blocks + ' block(s)';
document.getElementById('blocksResult').textContent = blocksResult;
const hours = Math.floor(minutes / 60);
const remainingMinutes = minutes % 60;
const timeResult = hours + ' hour(s) and ' + remainingMinutes + ' minute(s)';
const now = new Date();
const futureDate = new Date(now.getTime() + minutes * 60000);
const futureDateResult = futureDate.toLocaleString();
const formattedTime = formatTime(now, futureDate);
document.getElementById('futureDateResult').textContent = `Future Date & Time: ${futureDateResult}`;
document.getElementById('timeResult').textContent = `Roughly ${formattedTime} from now`;
// Calculate the reward amount based on the current block height
const rewardAmount = calculateReward(currentBlockHeight, blocks);
// Calculate the total value in USD
const totalUSDValue = rewardAmount * exchangeRate;
const percentOfTotal = (rewardAmount / 21000000) * 100;
document.getElementById('usdValueResult').textContent
=
`Exchange rate: $${exchangeRate.toFixed(2)} || Current block height: ${currentBlockHeight}\n` +
`New coins mined in that time: ${rewardAmount.toFixed(2)}\n` +
`which is ${percentOfTotal.toFixed(6)}% of the total network,\n` +
`resulting in USD value: $${totalUSDValue.toFixed(2)}\n`;
}
function calculateReward(currentHeight, blocksToMine) {
let reward = 6.25; // Current reward
const halvingInterval = 210000;
let remainingBlocks = blocksToMine;
let totalReward = 0;
// Calculate reward while taking halvings into account
while (remainingBlocks > 0) {
let blocksUntilHalving = halvingInterval - (currentHeight % halvingInterval);
if (remainingBlocks < blocksUntilHalving) {
totalReward += remainingBlocks * reward;
break;
} else {
totalReward += blocksUntilHalving * reward;
remainingBlocks -= blocksUntilHalving;
currentHeight += blocksUntilHalving;
reward /= 2; // Halve the reward
}
}
return totalReward;
}
function formatTime(currentDate, futureDate) {
// Calculate the total difference in days
const diff = futureDate - currentDate;
const totalDays = Math.floor(diff / (1000 * 60 * 60 * 24));
// Using 30 days as the length of each month
const monthsRaw = Math.floor(totalDays / 30);
const years = Math.floor(monthsRaw / 12); // Convert every 12 months into a year
const months = monthsRaw % 12; // Remaining months after converting to years
const days = totalDays % 30; // Remaining days after accounting for full months
// Now calculate the hours and minutes
const hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
const minutes = Math.floor((diff / (1000 * 60)) % 60);
// Construct the formatted time string
let formattedTime = "";
if (years > 0) formattedTime += years + " year(s), ";
if (months > 0) formattedTime += months + " month(s), ";
if (days > 0) formattedTime += days + " day(s), ";
if (hours > 0) formattedTime += hours + " hour(s), ";
if (minutes > 0) formattedTime += minutes + " minute(s)";
return formattedTime.trim(); // Trim any extra whitespace
}
</script>
</body>
</html>h
https://whatsonchain.com/tx/92bdc7edb20af1f7b7a7b7b78f663b4708ff945ddf2a8e2fde0fef9c640b2b51