From 8b43975963e2326ab2e168ee1309e7b5c6e93cd0 Mon Sep 17 00:00:00 2001 From: Ahmed Bodiwala Date: Sun, 24 Jun 2018 00:35:20 +0000 Subject: [PATCH] Add MPOS SSO DB Compatibility --- libs/mposCompatibility.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libs/mposCompatibility.js b/libs/mposCompatibility.js index 6f044c49d..6d4d8c963 100644 --- a/libs/mposCompatibility.js +++ b/libs/mposCompatibility.js @@ -5,7 +5,7 @@ module.exports = function(logger, poolConfig){ var mposConfig = poolConfig.mposMode; var coin = poolConfig.coin.name; - var connection = mysql.createPool({ + var mainDBConnection = mysql.createPool({ host: mposConfig.host, port: mposConfig.port, user: mposConfig.user, @@ -13,6 +13,14 @@ module.exports = function(logger, poolConfig){ database: mposConfig.database }); + var sharedDBConnection = mysql.createPool({ + host: mposConfig.host, + port: mposConfig.port, + user: mposConfig.user, + password: mposConfig.password, + database: mposConfig.shared_database + }); + var logIdentify = 'MySQL'; var logComponent = coin; @@ -26,7 +34,7 @@ module.exports = function(logger, poolConfig){ return; } - connection.query( + sharedDBConnection.query( 'SELECT password FROM pool_worker WHERE username = LOWER(?)', [workerName.toLowerCase()], function(err, result){ @@ -38,7 +46,7 @@ module.exports = function(logger, poolConfig){ else if (!result[0]){ if(mposConfig.autoCreateWorker){ var account = workerName.split('.')[0]; - connection.query( + sharedDBConnection.query( 'SELECT id,username FROM accounts WHERE username = LOWER(?)', [account.toLowerCase()], function(err, result){ @@ -49,7 +57,7 @@ module.exports = function(logger, poolConfig){ }else if(!result[0]){ authCallback(false); }else{ - connection.query( + sharedDBConnection.query( "INSERT INTO `pool_worker` (`account_id`, `username`, `password`) VALUES (?, ?, ?);", [result[0].id,workerName.toLowerCase(),password], function(err, result){ @@ -89,7 +97,7 @@ module.exports = function(logger, poolConfig){ typeof(shareData.error) === 'undefined' ? null : shareData.error, shareData.blockHash ? shareData.blockHash : (shareData.blockHashInvalid ? shareData.blockHashInvalid : '') ]; - connection.query( + mainDBConnection.query( 'INSERT INTO `shares` SET time = NOW(), rem_host = ?, username = ?, our_result = ?, upstream_result = ?, difficulty = ?, reason = ?, solution = ?', dbData, function(err, result) { @@ -103,14 +111,14 @@ module.exports = function(logger, poolConfig){ this.handleDifficultyUpdate = function(workerName, diff){ - connection.query( - 'UPDATE `pool_worker` SET `difficulty` = ' + diff + ' WHERE `username` = ' + connection.escape(workerName), + sharedDBConnection.query( + 'UPDATE `pool_worker` SET `difficulty` = ' + diff + ' WHERE `username` = ' + sharedDBConnection.escape(workerName), function(err, result){ if (err) logger.error(logIdentify, logComponent, 'Error when updating worker diff: ' + JSON.stringify(err)); else if (result.affectedRows === 0){ - connection.query('INSERT INTO `pool_worker` SET ?', {username: workerName, difficulty: diff}); + sharedDBConnection.query('INSERT INTO `pool_worker` SET ?', {username: workerName, difficulty: diff}); } else console.log('Updated difficulty successfully', result);