This repository has been archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a7242d
commit 228be8e
Showing
1 changed file
with
115 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = `<a href="getblockinfo.html?blockheight=${blockInfo.number}" class="block-link">${blockInfo.number}</a>`; | ||
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 = `<a href="getaddressbalance.html?address=${address}" class="address-link">${address}</a>`; | ||
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 = `<a href="getblockinfo.html?blockheight=${blockInfo.number}" class="block-link">${blockInfo.number}</a>`; | ||
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 = `<a href="getaddressbalance.html?address=${address}" class="address-link">${address}</a>`; | ||
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); | ||
// 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); | ||
})(); |