Code cleanup
-Replace tabs with double-spaces -Betting spacing and lining up of code functions -Add missing semi-colons -Remove extra characters and spaces where applicable -Remove commented-out code fragments -Add missing 2021 date to LICENSE -Small touchups and other misc nitpickings
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2019, The Exor Community
|
||||
Copyright (c) 2019-2021, The Exor Community
|
||||
Copyright (c) 2017, The Chaincoin Community
|
||||
Copyright (c) 2015, Iquidus Technology
|
||||
Copyright (c) 2015, Luke Williams
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
var express = require('express')
|
||||
, path = require('path')
|
||||
, nodeapi = require('./lib/nodeapi')
|
||||
, favicon = require('serve-favicon')
|
||||
, logger = require('morgan')
|
||||
, cookieParser = require('cookie-parser')
|
||||
, bodyParser = require('body-parser')
|
||||
, settings = require('./lib/settings')
|
||||
, routes = require('./routes/index')
|
||||
, lib = require('./lib/explorer')
|
||||
, db = require('./lib/database')
|
||||
, package_metadata = require('./package.json')
|
||||
, locale = require('./lib/locale')
|
||||
, request = require('postman-request');
|
||||
|
||||
var express = require('express'),
|
||||
path = require('path'),
|
||||
nodeapi = require('./lib/nodeapi'),
|
||||
favicon = require('serve-favicon'),
|
||||
logger = require('morgan'),
|
||||
cookieParser = require('cookie-parser'),
|
||||
bodyParser = require('body-parser'),
|
||||
settings = require('./lib/settings'),
|
||||
routes = require('./routes/index'),
|
||||
lib = require('./lib/explorer'),
|
||||
db = require('./lib/database'),
|
||||
package_metadata = require('./package.json'),
|
||||
locale = require('./lib/locale'),
|
||||
request = require('postman-request');
|
||||
var app = express();
|
||||
var apiAccessList = [];
|
||||
|
||||
@@ -79,9 +78,9 @@ app.post('/claim', function(req, res) {
|
||||
if (message == req.body.message) {
|
||||
// call the verifymessage api
|
||||
lib.verify_message(req.body.address, req.body.signature, req.body.message, function(body) {
|
||||
if (body == false) {
|
||||
if (body == false)
|
||||
res.json({'status': 'failed', 'error': true, 'message': 'Invalid signature'});
|
||||
} else if (body == true) {
|
||||
else if (body == true) {
|
||||
db.update_label(req.body.address, req.body.message, function(val) {
|
||||
// check if the update was successful
|
||||
if (val == '')
|
||||
@@ -120,27 +119,33 @@ app.use('/ext/getaddress/:hash', function(req, res) {
|
||||
db.get_address_txs_ajax(req.params.hash, 0, settings.api_page.public_apis.ext.getaddresstxs.max_items_per_query, function(txs, count) {
|
||||
if (address) {
|
||||
var last_txs = [];
|
||||
|
||||
for (i = 0; i < txs.length; i++) {
|
||||
if (typeof txs[i].txid !== "undefined") {
|
||||
var out = 0,
|
||||
vin = 0,
|
||||
tx_type = 'vout',
|
||||
row = {};
|
||||
|
||||
txs[i].vout.forEach(function (r) {
|
||||
if (r.addresses == req.params.hash)
|
||||
out += r.amount;
|
||||
});
|
||||
|
||||
txs[i].vin.forEach(function (s) {
|
||||
if (s.addresses == req.params.hash)
|
||||
vin += s.amount;
|
||||
});
|
||||
|
||||
if (vin > out)
|
||||
tx_type = 'vin';
|
||||
|
||||
row['addresses'] = txs[i].txid;
|
||||
row['type'] = tx_type;
|
||||
last_txs.push(row);
|
||||
}
|
||||
}
|
||||
|
||||
var a_ext = {
|
||||
address: address.a_id,
|
||||
sent: (address.sent / 100000000),
|
||||
@@ -148,6 +153,7 @@ app.use('/ext/getaddress/:hash', function(req, res) {
|
||||
balance: (address.balance / 100000000).toString().replace(/(^-+)/mg, ''),
|
||||
last_txs: last_txs
|
||||
};
|
||||
|
||||
res.send(a_ext);
|
||||
} else
|
||||
res.send({ error: 'address not found.', hash: req.params.hash});
|
||||
@@ -161,13 +167,13 @@ app.use('/ext/gettx/:txid', function(req, res) {
|
||||
// check if the gettx api is enabled
|
||||
if (settings.api_page.enabled == true && settings.api_page.public_apis.ext.gettx.enabled == true) {
|
||||
var txid = req.params.txid;
|
||||
|
||||
db.get_tx(txid, function(tx) {
|
||||
if (tx) {
|
||||
lib.get_blockcount(function(blockcount) {
|
||||
res.send({ active: 'tx', tx: tx, confirmations: settings.shared_pages.confirmations, blockcount: (blockcount ? blockcount : 0)});
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lib.get_rawtransaction(txid, function(rtx) {
|
||||
if (rtx && rtx.txid) {
|
||||
lib.prepare_vin(rtx, function(vin) {
|
||||
@@ -181,8 +187,9 @@ app.use('/ext/gettx/:txid', function(req, res) {
|
||||
total: total.toFixed(8),
|
||||
timestamp: rtx.time,
|
||||
blockhash: '-',
|
||||
blockindex: -1,
|
||||
blockindex: -1
|
||||
};
|
||||
|
||||
res.send({ active: 'tx', tx: utx, confirmations: settings.shared_pages.confirmations, blockcount:-1});
|
||||
} else {
|
||||
var utx = {
|
||||
@@ -192,8 +199,9 @@ app.use('/ext/gettx/:txid', function(req, res) {
|
||||
total: total.toFixed(8),
|
||||
timestamp: rtx.time,
|
||||
blockhash: rtx.blockhash,
|
||||
blockindex: rtx.blockheight,
|
||||
blockindex: rtx.blockheight
|
||||
};
|
||||
|
||||
lib.get_blockcount(function(blockcount) {
|
||||
res.send({ active: 'tx', tx: utx, confirmations: settings.shared_pages.confirmations, blockcount: (blockcount ? blockcount : 0)});
|
||||
});
|
||||
@@ -201,9 +209,8 @@ app.use('/ext/gettx/:txid', function(req, res) {
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
res.send({ error: 'tx not found.', hash: txid});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -297,6 +304,7 @@ app.use('/ext/getlasttxs/:min', function(req, res) {
|
||||
if (split.length > 2 && split[2] == 'internal')
|
||||
internal = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -363,11 +371,13 @@ app.use('/ext/getaddresstxs/:address/:start/:length', function(req, res) {
|
||||
|
||||
if (internal) {
|
||||
var row = [];
|
||||
|
||||
row.push(txs[i].timestamp);
|
||||
row.push(txs[i].txid);
|
||||
row.push(Number(out / 100000000));
|
||||
row.push(Number(vin / 100000000));
|
||||
row.push(Number(txs[i].balance / 100000000));
|
||||
|
||||
data.push(row);
|
||||
} else {
|
||||
data.push({
|
||||
@@ -399,6 +409,7 @@ app.use('/ext/getsummary', function(req, res) {
|
||||
if ((settings.api_page.enabled == true && settings.api_page.public_apis.ext.getsummary.enabled == true) || (req.headers['x-requested-with'] != null && req.headers['x-requested-with'].toLowerCase() == 'xmlhttprequest' && req.headers.referer != null && req.headers.accept.indexOf('text/javascript') > -1 && req.headers.accept.indexOf('application/json') > -1)) {
|
||||
lib.get_difficulty(function(difficulty) {
|
||||
difficultyHybrid = '';
|
||||
|
||||
if (difficulty && difficulty['proof-of-work']) {
|
||||
if (settings.shared_pages.difficulty == 'Hybrid') {
|
||||
difficultyHybrid = 'POS: ' + difficulty['proof-of-stake'];
|
||||
@@ -408,6 +419,7 @@ app.use('/ext/getsummary', function(req, res) {
|
||||
else
|
||||
difficulty = difficulty['proof-of-stake'];
|
||||
}
|
||||
|
||||
lib.get_hashrate(function(hashrate) {
|
||||
lib.get_connectioncount(function(connections) {
|
||||
lib.get_blockcount(function(blockcount) {
|
||||
@@ -415,6 +427,7 @@ app.use('/ext/getsummary', function(req, res) {
|
||||
lib.get_masternodecount(function(masternodestotal) {
|
||||
if (hashrate == 'There was an error. Check your console.')
|
||||
hashrate = 0;
|
||||
|
||||
// check if the masternode count api is enabled
|
||||
if (settings.api_page.public_apis.rpc.getmasternodecount.enabled == true && settings.api_cmds['getmasternodecount'] != null && settings.api_cmds['getmasternodecount'] != '') {
|
||||
// masternode count api is available
|
||||
@@ -424,9 +437,11 @@ app.use('/ext/getsummary', function(req, res) {
|
||||
if (masternodestotal) {
|
||||
if (masternodestotal.total)
|
||||
mn_total = masternodestotal.total;
|
||||
|
||||
if (masternodestotal.enabled)
|
||||
mn_enabled = masternodestotal.enabled;
|
||||
}
|
||||
|
||||
res.send({
|
||||
difficulty: (difficulty ? difficulty : '-'),
|
||||
difficultyHybrid: difficultyHybrid,
|
||||
@@ -477,6 +492,7 @@ app.use('/ext/getnetworkpeers', function(req, res) {
|
||||
delete peers[i]['_doc']['_id'];
|
||||
delete peers[i]['_doc']['__v'];
|
||||
}
|
||||
|
||||
// check if this is an internal request
|
||||
if (internal) {
|
||||
// display data formatted for internal datatable
|
||||
@@ -501,6 +517,7 @@ app.use('/ext/getmasternodelist', function(req, res) {
|
||||
delete masternodes[i]['_doc']['_id'];
|
||||
delete masternodes[i]['_doc']['__v'];
|
||||
}
|
||||
|
||||
// return masternode list
|
||||
res.send(masternodes);
|
||||
});
|
||||
@@ -524,6 +541,7 @@ app.use('/ext/getmasternoderewards/:hash/:since', function(req, res) {
|
||||
rewards[i]['total'] = rewards[i]['total'] / 100000000;
|
||||
rewards[i]['vout']['amount'] = rewards[i]['vout']['amount'] / 100000000;
|
||||
}
|
||||
|
||||
// return list of masternode rewards
|
||||
res.json(rewards);
|
||||
} else
|
||||
|
||||
+10
-9
@@ -8,36 +8,37 @@ if (cluster.isMaster) {
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Starting cluster with pid: ' + process.pid);
|
||||
|
||||
// ensure workers exit cleanly
|
||||
process.on('SIGINT', function() {
|
||||
console.log('Cluster shutting down..');
|
||||
|
||||
for (var id in cluster.workers) {
|
||||
console.log('Worker shutting down (' + id + ')');
|
||||
cluster.workers[id].kill();
|
||||
}
|
||||
|
||||
// exit the master process
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// Count the machine's CPUs
|
||||
// count the machine's CPUs
|
||||
var cpuCount = require('os').cpus().length;
|
||||
|
||||
// Create a worker for each CPU
|
||||
for (var i = 0; i < cpuCount; i += 1) {
|
||||
// create a worker for each CPU
|
||||
for (var i = 0; i < cpuCount; i += 1)
|
||||
cluster.fork();
|
||||
}
|
||||
|
||||
// Listen for dying workers
|
||||
// listen for dying workers
|
||||
cluster.on('exit', function (worker, code, signal) {
|
||||
if (worker['process']['exitCode'] === 0) {
|
||||
if (worker['process']['exitCode'] === 0)
|
||||
console.log('Worker shut down.');
|
||||
} else if ((signal != 'SIGINT') && (worker['process']['exitCode'] !== 0) && (worker.exitedAfterDisconnect !== true)) {
|
||||
else if ((signal != 'SIGINT') && (worker['process']['exitCode'] !== 0) && (worker.exitedAfterDisconnect !== true)) {
|
||||
console.log('Cluster restarting...');
|
||||
cluster.fork();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
require('./instance');
|
||||
}
|
||||
+2
-3
@@ -16,9 +16,7 @@ db.connect(dbString, function() {
|
||||
db.check_stats(settings.coin.name, function(exists) {
|
||||
if (exists == false) {
|
||||
console.log('no stats entry found, creating now..');
|
||||
db.create_stats(settings.coin.name, function(){
|
||||
//console.log('stats entry created successfully.');
|
||||
});
|
||||
db.create_stats(settings.coin.name, function() {});
|
||||
} else {
|
||||
db.get_stats(settings.coin.name, function (stats) {
|
||||
app.locals.stats = stats;
|
||||
@@ -62,6 +60,7 @@ db.connect(dbString, function() {
|
||||
db.create_richlist(settings.coin.name, function() {});
|
||||
}
|
||||
});
|
||||
|
||||
if (settings.blockchain_specific.heavycoin.enabled == true) {
|
||||
db.check_heavy(settings.coin.name, function(exists) {
|
||||
if (exists == false) {
|
||||
|
||||
@@ -2,19 +2,21 @@ var request = require('postman-request');
|
||||
|
||||
function get_usd_value(cb) {
|
||||
request({ uri: 'https://api.coindesk.com/v1/bpi/currentprice/USD.json', json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, body) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, 0);
|
||||
} else {
|
||||
else
|
||||
return cb(null, body.bpi.USD['rate_float'].toFixed(4));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
get_data: function (cb) {
|
||||
var error = null;
|
||||
|
||||
get_usd_value(function (err, last_usd) {
|
||||
if (err) { error = err; }
|
||||
if (err)
|
||||
error = err;
|
||||
|
||||
return cb(error, last_usd);
|
||||
});
|
||||
}
|
||||
|
||||
+126
-103
@@ -1,18 +1,18 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Stats = require('../models/stats')
|
||||
, Markets = require('../models/markets')
|
||||
, Masternode = require('../models/masternode')
|
||||
, Address = require('../models/address')
|
||||
, AddressTx = require('../models/addresstx')
|
||||
, Tx = require('../models/tx')
|
||||
, Richlist = require('../models/richlist')
|
||||
, Peers = require('../models/peers')
|
||||
, Heavy = require('../models/heavy')
|
||||
, lib = require('./explorer')
|
||||
, settings = require('./settings')
|
||||
, fs = require('fs')
|
||||
, coindesk = require('./apis/coindesk')
|
||||
, async = require('async');
|
||||
var mongoose = require('mongoose'),
|
||||
Stats = require('../models/stats'),
|
||||
Markets = require('../models/markets'),
|
||||
Masternode = require('../models/masternode'),
|
||||
Address = require('../models/address'),
|
||||
AddressTx = require('../models/addresstx'),
|
||||
Tx = require('../models/tx'),
|
||||
Richlist = require('../models/richlist'),
|
||||
Peers = require('../models/peers'),
|
||||
Heavy = require('../models/heavy'),
|
||||
lib = require('./explorer'),
|
||||
settings = require('./settings'),
|
||||
fs = require('fs'),
|
||||
coindesk = require('./apis/coindesk'),
|
||||
async = require('async');
|
||||
|
||||
function find_address(hash, caseSensitive, cb) {
|
||||
if (caseSensitive) {
|
||||
@@ -36,21 +36,19 @@ function find_address(hash, caseSensitive, cb) {
|
||||
|
||||
function find_address_tx(address, hash, cb) {
|
||||
AddressTx.findOne({a_id: address, txid: hash}, function(err, address_tx) {
|
||||
if(address_tx) {
|
||||
if (address_tx)
|
||||
return cb(address_tx);
|
||||
} else {
|
||||
else
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function find_richlist(coin, cb) {
|
||||
Richlist.findOne({coin: coin}, function(err, richlist) {
|
||||
if(richlist) {
|
||||
if (richlist)
|
||||
return cb(richlist);
|
||||
} else {
|
||||
else
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,9 +56,10 @@ function update_address(hash, blockheight, txid, amount, type, cb) {
|
||||
var to_sent = false;
|
||||
var to_received = false;
|
||||
var addr_inc = {}
|
||||
if ( hash == 'coinbase' ) {
|
||||
|
||||
if (hash == 'coinbase')
|
||||
addr_inc.sent = amount;
|
||||
} else {
|
||||
else {
|
||||
if (type == 'vin') {
|
||||
addr_inc.sent = amount;
|
||||
addr_inc.balance = -amount;
|
||||
@@ -69,15 +68,16 @@ function update_address(hash, blockheight, txid, amount, type, cb) {
|
||||
addr_inc.balance = amount;
|
||||
}
|
||||
}
|
||||
|
||||
Address.findOneAndUpdate({a_id: hash}, {
|
||||
$inc: addr_inc
|
||||
}, {
|
||||
new: true,
|
||||
upsert: true
|
||||
}, function (err, address) {
|
||||
if (err) {
|
||||
if (err)
|
||||
return cb(err);
|
||||
} else {
|
||||
else {
|
||||
if (hash != 'coinbase') {
|
||||
AddressTx.findOneAndUpdate({a_id: hash, txid: txid}, {
|
||||
$inc: {
|
||||
@@ -92,26 +92,23 @@ function update_address(hash, blockheight, txid, amount, type, cb) {
|
||||
new: true,
|
||||
upsert: true
|
||||
}, function (err,addresstx) {
|
||||
if (err) {
|
||||
if (err)
|
||||
return cb(err);
|
||||
} else {
|
||||
else
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
return cb();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function find_tx(txid, cb) {
|
||||
Tx.findOne({txid: txid}, function(err, tx) {
|
||||
if(tx) {
|
||||
if (tx)
|
||||
return cb(tx);
|
||||
} else {
|
||||
else
|
||||
return cb(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -122,12 +119,14 @@ function save_tx(txid, blockheight, cb) {
|
||||
lib.prepare_vout(tx.vout, txid, vin, ((!settings.blockchain_specific.zksnarks.enabled || typeof tx.vjoinsplit === 'undefined' || tx.vjoinsplit == null) ? [] : tx.vjoinsplit), function(vout, nvin) {
|
||||
lib.syncLoop(vin.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
update_address(nvin[i].addresses, blockheight, txid, nvin[i].amount, 'vin', function() {
|
||||
loop.next();
|
||||
});
|
||||
}, function() {
|
||||
lib.syncLoop(vout.length, function (subloop) {
|
||||
var t = subloop.iteration();
|
||||
|
||||
if (vout[t].addresses) {
|
||||
update_address(vout[t].addresses, blockheight, txid, vout[t].amount, 'vout', function() {
|
||||
subloop.next();
|
||||
@@ -143,8 +142,9 @@ function save_tx(txid, blockheight, cb) {
|
||||
total: total.toFixed(8),
|
||||
timestamp: tx.time,
|
||||
blockhash: tx.blockhash,
|
||||
blockindex: blockheight,
|
||||
blockindex: blockheight
|
||||
});
|
||||
|
||||
newTx.save(function(err) {
|
||||
if (err)
|
||||
return cb(err, false);
|
||||
@@ -164,6 +164,7 @@ function save_tx(txid, blockheight, cb) {
|
||||
function get_market_data(market, coin_symbol, pair_symbol, cb) {
|
||||
if (fs.existsSync('./lib/markets/' + market + '.js')) {
|
||||
exMarket = require('./markets/' + market);
|
||||
|
||||
exMarket.get_data({coin: coin_symbol, exchange: pair_symbol}, function(err, obj) {
|
||||
return cb(err, obj);
|
||||
});
|
||||
@@ -216,6 +217,7 @@ module.exports = {
|
||||
// ensure that if this address exists in the richlist that it displays the new alias
|
||||
module.exports.get_richlist(settings.coin.name, function(richlist) {
|
||||
var updated = false;
|
||||
|
||||
// loop through received addresses
|
||||
for (r = 0; r < richlist.received.length; r++) {
|
||||
// check if this is the correct address
|
||||
@@ -226,6 +228,7 @@ module.exports = {
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
// loop through balance addresses
|
||||
for (b = 0; b < richlist.balance.length; b++) {
|
||||
// check if this is the correct address
|
||||
@@ -236,6 +239,7 @@ module.exports = {
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check if the address was updated in the richlist
|
||||
if (updated) {
|
||||
// save the richlist back to collection
|
||||
@@ -263,6 +267,7 @@ module.exports = {
|
||||
// ensure that if this address exists in the masternode that it displays the new alias
|
||||
module.exports.get_masternodes(function(masternodes) {
|
||||
var updated = false;
|
||||
|
||||
// loop through masternode addresses
|
||||
for (m = 0; m < masternodes.length; m++) {
|
||||
// check if this is the correct address
|
||||
@@ -273,6 +278,7 @@ module.exports = {
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check if the address was updated in the masternode list
|
||||
if (updated) {
|
||||
// save the updated masternode back to collection
|
||||
@@ -301,24 +307,25 @@ module.exports = {
|
||||
if (stats) {
|
||||
// the last_usd_price needs to be added to the collection
|
||||
Stats.updateOne({coin: coin}, {
|
||||
last_usd_price: 0,
|
||||
}, function() { return cb(null); });
|
||||
last_usd_price: 0
|
||||
}, function() {
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return cb(true);
|
||||
} else {
|
||||
} else
|
||||
return cb(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
get_stats: function(coin, cb) {
|
||||
Stats.findOne({coin: coin}, function(err, stats) {
|
||||
if(stats) {
|
||||
if (stats)
|
||||
return cb(stats);
|
||||
} else {
|
||||
else
|
||||
return cb(null);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -334,7 +341,6 @@ module.exports = {
|
||||
return cb();
|
||||
} else {
|
||||
console.log("initial stats entry created for %s", coin);
|
||||
//console.log(newStats);
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
@@ -358,6 +364,7 @@ module.exports = {
|
||||
var total_addresses = 100;
|
||||
// create the burn address array so that we omit burned coins from the rich list
|
||||
var burn_addresses = settings.richlist_page.burned_coins.addresses;
|
||||
|
||||
// always omit the private address from the richlist
|
||||
burn_addresses.push("private_tx");
|
||||
|
||||
@@ -387,6 +394,7 @@ module.exports = {
|
||||
Address.find({}, 'a_id name balance received').sort({balance: 'desc'}).limit(total_addresses + burn_addresses.length).exec(function(err, addresses) {
|
||||
var return_addresses = [];
|
||||
var burned_balance = 0.0;
|
||||
|
||||
// loop through all richlist addresses
|
||||
addresses.forEach(function (address) {
|
||||
// check if this is a burned coin address
|
||||
@@ -398,6 +406,7 @@ module.exports = {
|
||||
return_addresses.push(address);
|
||||
}
|
||||
});
|
||||
|
||||
// update the rich list collection
|
||||
Richlist.updateOne({coin: settings.coin.name}, {
|
||||
balance: return_addresses,
|
||||
@@ -418,16 +427,17 @@ module.exports = {
|
||||
|
||||
get_txs: function(block, cb) {
|
||||
var txs = [];
|
||||
|
||||
lib.syncLoop(block.tx.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
find_tx(block.tx[i], function(tx) {
|
||||
if (tx) {
|
||||
txs.push(tx);
|
||||
loop.next();
|
||||
} else {
|
||||
} else
|
||||
loop.next();
|
||||
}
|
||||
})
|
||||
});
|
||||
}, function() {
|
||||
return cb(txs);
|
||||
});
|
||||
@@ -440,12 +450,14 @@ module.exports = {
|
||||
for (i = 0; i < txs.length; i++) {
|
||||
if (internal) {
|
||||
var row = [];
|
||||
|
||||
row.push(txs[i].blockindex);
|
||||
row.push(txs[i].blockhash);
|
||||
row.push(txs[i].txid);
|
||||
row.push(txs[i].vout.length);
|
||||
row.push((txs[i].total / 100000000));
|
||||
row.push(txs[i].timestamp);
|
||||
|
||||
data.push(row);
|
||||
} else {
|
||||
data.push({
|
||||
@@ -458,6 +470,7 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return cb(data, count);
|
||||
});
|
||||
},
|
||||
@@ -467,13 +480,12 @@ module.exports = {
|
||||
if (min > 0) {
|
||||
// min is greater than zero which means we must pull record count from the txes collection
|
||||
Tx.find({'total': {$gte: min}}).countDocuments(function(err, count) {
|
||||
// Get last transactions where there is at least 1 vout
|
||||
// get last transactions where there is at least 1 vout
|
||||
Tx.find({'total': {$gte: min}, 'vout': { $gte: { $size: 1 }}}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function(err, txs) {
|
||||
if (err) {
|
||||
if (err)
|
||||
return cb(err);
|
||||
} else {
|
||||
else
|
||||
return cb(txs, count);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -481,11 +493,10 @@ module.exports = {
|
||||
Stats.findOne({coin: settings.coin.name}, function(err, stats) {
|
||||
// Get last transactions where there is at least 1 vout
|
||||
Tx.find({'total': {$gte: min}, 'vout': { $gte: { $size: 1 }}}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function(err, txs) {
|
||||
if (err) {
|
||||
if (err)
|
||||
return cb(err);
|
||||
} else {
|
||||
else
|
||||
return cb(txs, stats.txes);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -493,11 +504,13 @@ module.exports = {
|
||||
|
||||
get_address_txs_ajax: function(hash, start, length, cb) {
|
||||
var totalCount = 0;
|
||||
|
||||
AddressTx.find({a_id: hash}).countDocuments(function(err, count) {
|
||||
if(err) {
|
||||
if (err)
|
||||
return cb(err);
|
||||
} else {
|
||||
else {
|
||||
totalCount = count;
|
||||
|
||||
AddressTx.aggregate([
|
||||
{ $match: { a_id: hash } },
|
||||
{ $sort: {blockindex: -1} },
|
||||
@@ -516,21 +529,21 @@ module.exports = {
|
||||
},
|
||||
{ $sort: {blockindex: -1} }
|
||||
], function (err,balance_sum) {
|
||||
if (err) {
|
||||
if (err)
|
||||
return cb(err);
|
||||
} else {
|
||||
else {
|
||||
AddressTx.find({a_id: hash}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
|
||||
if (err) {
|
||||
if (err)
|
||||
return cb(err);
|
||||
} else {
|
||||
else {
|
||||
var txs = [];
|
||||
var count = address_tx.length;
|
||||
var running_balance = balance_sum.length > 0 ? balance_sum[0].balance : 0;
|
||||
|
||||
var txs = [];
|
||||
|
||||
lib.syncLoop(count, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
find_tx(address_tx[i].txid, function (tx) {
|
||||
if (tx && !txs.includes(tx)) {
|
||||
tx.balance = running_balance;
|
||||
@@ -539,11 +552,11 @@ module.exports = {
|
||||
} else if (!txs.includes(tx)) {
|
||||
txs.push("1. Not found");
|
||||
loop.next();
|
||||
} else {
|
||||
} else
|
||||
loop.next();
|
||||
}
|
||||
|
||||
running_balance = running_balance - address_tx[i].amount;
|
||||
})
|
||||
});
|
||||
}, function () {
|
||||
return cb(txs, totalCount);
|
||||
});
|
||||
@@ -559,7 +572,7 @@ module.exports = {
|
||||
var newMarkets = new Markets({
|
||||
market: market,
|
||||
coin_symbol: coin_symbol,
|
||||
pair_symbol: pair_symbol,
|
||||
pair_symbol: pair_symbol
|
||||
});
|
||||
|
||||
newMarkets.save(function(err) {
|
||||
@@ -593,15 +606,15 @@ module.exports = {
|
||||
// creates initial richlist entry in database; called on first launch of explorer
|
||||
create_richlist: function(coin, cb) {
|
||||
var newRichlist = new Richlist({
|
||||
coin: coin,
|
||||
coin: coin
|
||||
});
|
||||
|
||||
newRichlist.save(function(err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return cb();
|
||||
} else {
|
||||
console.log("initial richlist entry created for %s", coin);
|
||||
//console.log(newRichlist);
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
@@ -610,28 +623,28 @@ module.exports = {
|
||||
// drops richlist data for given coin
|
||||
delete_richlist: function(coin, cb) {
|
||||
Richlist.findOneAndRemove({coin: coin}, function(err, exists) {
|
||||
if(exists) {
|
||||
if (exists)
|
||||
return cb(true);
|
||||
} else {
|
||||
else
|
||||
return cb(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// checks richlist data exists for given coin
|
||||
check_richlist: function(coin, cb) {
|
||||
Richlist.findOne({coin: coin}, function(err, exists) {
|
||||
if(exists) {
|
||||
if (exists)
|
||||
return cb(true);
|
||||
} else {
|
||||
else
|
||||
return cb(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
create_heavy: function(coin, cb) {
|
||||
var newHeavy = new Heavy({
|
||||
coin: coin,
|
||||
coin: coin
|
||||
});
|
||||
|
||||
newHeavy.save(function(err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
@@ -645,21 +658,19 @@ module.exports = {
|
||||
|
||||
check_heavy: function(coin, cb) {
|
||||
Heavy.findOne({coin: coin}, function(err, exists) {
|
||||
if(exists) {
|
||||
if (exists)
|
||||
return cb(true);
|
||||
} else {
|
||||
else
|
||||
return cb(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
get_heavy: function(coin, cb) {
|
||||
Heavy.findOne({coin: coin}, function(err, heavy) {
|
||||
if(heavy) {
|
||||
if (heavy)
|
||||
return cb(heavy);
|
||||
} else {
|
||||
else
|
||||
return cb(null);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -710,6 +721,7 @@ module.exports = {
|
||||
distribution.t_51_75.total = parseFloat(distribution.t_51_75.total).toFixed(8);
|
||||
distribution.t_76_100.percent = parseFloat(distribution.t_76_100.percent).toFixed(2);
|
||||
distribution.t_76_100.total = parseFloat(distribution.t_76_100.total).toFixed(8);
|
||||
|
||||
return cb(distribution);
|
||||
});
|
||||
},
|
||||
@@ -729,6 +741,7 @@ module.exports = {
|
||||
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 && block.vote ? block.vote : 0) });
|
||||
@@ -783,7 +796,7 @@ module.exports = {
|
||||
if (market == settings.markets_page.default_exchange.exchange_name && settings.markets_page.default_exchange.trading_pair.toUpperCase() == coin_symbol.toUpperCase() + '/' + pair_symbol.toUpperCase() && pair_symbol.toUpperCase() == 'BTC') {
|
||||
// this is the default market so update the last price stats
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last_price: obj.stats.last,
|
||||
last_price: obj.stats.last
|
||||
}, function() {
|
||||
// finished updating market data
|
||||
return cb(null);
|
||||
@@ -813,7 +826,7 @@ module.exports = {
|
||||
Stats.findOne({coin: settings.coin.name}, function(err, stats) {
|
||||
// update the last usd price
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last_usd_price: (last_usd * stats.last_price),
|
||||
last_usd_price: (last_usd * stats.last_price)
|
||||
}, function() {
|
||||
return cb(null);
|
||||
});
|
||||
@@ -831,8 +844,10 @@ module.exports = {
|
||||
// check to ensure count is a positive number
|
||||
if (!count || (count != null && typeof count === 'number' && count < 0)) {
|
||||
console.log('Unable to connect to explorer API');
|
||||
|
||||
return cb(false);
|
||||
}
|
||||
|
||||
lib.get_supply(function (supply) {
|
||||
lib.get_connectioncount(function (connections) {
|
||||
Stats.findOne({coin: coin}, function(err, stats) {
|
||||
@@ -843,9 +858,9 @@ module.exports = {
|
||||
supply: (supply ? supply : 0),
|
||||
connections: (connections ? connections : 0)
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
if (err)
|
||||
console.log("Error during Stats Update: ", err);
|
||||
}
|
||||
|
||||
return cb({
|
||||
coin: coin,
|
||||
count : count,
|
||||
@@ -870,11 +885,18 @@ module.exports = {
|
||||
var complete = false;
|
||||
var blocks_to_scan = [];
|
||||
var task_limit_blocks = settings.sync.block_parallel_tasks;
|
||||
if (typeof start === 'undefined' || start < 1) start = 1; // fix for invalid block height (skip genesis block as it should not have valid txs)
|
||||
if (task_limit_blocks < 1) { task_limit_blocks = 1; }
|
||||
var task_limit_txs = 1;
|
||||
|
||||
// fix for invalid block height (skip genesis block as it should not have valid txs)
|
||||
if (typeof start === 'undefined' || start < 1)
|
||||
start = 1;
|
||||
|
||||
if (task_limit_blocks < 1)
|
||||
task_limit_blocks = 1;
|
||||
|
||||
for (i = start; i < (end + 1); i++)
|
||||
blocks_to_scan.push(i);
|
||||
|
||||
async.eachLimit(blocks_to_scan, task_limit_blocks, function(block_height, next_block) {
|
||||
if (block_height % settings.sync.save_stats_after_sync_blocks === 0) {
|
||||
Stats.updateOne({coin: coin}, {
|
||||
@@ -882,6 +904,7 @@ module.exports = {
|
||||
txes: txes
|
||||
}, function() {});
|
||||
}
|
||||
|
||||
lib.get_blockhash(block_height, function(blockhash) {
|
||||
if (blockhash) {
|
||||
lib.get_block(blockhash, function(block) {
|
||||
@@ -902,6 +925,7 @@ module.exports = {
|
||||
|
||||
if (tx_has_vout)
|
||||
txes++;
|
||||
|
||||
setTimeout( function() {
|
||||
tx = null;
|
||||
next_tx();
|
||||
@@ -918,6 +942,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
console.log('block not found: %s', blockhash);
|
||||
|
||||
setTimeout( function() {
|
||||
next_block();
|
||||
}, timeout);
|
||||
@@ -941,28 +966,27 @@ module.exports = {
|
||||
|
||||
create_peer: function(params, cb) {
|
||||
var newPeer = new Peers(params);
|
||||
|
||||
newPeer.save(function(err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return cb();
|
||||
} else {
|
||||
} else
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
find_peer: function(address, cb) {
|
||||
Peers.findOne({address: address}, function(err, peer) {
|
||||
if (err) {
|
||||
if (err)
|
||||
return cb(null);
|
||||
} else {
|
||||
if (peer) {
|
||||
else {
|
||||
if (peer)
|
||||
return cb(peer);
|
||||
} else {
|
||||
else
|
||||
return cb (null)
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
drop_peer: function(address, cb) {
|
||||
@@ -970,10 +994,9 @@ module.exports = {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return cb();
|
||||
} else {
|
||||
return cb ()
|
||||
}
|
||||
})
|
||||
} else
|
||||
return cb();
|
||||
});
|
||||
},
|
||||
|
||||
drop_peers: function(cb) {
|
||||
@@ -981,19 +1004,17 @@ module.exports = {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return cb();
|
||||
} else {
|
||||
return cb ()
|
||||
}
|
||||
})
|
||||
} else
|
||||
return cb();
|
||||
});
|
||||
},
|
||||
|
||||
get_peers: function(cb) {
|
||||
Peers.find({}, function(err, peers) {
|
||||
if (err) {
|
||||
if (err)
|
||||
return cb([]);
|
||||
} else {
|
||||
else
|
||||
return cb(peers);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1012,6 +1033,7 @@ module.exports = {
|
||||
// save blank claim name to masternode obejct
|
||||
raw_masternode.claim_name = '';
|
||||
}
|
||||
|
||||
// add/update the masternode
|
||||
module.exports.add_update_masternode(raw_masternode, (masternode == null), function(success) {
|
||||
return cb(success);
|
||||
@@ -1032,6 +1054,7 @@ module.exports = {
|
||||
console.log('Masternode Update - TX or Outidx is missing');
|
||||
console.log(masternode.txhash);
|
||||
console.log(masternode.outidx);
|
||||
|
||||
return cb(false);
|
||||
} else {
|
||||
var mn = new Masternode({
|
||||
|
||||
+88
-41
@@ -1,22 +1,19 @@
|
||||
var request = require('postman-request')
|
||||
, settings = require('./settings')
|
||||
, Address = require('../models/address');
|
||||
var request = require('postman-request'),
|
||||
settings = require('./settings'),
|
||||
Address = require('../models/address');
|
||||
|
||||
var base_server = 'http://127.0.0.1:' + settings.webserver.port + "/";
|
||||
|
||||
var base_url = base_server + 'api/';
|
||||
|
||||
const onode = require('./node');
|
||||
const client = new onode.Client(settings.wallet);
|
||||
|
||||
// returns coinbase total sent as current coin supply
|
||||
function coinbase_supply(cb) {
|
||||
Address.findOne({a_id: 'coinbase'}, function(err, address) {
|
||||
if (address) {
|
||||
if (address)
|
||||
return cb(address.sent);
|
||||
} else {
|
||||
else
|
||||
return cb(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -81,7 +78,8 @@ module.exports = {
|
||||
|
||||
get_hashrate: function(cb) {
|
||||
// check if hash rate should be hidden
|
||||
if (settings.shared_pages.show_hashrate == false) return cb('-');
|
||||
if (settings.shared_pages.show_hashrate == false)
|
||||
return cb('-');
|
||||
// check how to acquire network hashrate
|
||||
if (settings.shared_pages.page_header.panels.network_panel.nethash == 'netmhashps') {
|
||||
// load getmininginfo rpc call from settings
|
||||
@@ -93,7 +91,8 @@ module.exports = {
|
||||
// get data from wallet via rpc cmd
|
||||
rpcCommand([{method:cmd.method, parameters: cmd.parameters}], function(response) {
|
||||
// check if an error msg was received from the rpc server
|
||||
if (response == 'There was an error. Check your console.') return cb('-');
|
||||
if (response == 'There was an error. Check your console.')
|
||||
return cb('-');
|
||||
|
||||
var net_hash = null;
|
||||
// check for different implementations of the net has value
|
||||
@@ -117,6 +116,7 @@ module.exports = {
|
||||
} else {
|
||||
// get data via internal web api request
|
||||
var uri = base_url + 'getmininginfo';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.') {
|
||||
@@ -158,7 +158,8 @@ module.exports = {
|
||||
// get data from wallet via rpc cmd
|
||||
rpcCommand([{method:cmd.method, parameters: cmd.parameters}], function(response) {
|
||||
// check if an error msg was received from the rpc server
|
||||
if (response == 'There was an error. Check your console.') return cb('-');
|
||||
if (response == 'There was an error. Check your console.')
|
||||
return cb('-');
|
||||
// check if the response has a value
|
||||
if (response) {
|
||||
// return hash value with proper units
|
||||
@@ -171,6 +172,7 @@ module.exports = {
|
||||
} else {
|
||||
// get data via internal web api request
|
||||
var uri = base_url + 'getnetworkhashps';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.') {
|
||||
@@ -206,6 +208,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getdifficulty';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -234,6 +237,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getconnectioncount';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -262,6 +266,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getmasternodelist';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -290,6 +295,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getmasternodecount';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -318,6 +324,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getblockcount';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -346,6 +353,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getblockhash?height=' + (height ? height : '');
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -374,6 +382,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getblock?hash=' + hash;
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -402,6 +411,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getrawtransaction?txid=' + hash + '&decrypt=1';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -430,6 +440,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getmaxmoney';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -458,6 +469,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getmaxvote';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -486,6 +498,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getvote';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -514,6 +527,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getphase';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -542,6 +556,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getreward';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -570,6 +585,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getnextrewardestimate';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -598,6 +614,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getnextrewardwhenstr';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -618,47 +635,69 @@ module.exports = {
|
||||
var index = 0,
|
||||
done = false,
|
||||
shouldExit = false;
|
||||
|
||||
var loop = {
|
||||
next: function() {
|
||||
if (done) {
|
||||
if (shouldExit && exit) {
|
||||
exit(); // Exit if we're done
|
||||
// exit if we're done
|
||||
exit();
|
||||
} else {
|
||||
// stop the loop if we're done
|
||||
return;
|
||||
}
|
||||
return; // Stop the loop if we're done
|
||||
}
|
||||
// If we're not finished
|
||||
|
||||
// if we're not finished
|
||||
if (index < iterations) {
|
||||
index++; // Increment our index
|
||||
if (index % 100 === 0) { //clear stack
|
||||
// increment our index
|
||||
index++;
|
||||
|
||||
if (index % 100 === 0) {
|
||||
// clear stack
|
||||
setTimeout(function() {
|
||||
process(loop); // Run our process, pass in the loop
|
||||
// run our process, pass in the loop
|
||||
process(loop);
|
||||
}, 1);
|
||||
} else {
|
||||
process(loop); // Run our process, pass in the loop
|
||||
// run our process, pass in the loop
|
||||
process(loop);
|
||||
}
|
||||
// Otherwise we're done
|
||||
} else {
|
||||
done = true; // Make sure we say we're done
|
||||
if(exit) exit(); // Call the callback on exit
|
||||
// otherwise we're done
|
||||
// make sure we say we're done
|
||||
done = true;
|
||||
|
||||
if (exit) {
|
||||
// call the callback on exit
|
||||
exit();
|
||||
}
|
||||
}
|
||||
},
|
||||
iteration: function() {
|
||||
return index - 1; // Return the loop number we're on
|
||||
// return the loop number we're on
|
||||
return index - 1;
|
||||
},
|
||||
break: function(end) {
|
||||
done = true; // End the loop
|
||||
shouldExit = end; // Passing end as true means we still call the exit callback
|
||||
// end the loop
|
||||
done = true;
|
||||
// passing end as true means we still call the exit callback
|
||||
shouldExit = end;
|
||||
}
|
||||
};
|
||||
|
||||
loop.next();
|
||||
|
||||
return loop;
|
||||
},
|
||||
|
||||
balance_supply: function(cb) {
|
||||
Address.find({}, 'balance').where('balance').gt(0).exec(function(err, docs) {
|
||||
var count = 0;
|
||||
|
||||
module.exports.syncLoop(docs.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
count = count + docs[i].balance;
|
||||
loop.next();
|
||||
}, function() {
|
||||
@@ -683,6 +722,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getsupply';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -710,6 +750,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getinfo';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (!body || !body.moneysupply ||body == 'There was an error. Check your console.')
|
||||
@@ -742,6 +783,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'gettxoutsetinfo';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (!body || !body.total_amount ||body == 'There was an error. Check your console.')
|
||||
@@ -776,6 +818,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getpeerinfo';
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -804,6 +847,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'verifymessage?address=' + address + '&signature=' + signature + '&message=' + message;
|
||||
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
@@ -827,16 +871,17 @@ module.exports = {
|
||||
is_unique: function(array, object, cb) {
|
||||
var unique = true;
|
||||
var index = null;
|
||||
|
||||
module.exports.syncLoop(array.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
if (array[i].addresses == object) {
|
||||
unique = false;
|
||||
index = i;
|
||||
loop.break(true);
|
||||
loop.next();
|
||||
} else {
|
||||
} else
|
||||
loop.next();
|
||||
}
|
||||
}, function() {
|
||||
return cb(unique, index);
|
||||
});
|
||||
@@ -844,12 +889,12 @@ module.exports = {
|
||||
|
||||
calculate_total: function(vout, cb) {
|
||||
var total = 0;
|
||||
|
||||
module.exports.syncLoop(vout.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
//module.exports.convert_to_satoshi(parseFloat(vout[i].amount), function(amount_sat){
|
||||
|
||||
total = total + vout[i].amount;
|
||||
loop.next();
|
||||
//});
|
||||
}, function() {
|
||||
return cb(total);
|
||||
});
|
||||
@@ -857,8 +902,8 @@ module.exports = {
|
||||
|
||||
prepare_vout: function(vout, txid, vin, vhidden, cb) {
|
||||
var arr_vout = [];
|
||||
var arr_vin = [];
|
||||
arr_vin = vin;
|
||||
var arr_vin = vin;
|
||||
|
||||
module.exports.syncLoop(vout.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
// make sure vout has an address
|
||||
@@ -906,6 +951,7 @@ module.exports = {
|
||||
// the sent and received values are not known in this case. only the fee paid is known and subtracted from the sender.
|
||||
arr_vout.push({addresses: "private_tx", amount: 0});
|
||||
}
|
||||
|
||||
// add a private send address with the known amount sent
|
||||
arr_vin.push({addresses: "private_tx", amount: amount_sat});
|
||||
});
|
||||
@@ -919,6 +965,7 @@ module.exports = {
|
||||
//PoS
|
||||
arr_vout[0].amount = arr_vout[0].amount - arr_vin[0].amount;
|
||||
arr_vin.shift();
|
||||
|
||||
return cb(arr_vout, arr_vin);
|
||||
} else
|
||||
return cb(arr_vout, arr_vin);
|
||||
@@ -931,10 +978,13 @@ module.exports = {
|
||||
|
||||
get_input_addresses: function(input, vout, cb) {
|
||||
var addresses = [];
|
||||
|
||||
if (input.coinbase) {
|
||||
var amount = 0;
|
||||
|
||||
module.exports.syncLoop(vout.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
amount = amount + parseFloat(vout[i].value);
|
||||
loop.next();
|
||||
}, function() {
|
||||
@@ -946,34 +996,32 @@ module.exports = {
|
||||
if (tx) {
|
||||
module.exports.syncLoop(tx.vout.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
if (tx.vout[i].n == input.vout) {
|
||||
//module.exports.convert_to_satoshi(parseFloat(tx.vout[i].value), function(amount_sat){
|
||||
if (tx.vout[i].scriptPubKey.addresses) {
|
||||
if (tx.vout[i].scriptPubKey.addresses)
|
||||
addresses.push({hash: tx.vout[i].scriptPubKey.addresses[0], amount:tx.vout[i].value});
|
||||
}
|
||||
|
||||
loop.break(true);
|
||||
loop.next();
|
||||
//});
|
||||
} else {
|
||||
} else
|
||||
loop.next();
|
||||
}
|
||||
}, function() {
|
||||
return cb(addresses);
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
prepare_vin: function(tx, cb) {
|
||||
var arr_vin = [];
|
||||
|
||||
module.exports.syncLoop(tx.vin.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
module.exports.get_input_addresses(tx.vin[i], tx.vout, function(addresses) {
|
||||
if (addresses && addresses.length) {
|
||||
//console.log('vin');
|
||||
module.exports.is_unique(arr_vin, addresses[0].hash, function(unique, index) {
|
||||
if (unique == true) {
|
||||
module.exports.convert_to_satoshi(parseFloat(addresses[0].amount), function(amount_sat) {
|
||||
@@ -987,9 +1035,8 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
loop.next();
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
return cb(arr_vin);
|
||||
|
||||
+34
-18
@@ -13,6 +13,7 @@ Client.prototype.call = function(method, params, callback, errback, path) {
|
||||
if (Array.isArray(method)) {
|
||||
// multiple rpc batch call
|
||||
requestJSON = [];
|
||||
|
||||
method.forEach(function(batchCall, i) {
|
||||
requestJSON.push({
|
||||
id: time + '-' + i,
|
||||
@@ -29,7 +30,7 @@ Client.prototype.call = function(method, params, callback, errback, path) {
|
||||
};
|
||||
}
|
||||
|
||||
// First we encode the request into JSON
|
||||
// first we encode the request into JSON
|
||||
var requestJSON = JSON.stringify(requestJSON);
|
||||
|
||||
// prepare request options
|
||||
@@ -51,36 +52,45 @@ Client.prototype.call = function(method, params, callback, errback, path) {
|
||||
}
|
||||
|
||||
// use HTTP auth if user and password set
|
||||
if (this.opts.username && this.opts.password) {
|
||||
if (this.opts.username && this.opts.password)
|
||||
requestOptions.auth = this.opts.username + ':' + this.opts.password;
|
||||
}
|
||||
|
||||
// Now we'll make a request to the server
|
||||
// now make a request to the server
|
||||
var cbCalled = false
|
||||
var request = this.http.request(requestOptions);
|
||||
|
||||
// start request timeout timer
|
||||
var reqTimeout = setTimeout(function() {
|
||||
if (cbCalled) return;
|
||||
if (cbCalled)
|
||||
return;
|
||||
|
||||
cbCalled = true;
|
||||
request.abort();
|
||||
|
||||
var err = new Error('ETIMEDOUT');
|
||||
|
||||
err.code = 'ETIMEDOUT';
|
||||
errback(err);
|
||||
}, this.opts.timeout || 30000);
|
||||
|
||||
// set additional timeout on socket in case of remote freeze after sending headers
|
||||
request.setTimeout(this.opts.timeout || 30000, function() {
|
||||
if (cbCalled) return;
|
||||
if (cbCalled)
|
||||
return;
|
||||
|
||||
cbCalled = true;
|
||||
request.abort();
|
||||
|
||||
var err = new Error('ESOCKETTIMEDOUT');
|
||||
|
||||
err.code = 'ESOCKETTIMEDOUT';
|
||||
errback(err);
|
||||
});
|
||||
|
||||
request.on('error', function(err) {
|
||||
if (cbCalled) return;
|
||||
if (cbCalled)
|
||||
return;
|
||||
|
||||
cbCalled = true;
|
||||
clearTimeout(reqTimeout);
|
||||
errback(err);
|
||||
@@ -89,18 +99,22 @@ Client.prototype.call = function(method, params, callback, errback, path) {
|
||||
request.on('response', function(response) {
|
||||
clearTimeout(reqTimeout);
|
||||
|
||||
// We need to buffer the response chunks in a nonblocking way.
|
||||
// we need to buffer the response chunks in a nonblocking way
|
||||
var buffer = '';
|
||||
|
||||
response.on('data', function(chunk) {
|
||||
buffer = buffer + chunk;
|
||||
});
|
||||
// When all the responses are finished, we decode the JSON and
|
||||
|
||||
// when all the responses are finished, we decode the JSON and
|
||||
// depending on whether it's got a result or an error, we call
|
||||
// emitSuccess or emitError on the promise.
|
||||
response.on('end', function() {
|
||||
var err;
|
||||
|
||||
if (cbCalled) return;
|
||||
if (cbCalled)
|
||||
return;
|
||||
|
||||
cbCalled = true;
|
||||
|
||||
try {
|
||||
@@ -115,12 +129,12 @@ Client.prototype.call = function(method, params, callback, errback, path) {
|
||||
err.code = -32603;
|
||||
errback(err);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Array.isArray(decoded)) {
|
||||
if (!Array.isArray(decoded))
|
||||
decoded = [decoded];
|
||||
}
|
||||
|
||||
// iterate over each response, normally there will be just one
|
||||
// unless a batch rpc call response is being processed
|
||||
@@ -128,27 +142,29 @@ Client.prototype.call = function(method, params, callback, errback, path) {
|
||||
if (decodedResponse.hasOwnProperty('error') && decodedResponse.error != null) {
|
||||
if (errback) {
|
||||
err = new Error(decodedResponse.error.message || '');
|
||||
if (decodedResponse.error.code) {
|
||||
|
||||
if (decodedResponse.error.code)
|
||||
err.code = decodedResponse.error.code;
|
||||
}
|
||||
|
||||
errback(err);
|
||||
}
|
||||
} else if (decodedResponse.hasOwnProperty('result')) {
|
||||
if (callback) {
|
||||
if (callback)
|
||||
callback(decodedResponse.result, response.headers);
|
||||
}
|
||||
} else {
|
||||
if (errback) {
|
||||
err = new Error(decodedResponse.error.message || '');
|
||||
if (decodedResponse.error.code) {
|
||||
|
||||
if (decodedResponse.error.code)
|
||||
err.code = decodedResponse.error.code;
|
||||
}
|
||||
|
||||
errback(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
request.on('error', errback);
|
||||
request.end(requestJSON);
|
||||
};
|
||||
|
||||
+9
-17
@@ -149,12 +149,10 @@ exports.heavy_key = "Key",
|
||||
exports.heavy_lastxvotes = "Last 20 votes",
|
||||
|
||||
exports.reloadLocale = function reloadLocale(locale) {
|
||||
// Discover where the locale file lives
|
||||
var localeFilename = locale;
|
||||
//console.log(localeFilename);
|
||||
localeFilename = "./" + localeFilename;
|
||||
//console.log('Loading locale: ' + localeFilename);
|
||||
// discover where the locale file lives
|
||||
var localeFilename = "./" + locale;
|
||||
var localeStr;
|
||||
|
||||
try {
|
||||
// read the settings sync
|
||||
localeStr = fs.readFileSync(localeFilename).toString();
|
||||
@@ -162,8 +160,9 @@ exports.reloadLocale = function reloadLocale(locale) {
|
||||
console.warn('Locale file not found. Continuing using defaults!');
|
||||
}
|
||||
|
||||
// try to parse the settings
|
||||
var lsettings;
|
||||
|
||||
// try to parse the settings
|
||||
try {
|
||||
if (localeStr) {
|
||||
localeStr = jsonminify(localeStr).replace(",]","]").replace(",}","}");
|
||||
@@ -174,27 +173,20 @@ exports.reloadLocale = function reloadLocale(locale) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
//loop trough the settings
|
||||
for(var i in lsettings)
|
||||
{
|
||||
// loop through the settings
|
||||
for (var i in lsettings) {
|
||||
// test if the setting start with a low character
|
||||
if (i.charAt(0).search("[a-z]") !== 0)
|
||||
{
|
||||
console.warn("Settings should start with a low character: '" + i + "'");
|
||||
}
|
||||
|
||||
if (exports[i] !== undefined) {
|
||||
// we know this setting, so we overwrite it
|
||||
if(exports[i] !== undefined)
|
||||
{
|
||||
exports[i] = lsettings[i];
|
||||
}
|
||||
} else {
|
||||
// this setting is unkown, output a warning and throw it away
|
||||
else
|
||||
{
|
||||
console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// initially load settings
|
||||
|
||||
+24
-27
@@ -6,25 +6,25 @@ function get_summary(coin, exchange, cb) {
|
||||
var req_url = base_url + coin.toLowerCase() + exchange.toLowerCase() + '/tickers';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, null);
|
||||
} else {
|
||||
else {
|
||||
// check for null body as the apis do not work all the time for some reason
|
||||
if (body != null) {
|
||||
if (body.errors) {
|
||||
if (body.errors)
|
||||
return cb(body.errors, null);
|
||||
} else {
|
||||
else {
|
||||
req_url = base_url + coin.toLowerCase() + exchange.toLowerCase() + '/order-book?asks_limit=1&bids_limit=1';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, order_body) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, null);
|
||||
} else {
|
||||
else {
|
||||
// check for null body as the apis do not work all the time for some reason
|
||||
if (body != null) {
|
||||
if (body.errors) {
|
||||
if (body.errors)
|
||||
return cb(body.errors, null);
|
||||
} else {
|
||||
else {
|
||||
var summary = {};
|
||||
|
||||
summary['bid'] = (order_body != null && order_body['bids'] != null && order_body['bids'].length > 0 ? order_body['bids'][0]['price'] : 0);
|
||||
@@ -53,9 +53,9 @@ function get_trades(coin, exchange, cb) {
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check for null body as the apis do not work all the time for some reason
|
||||
if (body != null) {
|
||||
if (body.errors != null) {
|
||||
if (body.errors != null)
|
||||
return cb(body.errors, null);
|
||||
} else {
|
||||
else {
|
||||
var trades = [];
|
||||
|
||||
if (body.length > 0) {
|
||||
@@ -66,7 +66,7 @@ function get_trades(coin, exchange, cb) {
|
||||
quantity: body[i]['amount'],
|
||||
total: body[i]['total'],
|
||||
timestamp: new Date(body[i]['created_at'] * 1000).toUTCString()
|
||||
}
|
||||
};
|
||||
|
||||
trades.push(trade);
|
||||
}
|
||||
@@ -74,9 +74,8 @@ function get_trades(coin, exchange, cb) {
|
||||
|
||||
return cb(null, trades);
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
return cb(api_error_msg, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,9 +85,9 @@ function get_orders(coin, exchange, cb) {
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check for null body as the apis do not work all the time for some reason
|
||||
if (body != null) {
|
||||
if (body.errors) {
|
||||
return cb(body.errors, [], [])
|
||||
} else {
|
||||
if (body.errors)
|
||||
return cb(body.errors, [], []);
|
||||
else {
|
||||
var orders = body;
|
||||
var buys = [];
|
||||
var sells = [];
|
||||
@@ -98,7 +97,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: orders.bids[i][0],
|
||||
quantity: orders.bids[i][1]
|
||||
}
|
||||
};
|
||||
|
||||
buys.push(order);
|
||||
}
|
||||
@@ -109,7 +108,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: orders.asks[i][0],
|
||||
quantity: orders.asks[i][1]
|
||||
}
|
||||
};
|
||||
|
||||
sells.push(order);
|
||||
}
|
||||
@@ -117,23 +116,23 @@ function get_orders(coin, exchange, cb) {
|
||||
|
||||
return cb(null, buys, sells.reverse());
|
||||
}
|
||||
} else {
|
||||
return cb(api_error_msg, [], [])
|
||||
}
|
||||
} else
|
||||
return cb(api_error_msg, [], []);
|
||||
});
|
||||
}
|
||||
|
||||
function get_chartdata(coin, exchange, cb) {
|
||||
var end = Date.now();
|
||||
|
||||
end = end / 1000;
|
||||
start = end - 86400;
|
||||
|
||||
var req_url = base_url + coin.toLowerCase() + exchange.toLowerCase() + '/k-line?time_from=' + parseInt(start) + '&time_to=' + parseInt(end) + '&period=15';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, chartdata) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, []);
|
||||
} else {
|
||||
else {
|
||||
// check for null chartdata as the apis do not work all the time for some reason
|
||||
if (chartdata != null) {
|
||||
if (chartdata.errors == null) {
|
||||
@@ -143,13 +142,11 @@ function get_chartdata(coin, exchange, cb) {
|
||||
processed.push([chartdata[i][0] * 1000, chartdata[i][1], chartdata[i][2], chartdata[i][3], chartdata[i][4]]);
|
||||
|
||||
return cb(null, processed);
|
||||
} else {
|
||||
} else
|
||||
return cb(chartdata.errors, []);
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
return cb(api_error_msg, []);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+22
-20
@@ -1,25 +1,24 @@
|
||||
var request = require('postman-request');
|
||||
|
||||
var base_url = 'https://api.bittrex.com/v3';
|
||||
|
||||
function get_summary(coin, exchange, cb) {
|
||||
var req_url = base_url + '/markets/' + coin + '-' + exchange + '/summary';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, summary) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, null);
|
||||
} else {
|
||||
if (summary.code) {
|
||||
return cb(summary.code, null)
|
||||
} else {
|
||||
else {
|
||||
if (summary.code)
|
||||
return cb(summary.code, null);
|
||||
else {
|
||||
req_url = base_url + '/markets/' + coin + '-' + exchange + '/ticker';
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, ticker) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, null);
|
||||
} else {
|
||||
if (ticker.code) {
|
||||
return cb(ticker.code, null)
|
||||
} else {
|
||||
else {
|
||||
if (ticker.code)
|
||||
return cb(ticker.code, null);
|
||||
else {
|
||||
var retVal = {
|
||||
'high': summary.high,
|
||||
'low': summary.low,
|
||||
@@ -29,6 +28,7 @@ function get_summary(coin, exchange, cb) {
|
||||
'last': ticker.lastTradeRate,
|
||||
'change': summary.percentChange
|
||||
};
|
||||
|
||||
return cb (null, retVal);
|
||||
}
|
||||
}
|
||||
@@ -40,10 +40,11 @@ function get_summary(coin, exchange, cb) {
|
||||
|
||||
function get_trades(coin, exchange, cb) {
|
||||
var req_url = base_url + '/markets/' + coin + '-' + exchange + '/trades';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, null);
|
||||
} else {
|
||||
else {
|
||||
var trades = [];
|
||||
|
||||
if (body.length > 0) {
|
||||
@@ -53,7 +54,7 @@ function get_trades(coin, exchange, cb) {
|
||||
price: body[i]['rate'],
|
||||
quantity: body[i]['quantity'],
|
||||
timestamp: body[i]['executedAt']
|
||||
}
|
||||
};
|
||||
|
||||
trades.push(trade);
|
||||
}
|
||||
@@ -68,9 +69,9 @@ function get_orders(coin, exchange, cb) {
|
||||
var req_url = base_url + '/markets/' + coin + '-' + exchange + '/orderbook?depth=25';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, [], []);
|
||||
} else {
|
||||
else {
|
||||
var buys = [];
|
||||
var sells = [];
|
||||
|
||||
@@ -79,7 +80,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: body.bid[i].rate,
|
||||
quantity: body.bid[i].quantity
|
||||
}
|
||||
};
|
||||
|
||||
buys.push(order);
|
||||
}
|
||||
@@ -90,7 +91,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: body.ask[i].rate,
|
||||
quantity: body.ask[i].quantity
|
||||
}
|
||||
};
|
||||
|
||||
sells.push(order);
|
||||
}
|
||||
@@ -110,9 +111,9 @@ function get_chartdata(coin, exchange, cb) {
|
||||
var req_url = base_url + '/markets/' + coin + '-' + exchange + '/candles/MINUTE_5/recent';
|
||||
|
||||
request({ uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, chartdata) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, []);
|
||||
} else {
|
||||
else {
|
||||
var processed = [];
|
||||
|
||||
for (var i = 0; i < chartdata.length; i++) {
|
||||
@@ -120,6 +121,7 @@ function get_chartdata(coin, exchange, cb) {
|
||||
if (new Date(chartdata[i].startsAt).getTime()/1000 > start && (i % 3) == 0)
|
||||
processed.push([new Date(chartdata[i].startsAt).getTime(), parseFloat(chartdata[i].open), parseFloat(chartdata[i].high), parseFloat(chartdata[i].low), parseFloat(chartdata[i].close)]);
|
||||
}
|
||||
|
||||
return cb(null, processed);
|
||||
}
|
||||
});
|
||||
|
||||
+18
-20
@@ -1,16 +1,16 @@
|
||||
var request = require('postman-request');
|
||||
|
||||
var base_url = 'https://bleutrade.com/api/v3/public';
|
||||
|
||||
function get_summary(coin, exchange, cb) {
|
||||
var req_url = base_url + '/getmarketsummary?market=' + coin + '_' + exchange;
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, null);
|
||||
} else {
|
||||
if (body.message) {
|
||||
return cb(body.message, null)
|
||||
} else {
|
||||
else {
|
||||
if (body.message)
|
||||
return cb(body.message, null);
|
||||
else {
|
||||
var retVal = {
|
||||
'high': body.result.High,
|
||||
'low': body.result.Low,
|
||||
@@ -29,6 +29,7 @@ function get_summary(coin, exchange, cb) {
|
||||
|
||||
function get_trades(coin, exchange, cb) {
|
||||
var req_url = base_url + '/getmarkethistory?market=' + coin + '_' + exchange + '&count=50';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (body.success) {
|
||||
var trades = [];
|
||||
@@ -41,21 +42,21 @@ function get_trades(coin, exchange, cb) {
|
||||
quantity: body.result[i]['Quantity'],
|
||||
total: body.result[i]['Total'],
|
||||
timestamp: body.result[i]['TimeStamp']
|
||||
}
|
||||
};
|
||||
|
||||
trades.push(trade);
|
||||
}
|
||||
}
|
||||
|
||||
return cb(null, trades);
|
||||
} else {
|
||||
} else
|
||||
return cb(body.message, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function get_orders(coin, exchange, cb) {
|
||||
var req_url = base_url + '/getorderbook?market=' + coin + '_' + exchange + '&type=all' + '&depth=50';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (body.success) {
|
||||
var orders = body.result;
|
||||
@@ -67,7 +68,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: orders.buy[i].Rate,
|
||||
quantity: orders.buy[i].Quantity
|
||||
}
|
||||
};
|
||||
|
||||
buys.push(order);
|
||||
}
|
||||
@@ -78,16 +79,15 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: orders.sell[i].Rate,
|
||||
quantity: orders.sell[i].Quantity
|
||||
}
|
||||
};
|
||||
|
||||
sells.push(order);
|
||||
}
|
||||
}
|
||||
|
||||
return cb(null, buys, sells);
|
||||
} else {
|
||||
return cb(body.message, [], [])
|
||||
}
|
||||
} else
|
||||
return cb(body.message, [], []);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,22 +100,20 @@ function get_chartdata(coin, exchange, cb) {
|
||||
var req_url = base_url + '/getcandles/?market=' + coin + '_' + exchange + '&period=1h';
|
||||
|
||||
request({ uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, chartdata) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, []);
|
||||
} else {
|
||||
else {
|
||||
if (chartdata.success) {
|
||||
var processed = [];
|
||||
|
||||
for (var i = 0; i < chartdata.result.length; i++) {
|
||||
// only take values more recent than the last 24 hours
|
||||
if (new Date(chartdata.result[i].TimeStamp).getTime()/1000 > start) {
|
||||
if (new Date(chartdata.result[i].TimeStamp).getTime()/1000 > start)
|
||||
processed.push([new Date(chartdata.result[i].TimeStamp).getTime(), parseFloat(chartdata.result[i].Open), parseFloat(chartdata.result[i].High), parseFloat(chartdata.result[i].Low), parseFloat(chartdata.result[i].Close)]);
|
||||
}
|
||||
}
|
||||
|
||||
return cb(null, processed);
|
||||
}
|
||||
else
|
||||
} else
|
||||
return cb(chartdata.message, []);
|
||||
}
|
||||
});
|
||||
|
||||
+9
-11
@@ -1,14 +1,13 @@
|
||||
var request = require('postman-request');
|
||||
|
||||
var base_url = 'https://api.crex24.com/v2/public';
|
||||
|
||||
function get_summary(coin, exchange, cb) {
|
||||
var url=base_url + '/tickers?instrument=' + coin.toUpperCase() + '-' + exchange.toUpperCase();
|
||||
|
||||
request({uri: url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, null);
|
||||
} else if (body.error !== true) {
|
||||
else if (body.error !== true) {
|
||||
var summary = {};
|
||||
|
||||
summary['ask'] = body[0]['ask'];
|
||||
@@ -21,9 +20,8 @@ function get_summary(coin, exchange, cb) {
|
||||
summary['change'] = body[0]['percentChange'];
|
||||
|
||||
return cb(null, summary);
|
||||
} else {
|
||||
} else
|
||||
return cb(error, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,7 +40,7 @@ function get_trades(coin, exchange, cb) {
|
||||
quantity: body[i].volume,
|
||||
price: body[i].price,
|
||||
timestamp: body[i].timestamp
|
||||
}
|
||||
};
|
||||
|
||||
trades.push(trade);
|
||||
}
|
||||
@@ -68,7 +66,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: body['buyLevels'][i].price,
|
||||
quantity: body['buyLevels'][i].volume
|
||||
}
|
||||
};
|
||||
|
||||
buys.push(order);
|
||||
}
|
||||
@@ -79,7 +77,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: body['sellLevels'][i].price,
|
||||
quantity: body['sellLevels'][i].volume
|
||||
}
|
||||
};
|
||||
|
||||
sells.push(order);
|
||||
}
|
||||
@@ -87,7 +85,7 @@ function get_orders(coin, exchange, cb) {
|
||||
|
||||
return cb(null, buys, sells);
|
||||
} else
|
||||
return cb(body.Message, [], [])
|
||||
return cb(body.Message, [], []);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,9 +98,9 @@ function get_chartdata(coin, exchange, cb) {
|
||||
var req_url = base_url + '/ohlcv?instrument=' + coin.toUpperCase() + '-' + exchange.toUpperCase() + '&granularity=15m&limit=100';
|
||||
|
||||
request({ uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, chartdata) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, []);
|
||||
} else {
|
||||
else {
|
||||
var processed = [];
|
||||
|
||||
for (var i = 0; i < chartdata.length; i++)
|
||||
|
||||
+12
-12
@@ -1,5 +1,4 @@
|
||||
var request = require('postman-request');
|
||||
|
||||
var base_url = 'https://poloniex.com/public?command=';
|
||||
|
||||
function get_summary(coin, exchange, cb) {
|
||||
@@ -7,9 +6,9 @@ function get_summary(coin, exchange, cb) {
|
||||
var ticker = exchange + '_' + coin;
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (body.error) {
|
||||
if (body.error)
|
||||
return cb(body.error, null);
|
||||
} else {
|
||||
else {
|
||||
var retVal = {
|
||||
'high': body[ticker].high24hr,
|
||||
'low': body[ticker].low24hr,
|
||||
@@ -29,9 +28,9 @@ function get_trades(coin, exchange, cb) {
|
||||
var req_url = base_url + 'returnTradeHistory¤cyPair=' + exchange + '_' + coin;
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (body.error) {
|
||||
if (body.error)
|
||||
return cb(body.error, []);
|
||||
} else {
|
||||
else {
|
||||
var trades = [];
|
||||
|
||||
if (body.length > 0) {
|
||||
@@ -42,7 +41,7 @@ function get_trades(coin, exchange, cb) {
|
||||
quantity: body[i]['amount'],
|
||||
total: body[i]['total'],
|
||||
timestamp: body[i]['date']
|
||||
}
|
||||
};
|
||||
|
||||
trades.push(trade);
|
||||
}
|
||||
@@ -57,9 +56,9 @@ function get_orders(coin, exchange, cb) {
|
||||
var req_url = base_url + 'returnOrderBook¤cyPair=' + exchange + '_' + coin + '&depth=50';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (body.error) {
|
||||
if (body.error)
|
||||
return cb(body.error, []);
|
||||
} else {
|
||||
else {
|
||||
var buys = [];
|
||||
var sells = [];
|
||||
|
||||
@@ -68,7 +67,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: body.bids[i][0],
|
||||
quantity: body.bids[i][1]
|
||||
}
|
||||
};
|
||||
|
||||
buys.push(order);
|
||||
}
|
||||
@@ -79,7 +78,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: body.asks[i][0],
|
||||
quantity: body.asks[i][1]
|
||||
}
|
||||
};
|
||||
|
||||
sells.push(order);
|
||||
}
|
||||
@@ -92,15 +91,16 @@ function get_orders(coin, exchange, cb) {
|
||||
|
||||
function get_chartdata(coin, exchange, cb) {
|
||||
var end = Date.now();
|
||||
|
||||
end = end / 1000;
|
||||
start = end - 86400;
|
||||
|
||||
var req_url = base_url + 'returnChartData¤cyPair=' + exchange + '_' + coin + '&start=' + start + '&end=' + end + '&period=1800';
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, chartdata) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, []);
|
||||
} else {
|
||||
else {
|
||||
if (chartdata.error == null) {
|
||||
var processed = [];
|
||||
|
||||
|
||||
+5
-6
@@ -1,5 +1,4 @@
|
||||
var request = require('postman-request');
|
||||
|
||||
var base_url = 'https://api3.stex.com/public';
|
||||
|
||||
function get_summary(coin, exchange, stex_id, cb) {
|
||||
@@ -39,7 +38,7 @@ function get_trades(coin, exchange, stex_id, cb) {
|
||||
price: body.data[i].price,
|
||||
quantity: body.data[i].amount,
|
||||
timestamp: new Date(body.data[i].timestamp * 1000).toUTCString()
|
||||
}
|
||||
};
|
||||
|
||||
trades.push(trade);
|
||||
}
|
||||
@@ -66,7 +65,7 @@ function get_orders(coin, exchange, stex_id, cb) {
|
||||
var order = {
|
||||
price: orders.bid[i].price,
|
||||
quantity: orders.bid[i].amount
|
||||
}
|
||||
};
|
||||
|
||||
buys.push(order);
|
||||
}
|
||||
@@ -77,7 +76,7 @@ function get_orders(coin, exchange, stex_id, cb) {
|
||||
var order = {
|
||||
price: orders.ask[i].price,
|
||||
quantity: orders.ask[i].amount
|
||||
}
|
||||
};
|
||||
|
||||
sells.push(order);
|
||||
}
|
||||
@@ -100,9 +99,9 @@ function get_chartdata(coin, exchange, stex_id, cb) {
|
||||
var req_url = base_url + '/chart/' + stex_id + '/30?timeStart=' + start + '&timeEnd=' + end + '&limit=1800&candlesType=1D';
|
||||
|
||||
request({ uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, chartdata) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, []);
|
||||
} else {
|
||||
else {
|
||||
if (chartdata.success == true) {
|
||||
var processed = [];
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
var request = require('postman-request');
|
||||
|
||||
var base_url = 'https://yobit.io/api/3';
|
||||
|
||||
function get_summary(coin, exchange, cb) {
|
||||
var req_url = base_url + '/ticker/' + coin + '_' + exchange;
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, null);
|
||||
} else {
|
||||
else {
|
||||
if (body.message)
|
||||
return cb(body.message, null);
|
||||
else {
|
||||
@@ -30,9 +30,9 @@ function get_trades(coin, exchange, cb) {
|
||||
var req_url = base_url + '/trades/' + coin + '_' + exchange;
|
||||
|
||||
request({uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
if (error) {
|
||||
if (error)
|
||||
return cb(error, null);
|
||||
} else {
|
||||
else {
|
||||
if (body.message)
|
||||
return cb(body.message, null);
|
||||
else {
|
||||
@@ -44,7 +44,7 @@ function get_trades(coin, exchange, cb) {
|
||||
price: body[coin + '_' + exchange][i].price,
|
||||
quantity: body[coin + '_' + exchange][i].amount,
|
||||
timestamp: new Date(body[coin + '_' + exchange][i].timestamp * 1000).toUTCString()
|
||||
}
|
||||
};
|
||||
|
||||
trades.push(trade);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: orders.bids[i][0],
|
||||
quantity: orders.bids[i][1]
|
||||
}
|
||||
};
|
||||
|
||||
buys.push(order);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ function get_orders(coin, exchange, cb) {
|
||||
var order = {
|
||||
price: orders.asks[i][0],
|
||||
quantity: orders.asks[i][1]
|
||||
}
|
||||
};
|
||||
|
||||
sells.push(order);
|
||||
}
|
||||
|
||||
+4
-4
@@ -14,15 +14,15 @@ Client.prototype.cmd = function() {
|
||||
function callRpc (cmd, args, rpc) {
|
||||
var fn = args[args.length - 1];
|
||||
|
||||
// If the last argument is a callback, pop it from the args list
|
||||
if (typeof fn === 'function') {
|
||||
// if the last argument is a callback, pop it from the args list
|
||||
if (typeof fn === 'function')
|
||||
args.pop();
|
||||
} else {
|
||||
else
|
||||
fn = function () {};
|
||||
}
|
||||
|
||||
rpc.call(cmd, args, function () {
|
||||
var args = [].slice.call(arguments);
|
||||
|
||||
args.unshift(null);
|
||||
fn.apply(this, args);
|
||||
}, function(err) {
|
||||
|
||||
+33
-6
@@ -1,6 +1,6 @@
|
||||
var onode = require('./node');
|
||||
var express = require('express');
|
||||
var settings = require('./settings');
|
||||
var onode = require('./node'),
|
||||
express = require('express'),
|
||||
settings = require('./settings');
|
||||
|
||||
module.exports = function() {
|
||||
function express_app() {
|
||||
@@ -22,8 +22,10 @@ module.exports = function() {
|
||||
for (var parameter in query_parameters) {
|
||||
if (query_parameters.hasOwnProperty(parameter)) {
|
||||
var param = query_parameters[parameter];
|
||||
|
||||
if (!isNaN(param))
|
||||
param = parseFloat(param);
|
||||
|
||||
params.push(param);
|
||||
}
|
||||
}
|
||||
@@ -62,6 +64,7 @@ module.exports = function() {
|
||||
method: method,
|
||||
params: params
|
||||
}];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -159,8 +162,10 @@ module.exports = function() {
|
||||
case 'getmasternodecount':
|
||||
case 'getmasternodelist':
|
||||
var cmd = prepareRpcCommand(settings.api_cmds[method_name]);
|
||||
|
||||
method_name = cmd.method;
|
||||
params = cmd.parameters;
|
||||
|
||||
break;
|
||||
case 'getmaxmoney':
|
||||
case 'getmaxvote':
|
||||
@@ -171,26 +176,34 @@ module.exports = function() {
|
||||
case 'getnextrewardwhenstr':
|
||||
case 'getsupply':
|
||||
var cmd = prepareRpcCommand(settings.blockchain_specific.heavycoin.api_cmds[method_name]);
|
||||
|
||||
method_name = cmd.method;
|
||||
params = cmd.parameters;
|
||||
|
||||
break;
|
||||
case 'getblockhash':
|
||||
for (var parameter in query_parameters) {
|
||||
if (query_parameters.hasOwnProperty(parameter) && (parameter == 'height' || parameter == 'index'))
|
||||
params.push(parseInt(query_parameters[parameter]));
|
||||
}
|
||||
|
||||
var cmd = prepareRpcCommand(settings.api_cmds.getblockhash, params);
|
||||
|
||||
method_name = cmd.method;
|
||||
params = cmd.parameters;
|
||||
|
||||
break;
|
||||
case 'getblock':
|
||||
for (var parameter in query_parameters) {
|
||||
if (query_parameters.hasOwnProperty(parameter) && parameter == 'hash')
|
||||
params.push(query_parameters[parameter]);
|
||||
}
|
||||
|
||||
var cmd = prepareRpcCommand(settings.api_cmds.getblock, params);
|
||||
|
||||
method_name = cmd.method;
|
||||
params = cmd.parameters;
|
||||
|
||||
break;
|
||||
case 'getrawtransaction':
|
||||
for (var parameter in query_parameters) {
|
||||
@@ -201,9 +214,12 @@ module.exports = function() {
|
||||
params.push(parseInt(query_parameters[parameter]));
|
||||
}
|
||||
}
|
||||
|
||||
var cmd = prepareRpcCommand(settings.api_cmds.getrawtransaction, params);
|
||||
|
||||
method_name = cmd.method;
|
||||
params = cmd.parameters;
|
||||
|
||||
break;
|
||||
case 'verifymessage':
|
||||
for (var parameter in query_parameters) {
|
||||
@@ -218,33 +234,43 @@ module.exports = function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cmd = prepareRpcCommand(settings.api_cmds.verifymessage, params);
|
||||
|
||||
method_name = cmd.method;
|
||||
params = cmd.parameters;
|
||||
|
||||
break;
|
||||
case 'sendmany':
|
||||
var after_account = false;
|
||||
var before_min_conf = true;
|
||||
var address_info = {};
|
||||
|
||||
for (var parameter in query_parameters) {
|
||||
if (query_parameters.hasOwnProperty(parameter)) {
|
||||
if (parameter == 'minconf') {
|
||||
before_min_conf = false;
|
||||
params.push(address_info);
|
||||
}
|
||||
|
||||
var param = query_parameters[parameter];
|
||||
|
||||
if (!isNaN(param))
|
||||
param = parseFloat(param);
|
||||
|
||||
if (after_account && before_min_conf)
|
||||
address_info[parameter] = param;
|
||||
else
|
||||
params.push(param);
|
||||
|
||||
if (parameter == 'account')
|
||||
after_account = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (before_min_conf)
|
||||
params.push(address_info);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -258,7 +284,6 @@ module.exports = function() {
|
||||
};
|
||||
|
||||
var accesslist = {};
|
||||
accesslist.type = 'all';
|
||||
var client = {};
|
||||
var wallet_passphrase = null;
|
||||
var requires_passphrase = {
|
||||
@@ -272,8 +297,10 @@ module.exports = function() {
|
||||
'signrawtransaction': true
|
||||
};
|
||||
|
||||
accesslist.type = 'all';
|
||||
|
||||
function setAccess(type, access_list) {
|
||||
//Reset//
|
||||
// reset
|
||||
accesslist = {};
|
||||
accesslist.type = type;
|
||||
|
||||
@@ -287,7 +314,7 @@ module.exports = function() {
|
||||
accesslist[access_list[i]] = false;
|
||||
}
|
||||
|
||||
//Default is for security reasons. Prevents accidental theft of coins/attack
|
||||
// default is for security reasons. Prevents accidental theft of coins/attack
|
||||
if (type == 'default-safe') {
|
||||
var restrict_list = ['dumpprivkey', 'walletpassphrasechange', 'stop'];
|
||||
|
||||
|
||||
+6
-6
@@ -27,16 +27,16 @@ var RateLimit = (function() {
|
||||
if (this._queue.length === 0) {
|
||||
this._numOps++;
|
||||
fn();
|
||||
}
|
||||
else {
|
||||
if (fn) this._queue.push(fn);
|
||||
} else {
|
||||
if (fn)
|
||||
this._queue.push(fn);
|
||||
|
||||
this._numOps++;
|
||||
this._queue.shift()();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (fn) this._queue.push(fn);
|
||||
} else {
|
||||
if (fn)
|
||||
this._queue.push(fn);
|
||||
|
||||
setTimeout(function() {
|
||||
that.schedule();
|
||||
|
||||
+4
-6
@@ -1,6 +1,4 @@
|
||||
/*
|
||||
This file must be valid JSON. But comments are allowed
|
||||
*/
|
||||
/* This file must be valid JSON. But comments are allowed */
|
||||
{
|
||||
// menu items
|
||||
"menu_explorer": "Explorer",
|
||||
@@ -114,7 +112,7 @@
|
||||
"api_getnextrewardestimate": "Returns an estimate for the next block reward based on the current state of decentralized voting.",
|
||||
"api_getnextrewardwhenstr": "Returns a string describing how long until the votes are tallied and the next block reward is computed.",
|
||||
|
||||
// Markets view
|
||||
// markets view
|
||||
"mkt_hours": "24 hours",
|
||||
"mkt_view_chart": "View 24 hour summary",
|
||||
"mkt_view_summary": "View 24 hour chart",
|
||||
@@ -137,7 +135,7 @@
|
||||
"mkt_time_stamp": "Time Stamp",
|
||||
"mkt_select": "Market Select",
|
||||
|
||||
// Heavycoin rewards view
|
||||
// heavycoin rewards view
|
||||
"heavy_title": "Reward/voting information",
|
||||
"heavy_vote": "Vote",
|
||||
"heavy_cap": "Coin Cap",
|
||||
@@ -148,5 +146,5 @@
|
||||
"heavy_estnext": "Est. Next",
|
||||
"heavy_changein": "Reward change in approximately",
|
||||
"heavy_key": "Key",
|
||||
"heavy_lastxvotes": "Last 20 votes",
|
||||
"heavy_lastxvotes": "Last 20 votes"
|
||||
}
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
var AddressSchema = new Schema({
|
||||
a_id: { type: String, unique: true, index: true},
|
||||
@@ -10,4 +10,3 @@ var AddressSchema = new Schema({
|
||||
}, {id: false});
|
||||
|
||||
module.exports = mongoose.model('Address', AddressSchema);
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
var AddressTXSchema = new Schema({
|
||||
a_id: { type: String, index: true},
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
var HeavySchema = new Schema({
|
||||
coin: { type: String },
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
var MarketsSchema = new Schema({
|
||||
market: { type: String, index: true },
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
var MasternodeSchema = new Schema({
|
||||
rank: { type: Number, default: 0 },
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
var PeersSchema = new Schema({
|
||||
createdAt: { type: Date, expires: 86400, default: Date.now() },
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
var RichlistSchema = new Schema({
|
||||
coin: { type: String },
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
var StatsSchema = new Schema({
|
||||
coin: { type: String },
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Schema = mongoose.Schema;
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
var TxSchema = new Schema({
|
||||
txid: { type: String, lowercase: true, unique: true, index: true},
|
||||
@@ -8,7 +8,7 @@ var TxSchema = new Schema({
|
||||
total: { type: Number, default: 0, index: true },
|
||||
timestamp: { type: Number, default: 0, index: true },
|
||||
blockhash: { type: String, index: true },
|
||||
blockindex: {type: Number, default: 0, index: true},
|
||||
blockindex: {type: Number, default: 0, index: true}
|
||||
}, {id: false});
|
||||
|
||||
TxSchema.index({total: 1, total: -1, blockindex: 1, blockindex: -1});
|
||||
|
||||
+36
-35
@@ -1,23 +1,24 @@
|
||||
var express = require('express')
|
||||
, router = express.Router()
|
||||
, settings = require('../lib/settings')
|
||||
, locale = require('../lib/locale')
|
||||
, db = require('../lib/database')
|
||||
, lib = require('../lib/explorer')
|
||||
, qr = require('qr-image');
|
||||
var express = require('express'),
|
||||
router = express.Router(),
|
||||
settings = require('../lib/settings'),
|
||||
locale = require('../lib/locale'),
|
||||
db = require('../lib/database'),
|
||||
lib = require('../lib/explorer'),
|
||||
qr = require('qr-image');
|
||||
|
||||
function route_get_block(res, blockhash) {
|
||||
lib.get_block(blockhash, function (block) {
|
||||
if (block && block != 'There was an error. Check your console.') {
|
||||
if (blockhash == settings.block_page.genesis_block) {
|
||||
if (blockhash == settings.block_page.genesis_block)
|
||||
res.render('block', { active: 'block', block: block, confirmations: settings.shared_pages.confirmations, txs: 'GENESIS', showSync: db.check_show_sync_message()});
|
||||
} else {
|
||||
else {
|
||||
db.get_txs(block, function(txs) {
|
||||
if (txs.length > 0) {
|
||||
if (txs.length > 0)
|
||||
res.render('block', { active: 'block', block: block, confirmations: settings.shared_pages.confirmations, txs: txs, showSync: db.check_show_sync_message()});
|
||||
} else {
|
||||
else {
|
||||
// cannot find block in local database so get the data from the wallet directly
|
||||
var ntxs = [];
|
||||
|
||||
lib.syncLoop(block.tx.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
@@ -31,6 +32,7 @@ function route_get_block(res, blockhash) {
|
||||
vout: vout,
|
||||
total: total.toFixed(8)
|
||||
});
|
||||
|
||||
loop.next();
|
||||
});
|
||||
});
|
||||
@@ -47,25 +49,25 @@ function route_get_block(res, blockhash) {
|
||||
} else {
|
||||
if (!isNaN(blockhash)) {
|
||||
var height = blockhash;
|
||||
|
||||
lib.get_blockhash(height, function(hash) {
|
||||
if (hash && hash != 'There was an error. Check your console.') {
|
||||
if (hash && hash != 'There was an error. Check your console.')
|
||||
res.redirect('/block/' + hash);
|
||||
} else {
|
||||
else
|
||||
route_get_index(res, 'Block not found: ' + blockhash);
|
||||
});
|
||||
} else
|
||||
route_get_index(res, 'Block not found: ' + blockhash);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
route_get_index(res, 'Block not found: ' + blockhash);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* GET functions */
|
||||
|
||||
function route_get_tx(res, txid) {
|
||||
if (txid == settings.transaction_page.genesis_tx) {
|
||||
if (txid == settings.transaction_page.genesis_tx)
|
||||
route_get_block(res, settings.block_page.genesis_block);
|
||||
} else {
|
||||
else {
|
||||
db.get_tx(txid, function(tx) {
|
||||
if (tx) {
|
||||
lib.get_blockcount(function(blockcount) {
|
||||
@@ -73,9 +75,8 @@ function route_get_tx(res, txid) {
|
||||
db.populate_claim_address_names(tx, function(tx) {
|
||||
res.render('tx', { active: 'tx', tx: tx, confirmations: settings.shared_pages.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
res.render('tx', { active: 'tx', tx: tx, confirmations: settings.shared_pages.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
lib.get_rawtransaction(txid, function(rtx) {
|
||||
@@ -91,16 +92,15 @@ function route_get_tx(res, txid) {
|
||||
total: total.toFixed(8),
|
||||
timestamp: rtx.time,
|
||||
blockhash: '-',
|
||||
blockindex: -1,
|
||||
blockindex: -1
|
||||
};
|
||||
|
||||
if (settings.claim_address_page.enabled == true) {
|
||||
db.populate_claim_address_names(utx, function(utx) {
|
||||
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.shared_pages.confirmations, blockcount:-1, showSync: db.check_show_sync_message()});
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.shared_pages.confirmations, blockcount:-1, showSync: db.check_show_sync_message()});
|
||||
}
|
||||
} else {
|
||||
// check if blockheight exists
|
||||
if (!rtx.blockheight && rtx.blockhash) {
|
||||
@@ -115,16 +115,16 @@ function route_get_tx(res, txid) {
|
||||
total: total.toFixed(8),
|
||||
timestamp: rtx.time,
|
||||
blockhash: rtx.blockhash,
|
||||
blockindex: block.height,
|
||||
blockindex: block.height
|
||||
};
|
||||
|
||||
lib.get_blockcount(function(blockcount) {
|
||||
if (settings.claim_address_page.enabled == true) {
|
||||
db.populate_claim_address_names(utx, function(utx) {
|
||||
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.shared_pages.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.shared_pages.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// cannot load tx
|
||||
@@ -140,25 +140,24 @@ function route_get_tx(res, txid) {
|
||||
total: total.toFixed(8),
|
||||
timestamp: rtx.time,
|
||||
blockhash: rtx.blockhash,
|
||||
blockindex: rtx.blockheight,
|
||||
blockindex: rtx.blockheight
|
||||
};
|
||||
|
||||
lib.get_blockcount(function(blockcount) {
|
||||
if (settings.claim_address_page.enabled == true) {
|
||||
db.populate_claim_address_names(utx, function(utx) {
|
||||
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.shared_pages.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.shared_pages.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
route_get_index(res, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -206,6 +205,7 @@ function route_get_claim_form(res, hash) {
|
||||
}
|
||||
|
||||
/* GET home page. */
|
||||
|
||||
router.get('/', function(req, res) {
|
||||
route_get_index(res, null);
|
||||
});
|
||||
@@ -245,7 +245,7 @@ router.get('/markets/:market/:coin_symbol/:pair_symbol', function(req, res) {
|
||||
market_logo: (market_data.market_logo == null ? '' : market_data.market_logo),
|
||||
coin: coin_symbol,
|
||||
exchange: pair_symbol,
|
||||
data: data,
|
||||
data: data
|
||||
},
|
||||
market: market_id,
|
||||
last_updated: stats.markets_last_updated,
|
||||
@@ -261,7 +261,7 @@ router.get('/markets/:market/:coin_symbol/:pair_symbol', function(req, res) {
|
||||
market_logo: (market_data.market_logo == null ? '' : market_data.market_logo),
|
||||
coin: coin_symbol,
|
||||
exchange: pair_symbol,
|
||||
data: data,
|
||||
data: data
|
||||
},
|
||||
market: market_id,
|
||||
last_updated: null,
|
||||
@@ -484,6 +484,7 @@ router.get('/qr/:string', function(req, res) {
|
||||
margin: 1,
|
||||
ec_level: 'M'
|
||||
});
|
||||
|
||||
res.type('png');
|
||||
address.pipe(res);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
var mongoose = require('mongoose')
|
||||
, db = require('../lib/database')
|
||||
, Tx = require('../models/tx')
|
||||
, Address = require('../models/address')
|
||||
, settings = require('../lib/settings');
|
||||
|
||||
var mongoose = require('mongoose'),
|
||||
db = require('../lib/database'),
|
||||
Tx = require('../models/tx'),
|
||||
Address = require('../models/address'),
|
||||
settings = require('../lib/settings');
|
||||
|
||||
var COUNT = 5000; // number of blocks to index
|
||||
|
||||
@@ -24,11 +23,14 @@ mongoose.connect(dbString, { useNewUrlParser: true, useCreateIndex: true, useUni
|
||||
console.log('Aborting');
|
||||
exit();
|
||||
}
|
||||
|
||||
Tx.deleteMany({}, function(err) {
|
||||
Address.deleteMany({}, function(err2) {
|
||||
var s_timer = new Date().getTime();
|
||||
|
||||
db.update_tx_db(settings.coin.name, 1, COUNT, 0, settings.sync.update_timeout, function() {
|
||||
var e_timer = new Date().getTime();
|
||||
|
||||
Tx.countDocuments({}, function(txerr, txcount) {
|
||||
Address.countDocuments({}, function(aerr, acount) {
|
||||
var stats = {
|
||||
@@ -36,6 +38,7 @@ mongoose.connect(dbString, { useNewUrlParser: true, useCreateIndex: true, useUni
|
||||
address_count: acount,
|
||||
seconds: (e_timer - s_timer)/1000,
|
||||
};
|
||||
|
||||
console.log(stats);
|
||||
exit();
|
||||
});
|
||||
|
||||
@@ -14,7 +14,9 @@ main() {
|
||||
if [ $currentblockcount -ne $endingblockcount ]; then
|
||||
forcesync $currentblockcount
|
||||
currentblockcount=$((currentblockcount + 1))
|
||||
else exit; fi
|
||||
else
|
||||
exit;
|
||||
fi
|
||||
main
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ main() {
|
||||
if [ $currentblockcount -ne $previousblockcount ]; then
|
||||
echo "New block found. Syncing..."
|
||||
forcesync $currentblockcount
|
||||
else echo "No new block found. Sleeping..."; fi
|
||||
else
|
||||
echo "No new block found. Sleeping...";
|
||||
fi
|
||||
sleep 20
|
||||
main
|
||||
}
|
||||
|
||||
+53
-37
@@ -1,13 +1,12 @@
|
||||
var mongoose = require('mongoose')
|
||||
, lib = require('../lib/explorer')
|
||||
, db = require('../lib/database')
|
||||
, Tx = require('../models/tx')
|
||||
, Address = require('../models/address')
|
||||
, AddressTx = require('../models/addresstx')
|
||||
, Richlist = require('../models/richlist')
|
||||
, Stats = require('../models/stats')
|
||||
, settings = require('../lib/settings');
|
||||
|
||||
var mongoose = require('mongoose'),
|
||||
lib = require('../lib/explorer'),
|
||||
db = require('../lib/database'),
|
||||
Tx = require('../models/tx'),
|
||||
Address = require('../models/address'),
|
||||
AddressTx = require('../models/addresstx'),
|
||||
Richlist = require('../models/richlist'),
|
||||
Stats = require('../models/stats'),
|
||||
settings = require('../lib/settings');
|
||||
var mode = 'update';
|
||||
var database = 'index';
|
||||
|
||||
@@ -30,18 +29,17 @@ function usage() {
|
||||
console.log('- \'current block\' is the latest created block when script is executed.');
|
||||
console.log('- The market + peers databases only support (& defaults to) reindex mode.');
|
||||
console.log('- If check mode finds missing data (ignoring new data since last sync),');
|
||||
console.log(' index_timeout in settings.json is set too low.')
|
||||
console.log(' index_timeout in settings.json is set too low.');
|
||||
console.log('');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// check options
|
||||
if (process.argv[2] == 'index') {
|
||||
if (process.argv.length <3) {
|
||||
if (process.argv.length < 3)
|
||||
usage();
|
||||
} else {
|
||||
switch(process.argv[3])
|
||||
{
|
||||
else {
|
||||
switch(process.argv[3]) {
|
||||
case 'update':
|
||||
mode = 'update';
|
||||
break;
|
||||
@@ -64,62 +62,58 @@ if (process.argv[2] == 'index') {
|
||||
usage();
|
||||
}
|
||||
}
|
||||
} else if (process.argv[2] == 'market') {
|
||||
} else if (process.argv[2] == 'market')
|
||||
database = 'market';
|
||||
} else if (process.argv[2] == 'peers') {
|
||||
else if (process.argv[2] == 'peers')
|
||||
database = 'peers';
|
||||
} else if (process.argv[2] == 'masternodes') {
|
||||
else if (process.argv[2] == 'masternodes')
|
||||
database = 'masternodes';
|
||||
} else {
|
||||
else
|
||||
usage();
|
||||
}
|
||||
|
||||
function create_lock(cb) {
|
||||
if (database == 'index') {
|
||||
var fname = './tmp/' + database + '.pid';
|
||||
|
||||
db.fs.appendFile(fname, process.pid.toString(), function (err) {
|
||||
if (err) {
|
||||
console.log("Error: unable to create %s", fname);
|
||||
process.exit(1);
|
||||
} else {
|
||||
} else
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
return cb();
|
||||
}
|
||||
}
|
||||
|
||||
function remove_lock(cb) {
|
||||
if (database == 'index') {
|
||||
var fname = './tmp/' + database + '.pid';
|
||||
|
||||
db.fs.unlink(fname, function (err) {
|
||||
if (err) {
|
||||
console.log("unable to remove lock: %s", fname);
|
||||
process.exit(1);
|
||||
} else {
|
||||
} else
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
return cb();
|
||||
}
|
||||
}
|
||||
|
||||
function is_locked(cb) {
|
||||
if (database == 'index') {
|
||||
var fname = './tmp/' + database + '.pid';
|
||||
|
||||
db.fs.exists(fname, function (exists) {
|
||||
if(exists) {
|
||||
if (exists)
|
||||
return cb(true);
|
||||
} else {
|
||||
else
|
||||
return cb(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
} else
|
||||
return cb();
|
||||
}
|
||||
}
|
||||
|
||||
function exit() {
|
||||
remove_lock(function() {
|
||||
@@ -137,6 +131,7 @@ dbString = dbString + '/' + settings.dbsettings.database;
|
||||
if (database == 'peers') {
|
||||
var rateLimitLib = require('../lib/ratelimit');
|
||||
console.log('syncing peers.. please wait..');
|
||||
|
||||
// syncing peers does not require a lock
|
||||
mongoose.connect(dbString, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true, useFindAndModify: false }, function(err) {
|
||||
if (err) {
|
||||
@@ -159,8 +154,9 @@ if (database == 'peers') {
|
||||
exit();
|
||||
});
|
||||
}
|
||||
console.log('Updated peer %s [%s/%s]', address, (i + 1).toString(), body.length.toString());
|
||||
|
||||
// peer already exists
|
||||
console.log('Updated peer %s [%s/%s]', address, (i + 1).toString(), body.length.toString());
|
||||
loop.next();
|
||||
} else {
|
||||
rateLimit.schedule(function() {
|
||||
@@ -203,6 +199,7 @@ if (database == 'peers') {
|
||||
});
|
||||
} else if (database == 'masternodes') {
|
||||
console.log('syncing masternodes.. please wait..');
|
||||
|
||||
// syncing masternodes does not require a lock
|
||||
mongoose.connect(dbString, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true, useFindAndModify: false }, function(err) {
|
||||
if (err) {
|
||||
@@ -214,6 +211,7 @@ if (database == 'peers') {
|
||||
if (body != null) {
|
||||
lib.syncLoop(body.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
db.save_masternode(body[i], function (success) {
|
||||
if (success)
|
||||
loop.next();
|
||||
@@ -265,13 +263,16 @@ if (database == 'peers') {
|
||||
if (mode == 'reindex') {
|
||||
Tx.deleteMany({}, function(err) {
|
||||
console.log('TXs cleared.');
|
||||
|
||||
Address.deleteMany({}, function(err2) {
|
||||
console.log('Addresses cleared.');
|
||||
|
||||
AddressTx.deleteMany({}, function(err3) {
|
||||
console.log('Address TXs cleared.');
|
||||
|
||||
Richlist.updateOne({coin: settings.coin.name}, {
|
||||
received: [],
|
||||
balance: [],
|
||||
balance: []
|
||||
}, function(err3) {
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last: 0,
|
||||
@@ -308,6 +309,7 @@ if (database == 'peers') {
|
||||
});
|
||||
} else if (mode == 'check') {
|
||||
console.log('starting check.. please wait..');
|
||||
|
||||
db.update_tx_db(settings.coin.name, 1, stats.count, stats.txes, settings.sync.check_timeout, function() {
|
||||
db.get_stats(settings.coin.name, function(nstats) {
|
||||
console.log('check complete (block: %s)', nstats.last);
|
||||
@@ -342,14 +344,21 @@ if (database == 'peers') {
|
||||
});
|
||||
} else if (mode == 'reindex-rich') {
|
||||
console.log('check richlist');
|
||||
|
||||
db.check_richlist(settings.coin.name, function(exists) {
|
||||
if (exists) console.log('richlist entry found, deleting now..');
|
||||
if (exists)
|
||||
console.log('richlist entry found, deleting now..');
|
||||
|
||||
db.delete_richlist(settings.coin.name, function(deleted) {
|
||||
if (deleted) console.log('richlist entry deleted');
|
||||
if (deleted)
|
||||
console.log('richlist entry deleted');
|
||||
|
||||
db.create_richlist(settings.coin.name, function() {
|
||||
console.log('richlist created.');
|
||||
|
||||
db.update_richlist('received', function() {
|
||||
console.log('richlist updated received.');
|
||||
|
||||
db.update_richlist('balance', function() {
|
||||
// update richlist_last_updated value
|
||||
db.update_last_updated_stats(settings.coin.name, { richlist_last_updated: Math.floor(new Date() / 1000) }, function (cb) {
|
||||
@@ -363,6 +372,7 @@ if (database == 'peers') {
|
||||
});
|
||||
} else if (mode == 'reindex-txcount') {
|
||||
console.log('calculating tx count.. please wait..');
|
||||
|
||||
// Resetting the transaction counter requires a single lookup on the txes collection to find all txes that have a positive or zero total and 1 or more vout
|
||||
Tx.find({'total': {$gte: 0}, 'vout': { $gte: { $size: 1 }}}).countDocuments(function(err, count) {
|
||||
console.log('found tx count: ' + count.toString());
|
||||
@@ -375,11 +385,13 @@ if (database == 'peers') {
|
||||
});
|
||||
} else if (mode == 'reindex-last') {
|
||||
console.log('finding last blockindex.. please wait..');
|
||||
|
||||
// Resetting the last blockindex counter requires a single lookup on the txes collection to find the last indexed blockindex
|
||||
Tx.find({}, {blockindex:1, _id:0}).sort({blockindex: -1}).limit(1).exec(function(err, tx) {
|
||||
// check if any blocks exists
|
||||
if (err != null || tx == null || tx.length == 0) {
|
||||
console.log('no blocks found. setting last blockindex to 0.');
|
||||
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last: 0
|
||||
}, function() {
|
||||
@@ -388,6 +400,7 @@ if (database == 'peers') {
|
||||
});
|
||||
} else {
|
||||
console.log('found last blockindex: ' + tx[0].blockindex.toString());
|
||||
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last: tx[0].blockindex
|
||||
}, function() {
|
||||
@@ -457,11 +470,13 @@ if (database == 'peers') {
|
||||
if (!err) {
|
||||
console.log('%s[%s]: market data updated successfully.', key, pair_key);
|
||||
complete++;
|
||||
|
||||
if (complete == total_pairs)
|
||||
get_last_usd_price();
|
||||
} else {
|
||||
console.log('%s[%s] error: %s', key, pair_key, err);
|
||||
complete++;
|
||||
|
||||
if (complete == total_pairs)
|
||||
get_last_usd_price();
|
||||
}
|
||||
@@ -480,6 +495,7 @@ if (database == 'peers') {
|
||||
// market not installed
|
||||
console.log('%s market not installed', key);
|
||||
complete++;
|
||||
|
||||
if (complete == total_pairs)
|
||||
get_last_usd_price();
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ describe('explorer', function() {
|
||||
|
||||
describe('prepare_vout', function() {
|
||||
var originalTimeout;
|
||||
|
||||
beforeEach(function() {
|
||||
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
||||
|
||||
Reference in New Issue
Block a user