Skip to content

Commit

Permalink
added back the block panel
Browse files Browse the repository at this point in the history
  • Loading branch information
dshuffma-ibm committed Mar 20, 2017
1 parent 8b1d321 commit 990eb3b
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 298 deletions.
79 changes: 0 additions & 79 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,83 +462,4 @@ function setupWebSocket() {
}
});
};

// ========================================================
// Monitor the height of the blockchain
// ========================================================
// this code is no longer used, fabric v1 does not yet have APIs to get block data 1/5/2017
// we will refactor this code when the apis exists

/*hfc_util.monitor_blockheight(hfc.getPeer(peer_url), function(chain_stats) { //there is a new block, lets refresh everything that has a state
if(chain_stats && chain_stats.height){
logger.debug('\nHey new block, lets refresh and broadcast to all', chain_stats.height-1);
hfc_util.getBlockStats(peer, chain_stats.height - 1, cb_blockstats);
wss.broadcast({msg: 'reset'});
hfc_util.queryCC(admin, chaincode_id, 'read', ['_marbleindex'], cb_got_index);
hfc_util.queryCC(admin, chaincode_id, 'read', ['_opentrades'], cb_got_trades);
}
//got the block's stats, lets send the statistics
function cb_blockstats(e, stats){
if(e != null) logger.debug('blockstats error:', e);
else {
chain_stats.height = chain_stats.height - 1; //its 1 higher than actual height
stats.height = chain_stats.height; //copy
wss.broadcast({msg: 'chainstats', e: e, chainstats: chain_stats, blockstats: stats});
}
}
//got the marble index, lets get each marble
function cb_got_index(e, index){
if(e != null) logger.debug('marble index error:', e);
else{
try{
var json = JSON.parse(index);
for(var i in json){
logger.debug('!', i, json[i]);
//iter over each, read their values
hfc_util.queryCC(admin, chaincode_id, 'read', [json[i]], cb_got_marble);
}
}
catch(e){
logger.debug('marbles index msg error:', e);
}
}
}
//call back for getting a marble, lets send a message
function cb_got_marble(e, marble){
if(e != null) logger.debug('marble error:', e);
else {
try{
wss.broadcast({msg: 'marbles', marble: JSON.parse(marble)});
}
catch(e){
logger.debug('marble msg error', e);
}
}
}
//call back for getting open trades, lets send the trades
function cb_got_trades(e, trades){
if(e != null) logger.debug('trade error:', e);
else {
try{
logger.debug('Found open trades: ' + trades);
if (trades !== '') {
trades = JSON.parse(trades);
if(trades && trades.open_trades){
wss.broadcast({msg: 'open_trades', open_trades: trades.open_trades});
}
}
else {
logger.debug('No open trades');
}
}
catch(e){
logger.debug('trade msg error', e);
}
}
}
});*/
}
2 changes: 1 addition & 1 deletion busters_css.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"public/css/singlecsshash":"72a9b9ec83971385280663737a953082"}
{"public/css/singlecsshash":"864cf861563699563eea49cfb2f73f90"}
2 changes: 1 addition & 1 deletion busters_js.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"public/js/singlejshash":"31a32913c151898d1e5a01c28494992e"}
{"public/js/singlejshash":"9c4156c6752f2da94b407575aba13558"}
80 changes: 55 additions & 25 deletions public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ strong {
width: 100%;
background: #222832;
border-top: 1px #646B73 solid;
height: 40px; }
height: 40px;
padding-bottom: 20px; }

.nav {
color: #E5EBEF;
Expand Down Expand Up @@ -588,7 +589,7 @@ strong {

#footerWrap {
height: 235px;
background: #181C22;
background: #222832;
color: #646B73;
width: 100%;
border-top: 25px #222832 solid; }
Expand Down Expand Up @@ -1165,21 +1166,27 @@ td.userRights, th.userRights{
margin: 15px 25px; }

.block {
line-height: 30px;
line-height: 32px;
color: #2EB9D6;
text-align: center;
position: absolute;
top: 0;
left: 100%;
height: 30px;
width: 30px;
border-radius: 4px;
height: 32px;
width: 32px;
border-radius: 2px;
opacity: 5;
border: #2EB9D6 solid 1px;
font-size: 12px;
transition: background-color 0.5s ease;
font-weight: bold; }

.thousands {
font-size: 9px; }

.million {
font-size: 7px; }

/*
.block:last-of-type{
background:#555;
Expand All @@ -1193,29 +1200,52 @@ td.userRights, th.userRights{
color: #222832;
border-color: #2EB9D6; }

.block:hover {
border: #6CC284 solid 1px;
color: #6CC284; }
#blockLegend {
color: #E5EBEF;
margin-right: 10px;
padding: 21px;
position: relative;
left: -26px;
bottom: 13px;
font-size: 18px; }

#details {
background: #222832;
color: #646B73;
display: none;
.tooltip {
position: relative;
top: 40px;
width: 400px;
border-radius: 10px;
padding: 15px 30px;
word-break: break-all;
font-size: 12px; }
display: inline-block; }

.blckLegend {
font-size: 16px;
font-weight: bold; }
/* Tooltip text */
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: #fff;
color: #39424D;
text-align: center;
padding: 5px 0;
border-radius: 2px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 1s;
line-height: 16px; }

.line {
background: #fff;
height: 1px !important; }
/* Tooltip arrow */
.tooltip .tooltiptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #fff transparent transparent transparent; }

/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1; }


/* Example
Expand Down
2 changes: 1 addition & 1 deletion public/css/main.min.css

Large diffs are not rendered by default.

144 changes: 60 additions & 84 deletions public/js/blockchain.js
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: &nbsp;' + formatDate(blocks[id].blockstats.transactions[0].timestamp.seconds * 1000, '%M-%d-%Y %I:%m%p') + ' UTC</p>';
html += '<p> UUID: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + formatUUID(blocks[id].blockstats.transactions[0].type, blocks[id].blockstats.transactions[0].uuid) + '</p>';
html += '<p> Type: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + formatType(blocks[id].blockstats.transactions[0].type) + '</p>';
html += '<p> CC ID: &nbsp;&nbsp;&nbsp;&nbsp;' + ccid + '</p>';
html += '<p> Payload: &nbsp;' + 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;
}
}
Loading

0 comments on commit 990eb3b

Please sign in to comment.