Changes to setting vardiff (for coin-switching). Added pubkey to address function

This commit is contained in:
Matt 2014-04-26 16:24:54 -06:00
parent 89e9f47e47
commit fe64fb8855
3 changed files with 17 additions and 3 deletions

View File

@ -221,7 +221,7 @@ var pool = module.exports = function pool(options, authorizeFn){
_this.varDiff = {}; _this.varDiff = {};
Object.keys(options.ports).forEach(function(port) { Object.keys(options.ports).forEach(function(port) {
if (options.ports[port].varDiff) if (options.ports[port].varDiff)
_this.setVarDiff(port, new varDiff(port, options.ports[port].varDiff)); _this.setVarDiff(port, options.ports[port].varDiff);
}); });
} }
@ -641,10 +641,11 @@ var pool = module.exports = function pool(options, authorizeFn){
}; };
this.setVarDiff = function(port, varDiffInstance) { this.setVarDiff = function(port, varDiffConfig) {
if (typeof(_this.varDiff[port]) != 'undefined' ) { if (typeof(_this.varDiff[port]) != 'undefined' ) {
_this.varDiff[port].removeAllListeners(); _this.varDiff[port].removeAllListeners();
} }
var varDiffInstance = new varDiff(port, varDiffConfig);
_this.varDiff[port] = varDiffInstance; _this.varDiff[port] = varDiffInstance;
_this.varDiff[port].on('newDifficulty', function(client, newDiff) { _this.varDiff[port].on('newDifficulty', function(client, newDiff) {

View File

@ -119,7 +119,7 @@ var StratumClient = function(options){
function handleAuthorize(message, replyToSocket){ function handleAuthorize(message, replyToSocket){
_this.workerName = message.params[0]; _this.workerName = message.params[0];
_this.workerPass = message.params[1]; _this.workerPass = message.params[1];
options.authorizeFn(_this.remoteAddress, _this.workerName, _this.workerPass, function(result) { options.authorizeFn(_this.remoteAddress, options.socket.localPort, _this.workerName, _this.workerPass, function(result) {
_this.authorized = (!result.error && result.authorized); _this.authorized = (!result.error && result.authorized);
if (replyToSocket) { if (replyToSocket) {

View File

@ -4,6 +4,19 @@ var base58 = require('base58-native');
var bignum = require('bignum'); var bignum = require('bignum');
exports.addressFromEx = function(exAddress, ripdm160Key){
try {
var versionByte = base58.decode(exAddress).slice(0, 1);
var addrBase = Buffer.concat([versionByte, new Buffer(ripdm160Key, 'hex')]);
var checksum = exports.sha256d(addrBase).slice(0, 4);
var address = Buffer.concat([addrBase, checksum]);
return base58.encode(address);
}
catch(e){
return null;
}
};
exports.sha256 = function(buffer){ exports.sha256 = function(buffer){
var hash1 = crypto.createHash('sha256'); var hash1 = crypto.createHash('sha256');