From fe64fb8855776d55cec4568e673303975078854d Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 26 Apr 2014 16:24:54 -0600 Subject: [PATCH] Changes to setting vardiff (for coin-switching). Added pubkey to address function --- lib/pool.js | 5 +++-- lib/stratum.js | 2 +- lib/util.js | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 229e464..8448537 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -221,7 +221,7 @@ var pool = module.exports = function pool(options, authorizeFn){ _this.varDiff = {}; Object.keys(options.ports).forEach(function(port) { 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' ) { _this.varDiff[port].removeAllListeners(); } + var varDiffInstance = new varDiff(port, varDiffConfig); _this.varDiff[port] = varDiffInstance; _this.varDiff[port].on('newDifficulty', function(client, newDiff) { diff --git a/lib/stratum.js b/lib/stratum.js index a5e8f88..7497a4f 100644 --- a/lib/stratum.js +++ b/lib/stratum.js @@ -119,7 +119,7 @@ var StratumClient = function(options){ function handleAuthorize(message, replyToSocket){ _this.workerName = message.params[0]; _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); if (replyToSocket) { diff --git a/lib/util.js b/lib/util.js index c834a99..2ccf4d9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -4,6 +4,19 @@ var base58 = require('base58-native'); 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){ var hash1 = crypto.createHash('sha256');