mirror of https://github.com/BTCPrivate/z-nomp.git
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
var redis = require('redis');
|
|
var Stratum = require('stratum-pool');
|
|
|
|
|
|
/*
|
|
This module deals with handling shares when in internal payment processing mode. It connects to a redis
|
|
database and inserts shares with the database structure of:
|
|
|
|
key: coin_name + ':' + block_height
|
|
value: a hash with..
|
|
key:
|
|
|
|
*/
|
|
|
|
|
|
module.exports = function(logger, poolConfig){
|
|
|
|
var internalConfig = poolConfig.shareProcessing.internal;
|
|
var redisConfig = internalConfig.redis;
|
|
var coin = poolConfig.coin.name;
|
|
|
|
|
|
|
|
|
|
var connection;
|
|
|
|
function connect(){
|
|
|
|
var reconnectTimeout;
|
|
|
|
connection = redis.createClient(redisConfig.port, redisConfig.host);
|
|
connection.on('ready', function(){
|
|
clearTimeout(reconnectTimeout);
|
|
logger.debug('redis', 'Successfully connected to redis database');
|
|
});
|
|
connection.on('error', function(err){
|
|
logger.error('redis', 'Redis client had an error: ' + JSON.stringify(err))
|
|
});
|
|
connection.on('end', function(){
|
|
logger.error('redis', 'Connection to redis database as been ended');
|
|
logger.warning('redis', 'Trying reconnection in 3 seconds...');
|
|
reconnectTimeout = setTimeout(function(){
|
|
connect();
|
|
}, 3000);
|
|
});
|
|
}
|
|
connect();
|
|
|
|
|
|
this.handleShare = function(isValidShare, isValidBlock, shareData){
|
|
|
|
|
|
if (!isValidShare) return;
|
|
|
|
connection.hincrby([coin + ':' + shareData.height, shareData.worker, shareData.difficulty], function(error, result){
|
|
if (error)
|
|
logger.error('redis', 'Could not store worker share')
|
|
});
|
|
|
|
};
|
|
|
|
}; |