From 228be8e519d77d04a8d9332ab970e99a602afb46 Mon Sep 17 00:00:00 2001 From: gonefishing4422 <119458070+gonefishing4422@users.noreply.github.com> Date: Tue, 16 Apr 2024 22:53:28 -0500 Subject: [PATCH] Update getblockmnstx.js --- js/getblockmnstx.js | 210 ++++++++++++++++++++++++-------------------- 1 file changed, 115 insertions(+), 95 deletions(-) diff --git a/js/getblockmnstx.js b/js/getblockmnstx.js index 9f26445..1219e9e 100644 --- a/js/getblockmnstx.js +++ b/js/getblockmnstx.js @@ -1,105 +1,125 @@ - async function fetchBlockInfo(blockNumber) { - const [blockMNS, blockInfo] = await Promise.all([ - fetchBlockMNS(blockNumber), - fetchBlockTimestamp(blockNumber) - ]); - return { blockMNS, blockInfo }; - } +async function fetchBlockInfo(blockNumber) { + const [blockMNS, blockInfo] = await Promise.all([ + fetchBlockMNS(blockNumber), + fetchBlockTimestamp(blockNumber) + ]); + return { blockMNS, blockInfo }; +} - async function fetchBlockMNS(blockNumber) { - const response = await fetch('https://rpc.nosocoin.com:8078', { - method: 'POST', - headers: { - 'Origin': 'https://rpc.nosocoin.com', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - "jsonrpc": "2.0", - "method": "getblockmns", - "params": [blockNumber], - "id": 1 - }) - }); - const data = await response.json(); - return data.result[0]; - } +async function fetchBlockMNS(blockNumber) { + const response = await fetch('https://rpc.nosocoin.com:8078', { + method: 'POST', + headers: { + 'Origin': 'https://rpc.nosocoin.com', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + "jsonrpc": "2.0", + "method": "getblockmns", + "params": [blockNumber], + "id": 1 + }) + }); + const data = await response.json(); + return data.result[0]; +} - async function fetchBlockTimestamp(blockNumber) { - const response = await fetch('https://rpc.nosocoin.com:8078', { - method: 'POST', - headers: { - 'Origin': 'https://rpc.nosocoin.com', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - "jsonrpc": "2.0", - "method": "getblocksinfo", - "params": [blockNumber], - "id": 2 - }) - }); - const data = await response.json(); - return data.result[0]; - } +async function fetchBlockTimestamp(blockNumber) { + const response = await fetch('https://rpc.nosocoin.com:8078', { + method: 'POST', + headers: { + 'Origin': 'https://rpc.nosocoin.com', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + "jsonrpc": "2.0", + "method": "getblocksinfo", + "params": [blockNumber], + "id": 2 + }) + }); + const data = await response.json(); + return data.result[0]; +} - async function createTableFromBlockInfo(blockNumber) { - const { blockMNS, blockInfo } = await fetchBlockInfo(blockNumber); - const tableBody = document.getElementById('blockInfoBody'); - tableBody.innerHTML = ''; // Clear previous data +async function fetchMainnetInfo() { + const response = await fetch('https://rpc.nosocoin.com:8078', { + method: 'POST', + headers: { + 'Origin': 'https://rpc.nosocoin.com', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + "jsonrpc": "2.0", + "method": "getmainnetinfo", + "params": [], + "id": 3 + }) + }); + const data = await response.json(); + return data.result[0].lastblock; // Extract the last block number +} - const timestamp = new Date(blockInfo.timeend * 1000); // Convert Unix timestamp to milliseconds +async function createTableFromBlockInfo(blockNumber) { + const { blockMNS, blockInfo } = await fetchBlockInfo(blockNumber); + const tableBody = document.getElementById('blockInfoBody'); + tableBody.innerHTML = ''; // Clear previous data - blockMNS.addresses.split(',').forEach((address, index) => { - const row = tableBody.insertRow(); - row.classList.add('order-table-row'); // Add class to row - row.classList.add(index % 2 === 0 ? 'even' : 'odd'); // Add even/odd class based on index + const timestamp = new Date(blockInfo.timeend * 1000); // Convert Unix timestamp to milliseconds - const cellBlock = row.insertCell(0); - const cellTimestamp = row.insertCell(1); - const cellSender = row.insertCell(2); - const cellReceiver = row.insertCell(3); - const cellRewardAmount = row.insertCell(4); - const cellReference = row.insertCell(5); - const cellType = row.insertCell(6); + blockMNS.addresses.split(',').forEach((address, index) => { + const row = tableBody.insertRow(); + row.classList.add('order-table-row'); // Add class to row + row.classList.add(index % 2 === 0 ? 'even' : 'odd'); // Add even/odd class based on index - cellBlock.innerHTML = `${blockInfo.number}`; - cellBlock.classList.add('order-table-cell'); // Add class to cell - cellTimestamp.textContent = formatTimestamp(timestamp); - cellTimestamp.classList.add('order-table-cell'); // Add class to cell - cellSender.textContent = "COINBASE"; - cellSender.classList.add('order-table-cell'); // Add class to cell - cellReceiver.innerHTML = `${address}`; - cellReceiver.classList.add('order-table-cell'); // Add class to cell - cellRewardAmount.textContent = (blockMNS.reward * 0.00000001).toFixed(8); - cellRewardAmount.classList.add('order-table-cell'); // Add class to cell - cellReference.textContent = "Masternode Reward"; - cellReference.classList.add('order-table-cell'); // Add class to cell - cellType.textContent = "MNS"; - cellType.classList.add('order-table-cell'); // Add class to cell - }); - } + const cellBlock = row.insertCell(0); + const cellTimestamp = row.insertCell(1); + const cellSender = row.insertCell(2); + const cellReceiver = row.insertCell(3); + const cellRewardAmount = row.insertCell(4); + const cellReference = row.insertCell(5); + const cellType = row.insertCell(6); - function formatTimestamp(timestamp) { - const options = { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: true - }; - return timestamp.toLocaleString('en-US', options); - } + cellBlock.innerHTML = `${blockInfo.number}`; + cellBlock.classList.add('order-table-cell'); // Add class to cell + cellTimestamp.textContent = formatTimestamp(timestamp); + cellTimestamp.classList.add('order-table-cell'); // Add class to cell + cellSender.textContent = "COINBASE"; + cellSender.classList.add('order-table-cell'); // Add class to cell + cellReceiver.innerHTML = `${address}`; + cellReceiver.classList.add('order-table-cell'); // Add class to cell + cellRewardAmount.textContent = (blockMNS.reward * 0.00000001).toFixed(8); + cellRewardAmount.classList.add('order-table-cell'); // Add class to cell + cellReference.textContent = "Masternode Reward"; + cellReference.classList.add('order-table-cell'); // Add class to cell + cellType.textContent = "MNS"; + cellType.classList.add('order-table-cell'); // Add class to cell + }); +} - // Function to parse block height from URL - function getBlockHeightFromUrl() { - const urlParams = new URLSearchParams(window.location.search); - const blockHeight = urlParams.get('blockheight'); - return blockHeight ? parseInt(blockHeight) : null; - } +function formatTimestamp(timestamp) { + const options = { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: true + }; + return timestamp.toLocaleString('en-US', options); +} - const defaultBlockNumber = 158302; // Replace with default block number - const blockNumberFromUrl = getBlockHeightFromUrl(); - const blockNumberToUse = blockNumberFromUrl || defaultBlockNumber; - createTableFromBlockInfo(blockNumberToUse); \ No newline at end of file +// Function to parse block height from URL +function getBlockHeightFromUrl() { + const urlParams = new URLSearchParams(window.location.search); + const blockHeight = urlParams.get('blockheight'); + return blockHeight ? parseInt(blockHeight) : null; +} + +(async () => { + const defaultBlockNumber = await fetchMainnetInfo(); // Replace with default block number + const blockNumberFromUrl = getBlockHeightFromUrl(); + const blockNumberToUse = blockNumberFromUrl || defaultBlockNumber; + createTableFromBlockInfo(blockNumberToUse); +})();