Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
joeuhren committed Jun 8, 2019
1 parent 60fb8e2 commit a175e03
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 36 deletions.
8 changes: 7 additions & 1 deletion UPGRADE
@@ -1,4 +1,10 @@
NOTE: All updates require the explorer to be restarted

1.0.0
1.0.1 [June 7, 2019]
-Added stex.com market support
-Added a new public api /ext/getbasicstats
-Fixed all depreciation warnings regarding mongo db.update statements
-Updated outdated mongodb and mongoose references

1.0.0 [May 27, 2019]
-Initial release
13 changes: 13 additions & 0 deletions app.js
Expand Up @@ -117,6 +117,19 @@ app.use('/ext/getcurrentprice', function(req,res){
});
});

app.use('/ext/getbasicstats', function(req,res){
lib.get_blockcount(function(blockcount){
lib.get_supply(function(supply){
db.get_stats(settings.coin, function (stats){
lib.get_masternodecount(function(masternodestotal){
eval('var p_ext = { "block_count": blockcount, "money_supply": supply, "last_price_'+settings.markets.exchange.toLowerCase()+'": stats.last_price, "last_price_usd": stats.last_usd_price, "masternode_count": masternodestotal.total }');
res.send(p_ext);
});
});
});
});
});

app.use('/ext/connections', function(req,res){
db.get_peers(function(peers){
res.send({data: peers});
Expand Down
32 changes: 19 additions & 13 deletions lib/database.js
Expand Up @@ -17,6 +17,7 @@ var mongoose = require('mongoose')
, empoex = require('./markets/empoex')
, ccex = require('./markets/ccex')
, coinexchange = require('./markets/coinexchange')
, stex = require('./markets/stex')
, coindesk = require('./apis/coindesk');

function find_address(hash, cb) {
Expand Down Expand Up @@ -45,7 +46,7 @@ function update_address(hash, txid, amount, type, cb) {
if (address) {
// if coinbase (new coins PoW), update sent only and return cb.
if ( hash == 'coinbase' ) {
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
sent: address.sent + amount,
balance: 0,
}, function() {
Expand All @@ -67,7 +68,7 @@ function update_address(hash, txid, amount, type, cb) {
if ( tx_array.length > settings.txcount ) {
tx_array.shift();
}
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
Expand All @@ -79,7 +80,7 @@ function update_address(hash, txid, amount, type, cb) {
if (type == tx_array[index].type) {
return cb(); //duplicate
} else {
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
Expand Down Expand Up @@ -236,6 +237,11 @@ function get_market_data(market, cb) {
return cb(err, obj);
});
break;
case 'stex':
stex.get_data(settings.markets.coin, settings.markets.exchange, settings.markets.stex_id, function(err, obj){
return cb(err, obj);
});
break;
default:
return cb(null);
}
Expand Down Expand Up @@ -263,7 +269,7 @@ module.exports = {
Stats.findOne({last_usd_price: {$exists: false}}, function(err, stats) {
if (stats) {
// the last_usd_price needs to be added to the collection
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last_usd_price: 0,
}, function() { return cb(null); });
}
Expand Down Expand Up @@ -317,15 +323,15 @@ module.exports = {
update_richlist: function(list, cb){
if(list == 'received') {
Address.find({}).sort({received: 'desc'}).limit(100).exec(function(err, addresses){
Richlist.update({coin: settings.coin}, {
Richlist.updateOne({coin: settings.coin}, {
received: addresses,
}, function() {
return cb();
});
});
} else { //balance
Address.find({}).sort({balance: 'desc'}).limit(100).exec(function(err, addresses){
Richlist.update({coin: settings.coin}, {
Richlist.updateOne({coin: settings.coin}, {
balance: addresses,
}, function() {
return cb();
Expand Down Expand Up @@ -563,7 +569,7 @@ module.exports = {
});
}, function(){
console.log(newVotes);
Heavy.update({coin: coin}, {
Heavy.updateOne({coin: coin}, {
lvote: vote,
reward: reward,
supply: supply,
Expand Down Expand Up @@ -592,15 +598,15 @@ module.exports = {
update_markets_db: function(market, cb) {
get_market_data(market, function (err, obj) {
if (err == null) {
Markets.update({market:market}, {
Markets.updateOne({market:market}, {
chartdata: JSON.stringify(obj.chartdata),
buys: obj.buys,
sells: obj.sells,
history: obj.trades,
summary: obj.stats,
}, function() {
if ( market == settings.markets.default ) {
Stats.update({coin:settings.coin}, {
Stats.updateOne({coin:settings.coin}, {
last_price: obj.stats.last,
}, function(){
return cb(null);
Expand All @@ -623,7 +629,7 @@ module.exports = {
// Get current stats
Stats.findOne({coin:settings.coin}, function(err, stats) {
// Update the last usd price
Stats.update({coin:settings.coin}, {
Stats.updateOne({coin:settings.coin}, {
last_usd_price: (last_usd * stats.last_price),
}, function(){
return cb(null);
Expand All @@ -644,7 +650,7 @@ module.exports = {
}
lib.get_supply( function (supply){
lib.get_connectioncount(function (connections) {
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
coin: coin,
count : count,
supply: supply,
Expand All @@ -664,7 +670,7 @@ module.exports = {
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.updateOne({coin: coin}, {
last: start + x - 1,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {});
Expand Down Expand Up @@ -710,7 +716,7 @@ module.exports = {
});
}, function(){
Tx.find({}).sort({timestamp: 'desc'}).limit(settings.index.last_txs).exec(function(err, txs){
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last: end,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {
Expand Down
1 change: 1 addition & 0 deletions lib/locale.js
Expand Up @@ -148,6 +148,7 @@ exports.cryptopia = "Cryptopia",
exports.empoex = "Empoex",
exports.ccex = "C-Cex",
exports.coinexchange = "CoinExchange",
exports.stex = "Stex",

exports.reloadLocale = function reloadLocale(locale) {
// Discover where the locale file lives
Expand Down
32 changes: 19 additions & 13 deletions lib/markets/database.js
Expand Up @@ -17,6 +17,7 @@ var mongoose = require('mongoose')
, empoex = require('./markets/empoex')
, ccex = require('./markets/ccex')
, coinexchange = require('./markets/coinexchange')
, stex = require('./markets/stex')
, coindesk = require('./apis/coindesk');

function find_address(hash, cb) {
Expand Down Expand Up @@ -45,7 +46,7 @@ function update_address(hash, txid, amount, type, cb) {
if (address) {
// if coinbase (new coins PoW), update sent only and return cb.
if ( hash == 'coinbase' ) {
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
sent: address.sent + amount,
balance: 0,
}, function() {
Expand All @@ -67,7 +68,7 @@ function update_address(hash, txid, amount, type, cb) {
if ( tx_array.length > settings.txcount ) {
tx_array.shift();
}
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
Expand All @@ -79,7 +80,7 @@ function update_address(hash, txid, amount, type, cb) {
if (type == tx_array[index].type) {
return cb(); //duplicate
} else {
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
Expand Down Expand Up @@ -236,6 +237,11 @@ function get_market_data(market, cb) {
return cb(err, obj);
});
break;
case 'stex':
stex.get_data(settings.markets.coin, settings.markets.exchange, settings.markets.stex_id, function(err, obj){
return cb(err, obj);
});
break;
default:
return cb(null);
}
Expand Down Expand Up @@ -263,7 +269,7 @@ module.exports = {
Stats.findOne({last_usd_price: {$exists: false}}, function(err, stats) {
if (stats) {
// the last_usd_price needs to be added to the collection
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last_usd_price: 0,
}, function() { return cb(null); });
}
Expand Down Expand Up @@ -317,15 +323,15 @@ module.exports = {
update_richlist: function(list, cb){
if(list == 'received') {
Address.find({}).sort({received: 'desc'}).limit(100).exec(function(err, addresses){
Richlist.update({coin: settings.coin}, {
Richlist.updateOne({coin: settings.coin}, {
received: addresses,
}, function() {
return cb();
});
});
} else { //balance
Address.find({}).sort({balance: 'desc'}).limit(100).exec(function(err, addresses){
Richlist.update({coin: settings.coin}, {
Richlist.updateOne({coin: settings.coin}, {
balance: addresses,
}, function() {
return cb();
Expand Down Expand Up @@ -563,7 +569,7 @@ module.exports = {
});
}, function(){
console.log(newVotes);
Heavy.update({coin: coin}, {
Heavy.updateOne({coin: coin}, {
lvote: vote,
reward: reward,
supply: supply,
Expand Down Expand Up @@ -592,15 +598,15 @@ module.exports = {
update_markets_db: function(market, cb) {
get_market_data(market, function (err, obj) {
if (err == null) {
Markets.update({market:market}, {
Markets.updateOne({market:market}, {
chartdata: JSON.stringify(obj.chartdata),
buys: obj.buys,
sells: obj.sells,
history: obj.trades,
summary: obj.stats,
}, function() {
if ( market == settings.markets.default ) {
Stats.update({coin:settings.coin}, {
Stats.updateOne({coin:settings.coin}, {
last_price: obj.stats.last,
}, function(){
return cb(null);
Expand All @@ -623,7 +629,7 @@ module.exports = {
// Get current stats
Stats.findOne({coin:settings.coin}, function(err, stats) {
// Update the last usd price
Stats.update({coin:settings.coin}, {
Stats.updateOne({coin:settings.coin}, {
last_usd_price: (last_usd * stats.last_price),
}, function(){
return cb(null);
Expand All @@ -644,7 +650,7 @@ module.exports = {
}
lib.get_supply( function (supply){
lib.get_connectioncount(function (connections) {
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
coin: coin,
count : count,
supply: supply,
Expand All @@ -664,7 +670,7 @@ module.exports = {
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.updateOne({coin: coin}, {
last: start + x - 1,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {});
Expand Down Expand Up @@ -710,7 +716,7 @@ module.exports = {
});
}, function(){
Tx.find({}).sort({timestamp: 'desc'}).limit(settings.index.last_txs).exec(function(err, txs){
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last: end,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {
Expand Down

0 comments on commit a175e03

Please sign in to comment.