diff --git a/lib/api.js b/lib/api.js index 133f5e2..8771db7 100644 --- a/lib/api.js +++ b/lib/api.js @@ -24,6 +24,17 @@ if (cluster.isMaster) { app.use(bodyParser.urlencoded({extended: false})); app.use(bodyParser.json()); +let pool_list = []; +if(global.config.pps.enable === true){ + pool_list.push('pps'); +} +if(global.config.solo.enable === true){ + pool_list.push('solo'); +} +if(global.config.pplns.enable === true){ + pool_list.push('pplns'); +} + // ROUTES FOR OUR API // ============================================================================= @@ -62,16 +73,6 @@ app.get('/pool/stats', function (req, res) { let localCache = global.database.getCache('pool_stats_global'); delete(localCache.minerHistory); delete(localCache.hashHistory); - let pool_list = []; - if(global.config.pps.enable === true){ - pool_list.push('pps'); - } - if(global.config.solo.enable === true){ - pool_list.push('solo'); - } - if(global.config.pplns.enable === true){ - pool_list.push('pplns'); - } res.json({pool_list: pool_list, pool_statistics: localCache}); }); @@ -150,11 +151,15 @@ app.get('/pool/ports', function (req, res) { }); app.get('/pool/blocks/:pool_type', function (req, res) { - res.json(global.database.getBlockList(req.params.pool_type)); + let limit = typeof(req.query.limit) !== 'undefined' ? Number(req.query.limit) : 25; + let page = typeof(req.query.page) !== 'undefined' ? Number(req.query.page) : 0; + res.json(global.database.getBlockList(req.params.pool_type).slice(page, page + limit + 1)); }); app.get('/pool/blocks', function (req, res) { - res.json(global.database.getBlockList()); + let limit = typeof(req.query.limit) !== 'undefined' ? Number(req.query.limit) : 25; + let page = typeof(req.query.page) !== 'undefined' ? Number(req.query.page) : 0; + res.json(global.database.getBlockList().slice(page, page + limit + 1)); }); app.get('/pool/payments/:pool_type', function (req, res) { @@ -205,8 +210,10 @@ app.get('/pool/payments/:pool_type', function (req, res) { }); app.get('/pool/payments', function (req, res) { - let query = "SELECT * FROM transactions ORDER BY id DESC"; - global.mysql.query(query).then(function (rows) { + let limit = typeof(req.query.limit) !== 'undefined' ? Number(req.query.limit) : 10; + let page = typeof(req.query.page) !== 'undefined' ? Number(req.query.page) : 0; + let query = "SELECT * FROM transactions ORDER BY id DESC LIMIT ? page ?"; + global.mysql.query(query, [limit, page]).then(function (rows) { if (rows.length === 0) { return res.json([]); } @@ -247,19 +254,21 @@ app.get('/miner/:address/identifiers', function (req, res) { }); app.get('/miner/:address/payments', function (req, res) { + let limit = typeof(req.query.limit) !== 'undefined' ? Number(req.query.limit) : 25; + let page = typeof(req.query.page) !== 'undefined' ? Number(req.query.page) : 0; let address_parts = req.params.address.split('.'); let address = address_parts[0]; let payment_id = address_parts[1]; let query = "SELECT amount, pool_type, transaction_id, UNIX_TIMESTAMP(paid_time) as ts FROM " + - "payments WHERE payment_address = ? AND paid_time < ? AND payment_id = ? ORDER BY paid_time DESC LIMIT 25"; + "payments WHERE payment_address = ? AND paid_time < ? AND payment_id = ? ORDER BY paid_time DESC LIMIT ? OFFSET ?"; if (typeof(payment_id) === 'undefined') { query = "SELECT amount as amt, pool_type, transaction_id, UNIX_TIMESTAMP(paid_time) as ts FROM " + - "payments WHERE payment_address = ? AND paid_time < ? AND payment_id IS ? ORDER BY paid_time DESC LIMIT 25"; + "payments WHERE payment_address = ? AND paid_time < ? AND payment_id IS ? ORDER BY paid_time DESC LIMIT ? OFFSET ?"; } let start = req.query.start || Date.now() / 1000; start *= 1000; let response = []; - global.mysql.query(query, [address, global.support.formatDate(start), payment_id]).then(function (rows) { + global.mysql.query(query, [address, global.support.formatDate(start), payment_id, limit, page]).then(function (rows) { if (rows.length === 0) { return res.json(response); } diff --git a/lib/pool.js b/lib/pool.js index 097e7e2..524ee48 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -22,6 +22,7 @@ let httpResponse = ' 200 OK\nContent-Type: text/plain\nContent-Length: 18\n\nMin let threadName; let minerCount = []; let BlockTemplate = global.coinFuncs.BlockTemplate; +let hexMatch = new RegExp("^[0-9a-f]$"); Buffer.prototype.toByteArray = function () { return Array.prototype.slice.call(this, 0); @@ -232,9 +233,14 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer this.error = "Too many options in the login field"; this.valid_miner = false; } - if (typeof(addressSplit[1]) !== 'undefined' && (addressSplit[1].length === 16 || addressSplit[1].length === 64)) { + if (typeof(addressSplit[1]) !== 'undefined' && addressSplit[1].length === 64 && addressSplit[1].test(hexMatch)) { this.paymentID = addressSplit[1]; this.payout = this.address + "." + this.paymentID; + } else if (addressSplit[1] !== 'undefined') { + this.identifier = this.identifier === 'x' ? addressSplit[1] : pass_split[0]; + } + if (typeof(addressSplit[2]) !== 'undefined') { + this.identifier = this.identifier === 'x' ? addressSplit[2] : pass_split[0]; } if (pass_split.length === 2) {