Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Commit

Permalink
Update getblockmnstx.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gonefishing4422 committed Apr 17, 2024
1 parent 3a7242d commit 228be8e
Showing 1 changed file with 115 additions and 95 deletions.
210 changes: 115 additions & 95 deletions js/getblockmnstx.js
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);
})();

0 comments on commit 228be8e

Please sign in to comment.