Skip to content

Commit

Permalink
heavycoin support
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Williams committed Sep 21, 2014
1 parent fa2868e commit dd88762
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 13 deletions.
9 changes: 9 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ db.connect(dbString, function() {
}
});

db.check_heavy(settings.coin, function(exists){
if (exists == false) {
console.log('no heavy entry found, creating now..');
db.create_heavy(settings.coin, function() {

});
}
});

var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
console.log('Ready to receive connections on port: ' + server.address().port);
Expand Down
86 changes: 85 additions & 1 deletion lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var mongoose = require('mongoose')
, Address = require('../models/address')
, Tx = require('../models/tx')
, Richlist = require('../models/richlist')
, Heavy = require('../models/heavy')
, lib = require('./explorer')
, settings = require('./settings')
, mintpal = require('./mintpal')
Expand Down Expand Up @@ -569,7 +570,7 @@ module.exports = {
}
});
},

create_txs: function(block, cb) {
lib.syncLoop(block.tx.length, function (loop) {
var i = loop.iteration();
Expand Down Expand Up @@ -653,6 +654,89 @@ module.exports = {
}
});
},

create_heavy: function(coin, cb) {
var newHeavy = new Heavy({
coin: coin,
});
newHeavy.save(function(err) {
if (err) {
console.log(err);
return cb();
} else {
console.log("initial heavy entry created for %s", coin);
console.log(newHeavy);
return cb();
}
});
},

check_heavy: function(coin, cb) {
Heavy.findOne({coin: coin}, function(err, exists) {
if(exists) {
return cb(true);
} else {
return cb(false);
}
});
},

get_heavy: function(coin, cb) {
Heavy.findOne({coin: coin}, function(err, heavy) {
if(heavy) {
return cb(heavy);
} else {
return cb(null);
}
});
},

// updates heavy stats for coin
// height: current block height, count: amount of votes to store
update_heavy: function(coin, height, count, cb) {
var newVotes = [];
lib.get_maxmoney( function (maxmoney) {
lib.get_maxvote( function (maxvote) {
lib.get_vote( function (vote) {
lib.get_phase( function (phase) {
lib.get_reward( function (reward) {
lib.get_supply( function (supply) {
lib.get_estnext( function (estnext) {
lib.get_nextin( function (nextin) {
lib.syncLoop(count, function (loop) {
var i = loop.iteration();
lib.get_blockhash(height-i, function (hash) {
lib.get_block(hash, function (block) {
newVotes.push({count:height-i,reward:block.reward,vote:block.vote});
loop.next();
});
});
}, function(){
console.log(newVotes);
Heavy.update({coin: coin}, {
lvote: vote,
reward: reward,
supply: supply,
cap: maxmoney,
estnext: estnext,
phase: phase,
maxvote: maxvote,
nextin: nextin,
votes: newVotes,
}, function() {
//console.log('address updated: %s', hash);
return cb();
});
});
});
});
});
});
});
});
});
});
},

// updates market data for given market; called by sync.js
update_markets_db: function(market, cb) {
Expand Down
4 changes: 2 additions & 2 deletions models/heavy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ var mongoose = require('mongoose')

var HeavySchema = new Schema({
coin: { type: String },
vote: { type: Number, default: 0 },
lvote: { type: Number, default: 0 },
reward: { type: Number, default: 0 },
supply: { type: Number, default: 0 },
cap: { type: Number, default: 0 },
estnext: { type: Number, default: 0 },
phase: { type: String, default: 'N/A'},
maxvote: { type: Number, default: 0 },
nextin: { type: String, default: 'N/A'}
nextin: { type: String, default: 'N/A'},
votes: { type: Array, default: [] },
});

Expand Down
8 changes: 0 additions & 8 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,6 @@ tr {

}

.glyphicon-ok {
color: rgb(0,255,0);
}

.glyphicon-remove {
color: rgb(255,0,0);
}

#twitter-icon img{
width: 40px;
margin: 5px 5px;
Expand Down
21 changes: 21 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,27 @@ router.get('/richlist', function(req, res) {
}
});

router.get('/reward', function(req, res){
db.get_stats(settings.coin, function (stats) {
console.log(stats);
db.get_heavy(settings.coin, function (heavy) {
//heavy = heavy;
var votes = heavy.votes;
votes.sort(function (a,b) {
if (a.count < b.count) {
return -1;
} else if (a.count > b.count) {
return 1;
} else {
return 0;
}
});

res.render('reward', { active: 'reward', stats: stats, heavy: heavy, votes: heavy.votes });
});
});
});

router.get('/tx/:txid', function(req, res) {
route_get_tx(res, req.param('txid'));
});
Expand Down
5 changes: 5 additions & 0 deletions scripts/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ is_locked(function (exists) {
} else {
db.update_db(settings.coin, function(){
db.get_stats(settings.coin, function(stats){
if (settings.heavy == true) {
db.update_heavy(settings.coin, stats.count, 20, function(){

});
}
if (mode == 'reindex') {
Tx.remove({}, function(err) {
Address.remove({}, function(err2) {
Expand Down
8 changes: 8 additions & 0 deletions views/block.jade
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ block content
th #{settings.locale.height}
th #{settings.locale.difficulty}
th #{settings.locale.confirmations}
if settings.heavy == true
th Vote
th.hidden-xs #{settings.locale.size} (kB)
th.hidden-xs #{settings.locale.bits}
th.hidden-xs #{settings.locale.nonce}
Expand All @@ -37,6 +39,8 @@ block content
td #{block.height}
td #{block.difficulty.toFixed(4)}
td #{block.confirmations}
if settings.heavy == true
td #{block.vote}
td.hidden-xs #{block_size.toFixed(2)}
td.hidden-xs #{block.bits}
td.hidden-xs #{block.nonce}
Expand All @@ -48,6 +52,8 @@ block content
td #{block.height}
td #{block.difficulty.toFixed(4)}
td #{block.confirmations}
if settings.heavy == true
td #{block.vote}
td.hidden-xs #{block_size.toFixed(2)}
td.hidden-xs #{block.bits}
td.hidden-xs #{block.nonce}
Expand All @@ -58,6 +64,8 @@ block content
td #{block.height}
td #{block.difficulty.toFixed(4)}
td #{block.confirmations}
if settings.heavy == true
td #{block.vote}
td.hidden-xs #{block_size.toFixed(2)}
td.hidden-xs #{block.bits}
td.hidden-xs #{block.nonce}
Expand Down
15 changes: 13 additions & 2 deletions views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ html
script(src='//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js')
script(src='//cdn.datatables.net/responsive/1.0.1/js/dataTables.responsive.js')
script(src='//cdn.datatables.net/plug-ins/725b2a2115b/integration/bootstrap/3/dataTables.bootstrap.js')

script(src='/javascripts/chart.js')
script.
$(document).ready(function(){
$('#loading-icon').hide();
Expand Down Expand Up @@ -78,6 +78,17 @@ html
a.navbar-link(href='/')
span.glyphicon.glyphicon-search
span.menu-text #{settings.locale.menu_explorer}
if settings.heavy == true
if active == 'reward'
li.active
a.navbar-link(href='/reward')
span.fa.fa-star
span.menu-text Reward
else
li
a.navbar-link(href='/reward')
span.fa.fa-star
span.menu-text Reward
if settings.display.markets == true
if active == 'markets'
li.active
Expand Down Expand Up @@ -146,7 +157,7 @@ html
else
label.label.label-success.connections
span.glyphicon.glyphicon-ok(style='margin-right:5px;')
| #{stats.connections} connections
| #{stats.connections} connections
li.text-center
p(style='margin-top:15px;')
a.navbar-link(href='https://github.com/iquidus/explorer', target='_blank') Powered by Iquidus Explorer
Expand Down
118 changes: 118 additions & 0 deletions views/reward.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
extends layout

block content
.row(style='margin-top:5px;')
.col-md-12(style='text-align:center;')
img(src='/images/logo.png' style='width:80px;margin: 0px auto 15px auto;')
.row
.col-xs-12.col-md-10.col-md-offset-1
.panel.panel-default.panel-iquidus.panel-address-summary
.panel-heading(style='position:relative;')
strong #{settings.coin} Block reward voting information
table.table.table-bordered.table-striped.summary-table
thead
tr
th Current Supply (#{settings.symbol})
th Coin Cap (#{settings.symbol})
th Phase
th Max Vote
th Reward
th Est. Next
tbody
tr
td
=heavy.supply
td
=heavy.cap
td
=heavy.phase
td
=heavy.maxvote
td
=heavy.reward
td
=heavy.estnext
.row
.col-md-10.col-md-offset-1
.panel.panel-defual.panel-iquidus
.panel-body
.col-md-3
center
canvas(id="myChart2", width="150", height="150")
script.
var ctx = document.getElementById("myChart2").getContext("2d");
var data = [
{
value: ((#{stats.count}/3600)%1)*100,
//color: "rgba(151,187,205,0.5)"
color: "rgba(92,184,92,1.0)"
},
{
value : (1-((#{stats.count}/3600)%1))*100,
color : "#222"
}
]
new Chart(ctx).Doughnut(data);
h5 Reward change in approximately
h5
=heavy.nextin

form
table.table
thead
tbody
tr
th Key
td
tr
th Vote
td
div(style="width:20px;height:20px;background-color:#428bca")
tr
th Current Reward
td
div(style="width:20px;height:20px;background-color:#222")
tr
th Est. Next
td
div(style="width:20px;height:20px;background-color:rgba(92,184,92,1.0)")

.col-md-9
center
.row
strong Last 20 votes
.row
canvas(id="myChart", width="800", height="300", style="margin-left:-30px;margin-top:30px;")
script.

var ctx = document.getElementById("myChart").getContext("2d");
var options = {
scaleOverride : true,
scaleSteps : 8,
scaleStepWidth : 1,
scaleStartValue : 0,
bezierCurve : false,
}
var data = {
labels : [#{votes[0].count},#{votes[1].count},#{votes[2].count},#{votes[3].count},#{votes[4].count},#{votes[5].count},#{votes[6].count},#{votes[7].count},#{votes[8].count},#{votes[9].count},#{votes[10].count},#{votes[11].count},#{votes[12].count},#{votes[13].count},#{votes[14].count},#{votes[15].count},#{votes[16].count},#{votes[17].count},#{votes[18].count},#{votes[19].count}],
datasets : [
{
fillColor : "rgba(66,139,202,0.5)",
strokeColor : "rgba(66,139,202,0.8)",
pointColor : '#428bca',
pointStrokeColor : "#fff",
data : [#{votes[0].vote},#{votes[1].vote},#{votes[2].vote},#{votes[3].vote},#{votes[4].vote},#{votes[5].vote},#{votes[6].vote},#{votes[7].vote},#{votes[8].vote},#{votes[9].vote},#{votes[10].vote},#{votes[11].vote},#{votes[12].vote},#{votes[13].vote},#{votes[14].vote},#{votes[15].vote},#{votes[16].vote},#{votes[17].vote},#{votes[18].vote},#{votes[19].vote}]
},
{
fillColor : "rgba(151,187,205,0.0)",
strokeColor : '#222',
pointColor : "rgba(0,0,0,0)",
pointStrokeColor : "rgba(0,0,0,0.0)",
data : [#{votes[0].reward},#{votes[1].reward},#{votes[2].reward},#{votes[3].reward},#{votes[4].reward},#{votes[5].reward},#{votes[6].reward},#{votes[7].reward},#{votes[8].reward},#{votes[9].reward},#{votes[10].reward},#{votes[11].reward},#{votes[12].reward},#{votes[13].reward},#{votes[14].reward},#{votes[15].reward},#{votes[16].reward},#{votes[17].reward},#{votes[18].reward},#{votes[19].reward}]
},
]
}
var myNewChart = new Chart(ctx).Line(data,options);



0 comments on commit dd88762

Please sign in to comment.