Permalink
Browse files

added network views;added network settings;added peers script;

  • Loading branch information...
iquidus committed Jul 18, 2016
1 parent 3e9feb1 commit b06383951e10ed3fb018ee45e1f9aa92f00ee679
Showing with 218 additions and 39 deletions.
  1. +8 −10 README.md
  2. +8 −1 app.js
  3. +64 −27 lib/database.js
  4. +7 −0 lib/locale.js
  5. +2 −1 lib/settings.js
  6. +8 −0 locale/en.json
  7. +12 −0 models/peers.js
  8. +4 −0 routes/index.js
  9. +52 −0 scripts/peers.js
  10. +5 −0 views/layout.jade
  11. +48 −0 views/network.jade
View
@@ -7,10 +7,8 @@ An open source block explorer written in node.js.
* [Jumbucks](http://explorer.getjumbucks.com)
* [Sphere](http://sphere.iquidus.io)
* [Gambit](http://explorer.gambitcrypto.com)
* [SAR](http://explorer.sarcoin.info)
* [Vanillacoin](https://blockchain.vanillacoin.net/)
* [Coven](http://cov.iquidus.io)
* [OKCash](http://okcash.explorer.rocks/)
* [Neoscoin](http://explorer.infernopool.com/)
* [C2Chain](http://c2chain.info/)
@@ -73,16 +71,16 @@ To stop the cluster you can use
sync.js (located in scripts/) is used for updating the local databases. This script must be called from the explorers root directory.
Usage: node scripts/sync.js [database] [mode]
database: (required)
index [mode] Main index: coin info/stats, transactions & addresses
market Market data: summaries, orderbooks, trade history & chartdata
mode: (required for index database only)
update Updates index from last sync to current block
check checks index for (and adds) any missing transactions/addresses
reindex Clears index then resyncs from genesis to current block
notes:
* 'current block' is the latest created block when script is executed.
* The market database only supports (& defaults to) reindex mode.
@@ -96,8 +94,9 @@ sync.js (located in scripts/) is used for updating the local databases. This scr
*Example crontab; update index every minute and market data every 2 minutes*
*/1 * * * * cd /path/to/explorer && /usr/bin/node scripts/sync.js index update > /dev/null 2>&1
*/2 * * * * cd /path/to/explorer && /usr/bin/node scripts/sync.js market > /dev/null 2>&1
*/1 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/sync.js index update > /dev/null 2>&1
*/2 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/sync.js market > /dev/null 2>&1
*/5 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/peers.js > /dev/null 2>&1
### Wallet
@@ -132,7 +131,7 @@ To run sync.js with a larger stack size launch with
node --stack-size=[SIZE] scripts/sync.js index update
Where [SIZE] is an integer higher than the default.
Where [SIZE] is an integer higher than the default.
*note: SIZE will depend on which blockchain you are using, you may need to play around a bit to find an optimal setting*
@@ -166,4 +165,3 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
9 app.js
@@ -9,7 +9,8 @@ var express = require('express')
, routes = require('./routes/index')
, lib = require('./lib/explorer')
, db = require('./lib/database')
, locale = require('./lib/locale');
, locale = require('./lib/locale')
, request = require('request');
var app = express();
@@ -99,6 +100,12 @@ app.use('/ext/getlasttxs/:min', function(req,res){
});
});
app.use('/ext/connections', function(req,res){
db.get_peers(function(peers){
res.send({data: peers});
});
});
// locals
app.set('title', settings.title);
app.set('symbol', settings.symbol);
View
@@ -4,6 +4,7 @@ var mongoose = require('mongoose')
, Address = require('../models/address')
, Tx = require('../models/tx')
, Richlist = require('../models/richlist')
, Peers = require('../models/peers')
, Heavy = require('../models/heavy')
, lib = require('./explorer')
, settings = require('./settings')
@@ -60,8 +61,8 @@ function update_address(hash, txid, amount, type, cb) {
} else {
received = received + amount;
}
if (unique == true) {
tx_array.push({addresses: txid, type: type});
if (unique == true) {
tx_array.push({addresses: txid, type: type});
if ( tx_array.length > settings.txcount ) {
tx_array.shift();
}
@@ -74,9 +75,9 @@ function update_address(hash, txid, amount, type, cb) {
return cb();
});
} else {
if (type == tx_array[index].type) {
if (type == tx_array[index].type) {
return cb(); //duplicate
} else {
} else {
Address.update({a_id:hash}, {
txs: tx_array,
received: received,
@@ -85,7 +86,7 @@ function update_address(hash, txid, amount, type, cb) {
}, function() {
return cb();
});
}
}
}
});
}
@@ -106,7 +107,7 @@ function update_address(hash, txid, amount, type, cb) {
balance: amount,
});
}
newAddress.save(function(err) {
if (err) {
return cb(err);
@@ -130,8 +131,8 @@ function find_tx(txid, cb) {
});
}
function save_tx(txid, cb) {
//var s_timer = new Date().getTime();
function save_tx(txid, cb) {
//var s_timer = new Date().getTime();
lib.get_rawtransaction(txid, function(tx){
if (tx != 'There was an error. Check your console.') {
lib.get_block(tx.blockhash, function(block){
@@ -142,14 +143,14 @@ function save_tx(txid, cb) {
var i = loop.iteration();
update_address(nvin[i].addresses, txid, nvin[i].amount, 'vin', function(){
loop.next();
});
}, function(){
});
}, function(){
lib.syncLoop(vout.length, function (subloop) {
var t = subloop.iteration();
if (vout[t].addresses) {
update_address(vout[t].addresses, txid, vout[t].amount, 'vout', function(){
subloop.next();
});
});
} else {
subloop.next();
}
@@ -176,7 +177,7 @@ function save_tx(txid, cb) {
});
});
});
});
});
} else {
return cb('block not found: ' + tx.blockhash);
}
@@ -351,7 +352,7 @@ module.exports = {
}
});
},
create_txs: function(block, cb) {
lib.syncLoop(block.tx.length, function (loop) {
var i = loop.iteration();
@@ -367,7 +368,7 @@ module.exports = {
return cb();
});
},
get_last_txs: function(count, min, cb) {
Tx.find({'total': {$gt: min}}).sort({_id: 'desc'}).limit(count).exec(function(err, txs){
if (err) {
@@ -396,7 +397,7 @@ module.exports = {
}
});
},
// checks market data exists for given market
check_market: function(market, cb) {
Markets.findOne({market: market}, function(err, exists) {
@@ -445,7 +446,7 @@ module.exports = {
}
});
},
create_heavy: function(coin, cb) {
var newHeavy = new Heavy({
coin: coin,
@@ -461,7 +462,7 @@ module.exports = {
}
});
},
check_heavy: function(coin, cb) {
Heavy.findOne({coin: coin}, function(err, exists) {
if(exists) {
@@ -527,7 +528,7 @@ module.exports = {
},
// updates heavy stats for coin
// height: current block height, count: amount of votes to store
update_heavy: function(coin, height, count, cb) {
update_heavy: function(coin, height, count, cb) {
var newVotes = [];
lib.get_maxmoney( function (maxmoney) {
lib.get_maxvote( function (maxvote) {
@@ -544,7 +545,7 @@ module.exports = {
newVotes.push({count:height-i,reward:block.reward,vote:block.vote});
loop.next();
});
});
});
}, function(){
console.log(newVotes);
Heavy.update({coin: coin}, {
@@ -569,7 +570,7 @@ module.exports = {
});
});
});
});
});
},
// updates market data for given market; called by sync.js
@@ -598,17 +599,17 @@ module.exports = {
}
});
},
// updates stats data for given coin; called by sync.js
update_db: function(coin, cb) {
lib.get_blockcount( function (count) {
if (!count){
console.log('Unable to connect to explorer API');
return cb(false);
}
lib.get_supply( function (supply){
lib.get_supply( function (supply){
lib.get_connectioncount(function (connections) {
Stats.update({coin: coin}, {
Stats.update({coin: coin}, {
coin: coin,
count : count,
supply: supply,
@@ -624,11 +625,11 @@ module.exports = {
// updates tx, address & richlist db's; called by sync.js
update_tx_db: function(coin, start, end, timeout, cb) {
var complete = false;
lib.syncLoop((end - start) + 1, function (loop) {
lib.syncLoop((end - start) + 1, function (loop) {
var x = loop.iteration();
if (x % 5000 === 0) {
Tx.find({}).where('blockindex').lt(start + x).sort({timestamp: 'desc'}).limit(settings.index.last_txs).exec(function(err, txs){
Stats.update({coin: coin}, {
Stats.update({coin: coin}, {
last: start + x - 1,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {});
@@ -674,13 +675,49 @@ module.exports = {
});
}, function(){
Tx.find({}).sort({timestamp: 'desc'}).limit(settings.index.last_txs).exec(function(err, txs){
Stats.update({coin: coin}, {
Stats.update({coin: coin}, {
last: end,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {
return cb();
});
});
});
});
},
create_peer: function(params, cb) {
var newPeer = new Peers(params);
newPeer.save(function(err) {
if (err) {
console.log(err);
return cb();
} else {
return cb();
}
});
},
find_peer: function(address, cb) {
Peers.findOne({address: address}, function(err, peer) {
if (err) {
return cb(null);
} else {
if (peer) {
return cb(peer);
} else {
return cb (null)
}
}
})
},
get_peers: function(cb) {
Peers.find({}, function(err, peers) {
if (err) {
return cb([]);
} else {
return cb(peers);
}
});
}
};
View
@@ -14,6 +14,7 @@ exports.menu_richlist = "Rich List",
exports.menu_reward = "Reward",
exports.menu_movement = "Movement",
exports.menu_node = "Nodes",
exports.menu_network = "Network"
exports.ex_title = "Block Explorer",
exports.ex_search_title = "Search",
@@ -70,6 +71,12 @@ exports.rl_top75 = "Top 51-75",
exports.rl_top100 = "Top 76-100",
exports.rl_hundredplus = "101+",
exports.net_connections = "Connections",
exports.net_address = "Address",
exports.net_protocol = "Protocol",
exports.net_subversion = "Sub-version",
exports.net_country = "Country",
exports.net_warning = "This is simply a sub sample of the network based on wallets connected to this node.",
exports.api_title = "API Documentation",
exports.api_message = "The block explorer provides an API allowing users and/or applications to retrieve information from the network without the need for a local wallet.",
View
@@ -64,7 +64,8 @@ exports.display = {
"twitter": true,
"search": true,
"richlist": true,
"movement": true
"movement": true,
"network": true
};
View
@@ -12,6 +12,7 @@
"menu_reward": "Reward",
"menu_movement": "Movement",
"menu_node": "Nodes",
"menu_network": "Network",
// explorer view
"ex_title": "Block Explorer",
@@ -74,6 +75,13 @@
"rl_top100": "Top 76-100",
"rl_hundredplus": "101+",
"net_connections": "Connections",
"net_address": "Address",
"net_protocol": "Protocol",
"net_subversion": "Sub-version",
"net_country": "Country",
"net_warning": "This is sub sample of the network based on wallets that have connected to this node in the last 24hours.",
// api view
"api_title": "API Documentation",
"api_message": "The block explorer provides an API allowing users and/or applications to retrieve information from the network without the need for a local wallet.",
View
@@ -0,0 +1,12 @@
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
var PeersSchema = new Schema({
createdAt: { type: Date, expires: 86400, default: Date.now()},
address: { type: String, default: "" },
protocol: { type: String, default: "" },
version: { type: String, default: "" },
country: { type: String, default: "" }
});
module.exports = mongoose.model('Peers', PeersSchema);
Oops, something went wrong.

0 comments on commit b063839

Please sign in to comment.