-
Notifications
You must be signed in to change notification settings - Fork 977
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
8b1d321
commit 990eb3b
Showing
16 changed files
with
262 additions
and
298 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
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 +1 @@ | ||
{"public/css/singlecsshash":"72a9b9ec83971385280663737a953082"} | ||
{"public/css/singlecsshash":"864cf861563699563eea49cfb2f73f90"} |
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 +1 @@ | ||
{"public/js/singlejshash":"31a32913c151898d1e5a01c28494992e"} | ||
{"public/js/singlejshash":"9c4156c6752f2da94b407575aba13558"} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,108 +1,84 @@ | ||
/* global $, document, formatDate, nDig, atob */ | ||
/* global $, document, nDig */ | ||
/* exported clear_blocks, new_block */ | ||
var block = 0; | ||
var uiBlocksCount = 0; | ||
var blocks = []; | ||
var block_height = 0; | ||
|
||
$(document).on('ready', function() { | ||
setInterval(function(){ | ||
move_on_down(); | ||
}, 2000); | ||
|
||
var clicked = false; | ||
$(document).on('click', '.block', function(event){ | ||
clicked = !clicked; | ||
show_details(event, Number($(this).html())); | ||
}); | ||
var block_width_px = 32; //width of the block in px (match this to css) | ||
var block_margin_px = 15; //desired margin of the block | ||
var block_left_px = block_width_px + block_margin_px; | ||
var moveBlocks = null; //interval var | ||
|
||
$(document).on('mouseover', '.block', function(event){ | ||
show_details(event, Number($(this).html())); | ||
}); | ||
|
||
$(document).on('mouseleave', '#blockWrap', function(){ | ||
if(!clicked) $('#details').fadeOut(); | ||
}); | ||
$(document).on('ready', function() { | ||
startTheShow(); | ||
}); | ||
|
||
function show_details(event, id){ //build the block details html | ||
var left = event.pageX - $('#details').parent().offset().left - 50; | ||
if(left < 0) left = 0; | ||
var ccid = formatCCID(blocks[id].blockstats.transactions[0].type, blocks[id].blockstats.transactions[0].uuid, atob(blocks[id].blockstats.transactions[0].chaincodeID)); | ||
var payload = atob(blocks[id].blockstats.transactions[0].payload); | ||
|
||
var html = '<p class="blckLegend"> Block Height: ' + blocks[id].id + '</p>'; | ||
html += '<hr class="line"/><p>Created: ' + formatDate(blocks[id].blockstats.transactions[0].timestamp.seconds * 1000, '%M-%d-%Y %I:%m%p') + ' UTC</p>'; | ||
html += '<p> UUID: ' + formatUUID(blocks[id].blockstats.transactions[0].type, blocks[id].blockstats.transactions[0].uuid) + '</p>'; | ||
html += '<p> Type: ' + formatType(blocks[id].blockstats.transactions[0].type) + '</p>'; | ||
html += '<p> CC ID: ' + ccid + '</p>'; | ||
html += '<p> Payload: ' + formatPayload(payload, ccid) + '</p>'; | ||
$('#details').html(html).css('left', left).fadeIn(); | ||
function startTheShow(){ | ||
moveBlocks = setInterval(function(){ | ||
move_on_down(); | ||
}, 2000); | ||
} | ||
|
||
function new_block(newblck){ //rec a new block | ||
if(!blocks[Number(newblck.id)]){ | ||
for(var last in blocks); //find the id of the last known block | ||
if(!last) last = 0; | ||
last++; | ||
//console.log('last', last, Number(newblck.id)); | ||
if(block > 0){ //never fake blocks on an initial load | ||
for(var i=last; i < Number(newblck.id); i++){ //build fake blocks for ones we missed out on | ||
console.log('run?'); | ||
blocks[Number(i)] = newblck; | ||
build_block(i); | ||
function new_block(id){ //rec a new block | ||
id = Number(id); | ||
if(!blocks[id]){ //if its a new block, build it | ||
|
||
if(uiBlocksCount > 0){ //build missing blocks, except on load (so we dont start at block 0) | ||
for(var prev=block_height+1; prev < id; prev++){ | ||
console.log('building missing block', prev); | ||
blocks[prev] = {block_height: prev}; | ||
build_block(prev); //build the missing blocks | ||
} | ||
} | ||
blocks[Number(newblck.id)] = newblck; | ||
build_block(newblck.id); //build block | ||
|
||
if(id > block_height){ //only draw blocks that are newer | ||
blocks[id] = {block_height: id}; | ||
build_block(id); //build this new block | ||
block_height = id; | ||
} | ||
} | ||
} | ||
|
||
function build_block(id){ //build and append the block html | ||
$('#blockWrap').append('<div class="block">' + nDig(id, 3) + '</div>'); | ||
$('.block:last').animate({opacity: 1, left: (block * 36)}, 600, function(){ | ||
var sizeClass = ''; | ||
if(id >= 1000000) { | ||
sizeClass = 'million'; //figure out a size thats okay | ||
} else if(id >= 1000) { | ||
sizeClass = 'thousands'; | ||
} else{ | ||
id = nDig(id, 3); | ||
} | ||
|
||
var html = `<div class="block ` + sizeClass + `"> | ||
<div class="tooltip"> | ||
<span class="tooltiptext">Block ` + Number(id) + ` has been committed to the ledger</span> | ||
` + id + ` | ||
</div> | ||
</div>`; | ||
$('#blockWrap').append(html); | ||
|
||
// move the block left (number_of_blocks * blocks_width) + 2 blocks_width | ||
$('.block:last').animate({opacity: 1, left: (uiBlocksCount * block_left_px) + block_left_px*2}, 600, function(){ | ||
$('.lastblock').removeClass('lastblock'); | ||
$('.block:last').addClass('lastblock'); | ||
}); | ||
block++; | ||
uiBlocksCount++; | ||
} | ||
|
||
function move_on_down(){ //move the blocks left | ||
if(block > 10){ | ||
if(uiBlocksCount > 10){ | ||
$('.block:first').animate({opacity: 0}, 800, function(){$('.block:first').remove();}); | ||
$('.block').animate({left: '-=36'}, 800, function(){}); | ||
block--; | ||
} | ||
} | ||
$('.block').animate({left: '-=' + block_left_px}, 800, function(){}); | ||
uiBlocksCount--; | ||
|
||
function clear_blocks(){ //empty blocks | ||
block = 0; | ||
blocks = []; | ||
$('.block').remove(); | ||
} | ||
|
||
|
||
function formatCCID(i, uuid, ccid){ //flip uuid and ccid if deploy, weird i know | ||
if(i == 1) return uuid; | ||
return ccid; | ||
} | ||
|
||
function formatUUID(i, uuid){ //blank uuid if deploy, its just ccid again | ||
if(i == 1) return '-'; | ||
return uuid; | ||
} | ||
|
||
function formatType(i){ //spell out deploy or invoke | ||
if(i == 1) return 'deploy'; | ||
if(i == 3) return 'invoke'; | ||
return i; | ||
} | ||
|
||
function formatPayload(str, ccid){ //create a sllliiiggghhhtttlllllyyy better payload name from decoded payload | ||
var func = ['init', 'delete', 'write', 'init_marble', 'set_owner', 'open_trade', 'perform_trade', 'remove_trade']; | ||
str = str.substring(str.indexOf(ccid) + ccid.length + 4); | ||
for(var i in func){ | ||
if(str.indexOf(func[i]) >= 0){ | ||
return func[i] + ': ' + str.substr(func[i].length); | ||
if(uiBlocksCount > 10) { //fast mode, clear the blocks! | ||
clearInterval(moveBlocks); | ||
setTimeout(function(){ | ||
move_on_down(); | ||
}, 900); //delay should be longer than animation delay | ||
} | ||
else{ | ||
startTheShow(); | ||
} | ||
} | ||
return str; | ||
} | ||
} |
Oops, something went wrong.