ソースを参照

Some more pizzaz.

master
Trey Del Bonis 4年前
コミット
3bc23b7659
2個のファイルの変更58行の追加25行の削除
  1. 48
    16
      www/main.js
  2. 10
    9
      www/style.css

+ 48
- 16
www/main.js ファイルの表示

const API_PREFIX = "https://blockstream.info/api"; const API_PREFIX = "https://blockstream.info/api";


const IRON_BLOCK = "https://gamepedia.cursecdn.com/minecraft_gamepedia/7/7e/Block_of_Iron_JE4_BE3.png?version=692673bafa1e94785ab6012d7a3c8dc4"; const IRON_BLOCK = "https://gamepedia.cursecdn.com/minecraft_gamepedia/7/7e/Block_of_Iron_JE4_BE3.png?version=692673bafa1e94785ab6012d7a3c8dc4";
const GOLD_BLOCK = "https://gamepedia.cursecdn.com/minecraft_gamepedia/7/72/Block_of_Gold_JE6_BE3.png?version=9d1a63c717df80feffa9ec93ebceb014";
const DIAMOND_BLOCK = "https://gamepedia.cursecdn.com/minecraft_gamepedia/6/6b/Block_of_Diamond_JE6_BE3.png?version=117daf438c2ddfff59bab05d5715f6d2";
const GOLD_BLOCK = "https://gamepedia.cursecdn.com/minecraft_gamepedia/archive/7/72/20190429060628%21Block_of_Gold_JE6_BE3.png?version=448d791eb688910a0cc215181312b715";
const DIAMOND_BLOCK = "https://gamepedia.cursecdn.com/minecraft_gamepedia/archive/6/6b/20190502005227%21Block_of_Diamond_JE6_BE3.png?version=721888d830050c06303696cf79695eb9";


var nextHalvingHeight = 630000;
const HALVING_PERIOD = 210000;


var curTipBlock = null;
var recentBlocks = null; var recentBlocks = null;


function getCurTipBlock() {
return recentBlocks[0];
}

function doApiReq(endpoint, cb) { function doApiReq(endpoint, cb) {
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();


} }


function doGetBlockCoinBaseTx(blockhash, cb) { function doGetBlockCoinBaseTx(blockhash, cb) {
doApiReq("/block/" + blockhash + "/txs", function(resp) {
let reqSuffix = "/block/" + blockhash + "/txs";
let internalCb = function(resp) {
if (resp != null) { if (resp != null) {
cb(resp[0]); cb(resp[0]);
} else { } else {
cb(null); cb(null);
} }
};

doApiReq(reqSuffix, function(resp) {
if (resp != null) {
internalCb(resp);
} else {
// Sometimes the data hasn't been fully processed yet by the time we
// make the call so wait a bit and then try again.
setTimeout(function() {
doApiReq(reqSuffix, internalCb);
}, 1000)
}
}); });
} }


} }
} }


const HALVING_PERIOD = 210000;
function calcNextHalvingHeight() {
let height = recentBlocks[0].height;
let epoch = Math.floor(height / HALVING_PERIOD);
return (epoch + 1) * HALVING_PERIOD;
}


function calcRewardAtHeight(height) { function calcRewardAtHeight(height) {
let epoch = Math.floor(height / HALVING_PERIOD); let epoch = Math.floor(height / HALVING_PERIOD);
return datePart + " " + timePart; return datePart + " " + timePart;
} }


function isHalvingHeight(height) {
return height % HALVING_PERIOD == 0;
}

function makeBlockElem(block, prevBlock) { function makeBlockElem(block, prevBlock) {
let entry = document.createElement("div"); let entry = document.createElement("div");


let iconElem = document.createElement("img"); let iconElem = document.createElement("img");
iconElem.classList.add("blbicon"); iconElem.classList.add("blbicon");
iconCtr.appendChild(iconElem); iconCtr.appendChild(iconElem);
if (block.height % HALVING_PERIOD == 0) {
if (isHalvingHeight(block.height)) {
iconElem.src = DIAMOND_BLOCK; iconElem.src = DIAMOND_BLOCK;
entry.classList.add("halvingblockentry");
} else { } else {
iconElem.src = GOLD_BLOCK; iconElem.src = GOLD_BLOCK;
} }
var timeLeftElem = null; var timeLeftElem = null;
var halfTimeElem = null; var halfTimeElem = null;


const TARGET_BLOCKTIME = 10 * 60;
var blocktimeAvgSecs = TARGET_BLOCKTIME;

function updateRemainingCount(block) { function updateRemainingCount(block) {
if (blocksLeftElem == null) { if (blocksLeftElem == null) {
blocksLeftElem = document.getElementById("blocksleft"); blocksLeftElem = document.getElementById("blocksleft");
halfTimeElem = document.getElementById("halftime"); halfTimeElem = document.getElementById("halftime");
} }


let blocksLeft = nextHalvingHeight - curTipBlock.height;
let nextHalvingHeight = calcNextHalvingHeight();
let blocksLeft = nextHalvingHeight - getCurTipBlock().height;
blocksLeftElem.innerHTML = blocksLeft.toString() blocksLeftElem.innerHTML = blocksLeft.toString()


if (blocksLeft < 1) {
if (blocksLeft <= 1) {
timeLeftElem.innerHTML = "Halving imminent!"; timeLeftElem.innerHTML = "Halving imminent!";


// Hide the expected time. // Hide the expected time.
let nowUnix = Date.now() / 1000; // wtf??? let nowUnix = Date.now() / 1000; // wtf???


let sinceLastBlock = nowUnix - block.timestamp; let sinceLastBlock = nowUnix - block.timestamp;
let secsLeft = ((blocksLeft * 10 * 60) - sinceLastBlock)|0;
let secsLeft = ((blocksLeft * blocktimeAvgSecs) - sinceLastBlock)|0;


let secsPart = secsLeft % 60; let secsPart = secsLeft % 60;
let minLeft = (secsLeft - secsPart) / 60; let minLeft = (secsLeft - secsPart) / 60;


function addNewBlock(block) { function addNewBlock(block) {


let prev = recentBlocks[0];
let prev = getCurTipBlock();
recentBlocks = [block].concat(recentBlocks); recentBlocks = [block].concat(recentBlocks);
//updateBlocktimeAvg();
let elem = makeBlockElem(block, prev); let elem = makeBlockElem(block, prev);


elem.classList.add("newblock"); elem.classList.add("newblock");
let blocklist = document.getElementById("blocklist"); let blocklist = document.getElementById("blocklist");
let loadingElem = document.getElementById("blocklistloading"); let loadingElem = document.getElementById("blocklistloading");


curTipBlock = blocks[0];
updateRemainingCount(curTipBlock.height);
updateRemainingCount(getCurTipBlock());


for (let i = 0; i < blocks.length; i++) { for (let i = 0; i < blocks.length; i++) {
let block = blocks[i]; let block = blocks[i];
} }


loadingElem.style.display = "none"; loadingElem.style.display = "none";
updateRemainingCount(curTipBlock);
//updateRemainingCount(curTipBlock);
} }


function getPollDelayAtHeight(height) { function getPollDelayAtHeight(height) {
let blocksUntilHalving = HALVING_PERIOD - (height % HALVING_PERIOD); let blocksUntilHalving = HALVING_PERIOD - (height % HALVING_PERIOD);
if (blocksUntilHalving == 1) {
if (blocksUntilHalving <= 1) {
return 1000; return 1000;
} else if (blocksUntilHalving == 2) { } else if (blocksUntilHalving == 2) {
return 2500; return 2500;
return; return;
} }


let curTip = getCurTipBlock();

// Find the index of the newest known block. // Find the index of the newest known block.
let knownHeight = recentBlocks[0].height;
let knownHeight = curTip.height;
let newestKnownIndex = -1; let newestKnownIndex = -1;
for (let i = 0; i < blocks.length; i++) { for (let i = 0; i < blocks.length; i++) {
if (blocks[i].height == knownHeight) { if (blocks[i].height == knownHeight) {
} }


recentBlocks = blocks; recentBlocks = blocks;
//updateBlocktimeAvg();


populateRecentBlocks(blocks); populateRecentBlocks(blocks);
setTimeout(checkNewBlocks, 5000); setTimeout(checkNewBlocks, 5000);

+ 10
- 9
www/style.css ファイルの表示

} }
} }


.closebtn {
width: 36pt;
margin: 4pt;

border: 1px solid grey;
border-radius: 4px 4px 4px 4px;
padding: 4pt;
.halvingblockentry .entryinner {
animation: 0.5s linear 0s infinite alternate both running halvingblockanim;
}


background-color: lightgrey;
text-align: center;
@keyframes halvingblockanim {
from {
background-color: #90ffff;
}
to {
background-color: #eeffff;
}
} }

読み込み中…
キャンセル
保存