From df5fdb1f752bd3d8eb3737153bc36e684620d8ae Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 1 Sep 2015 11:53:07 -0300 Subject: [PATCH] parse client version --- lib/server.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index 3ffb5ba..6b3df1d 100644 --- a/lib/server.js +++ b/lib/server.js @@ -512,8 +512,38 @@ WalletService.prototype.addAccess = function(opts, cb) { }); }; +WalletService.prototype._parseClientVersion = function() { + function parse(version) { + var v = {}; + + if (!version) return null; + + var x = version.split('-'); + if (x.length != 2) { + v.agent = version; + return v; + } + v.agent = _.contains(['bwc', 'bws'], x[0]) ? 'bwc' : x[0]; + x = x[1].split('.'); + v.major = parseInt(x[0]); + v.minor = parseInt(x[1]); + v.patch = parseInt(x[2]); + + return v; + }; + + if (_.isUndefined(this.parsedClientVersion)) { + this.parsedClientVersion = parse(this.clientVersion); + } + return this.parsedClientVersion; +}; + WalletService.prototype._clientSupportsBIP44 = function() { - return !!this.clientVersion && !(/^bw.-0\.[01]\./.test(this.clientVersion)); + var version = this._parseClientVersion(); + if (!version) return false; + if (version.agent != 'bwc') return true; // Asume 3rd party clients are up-to-date + if (version.major == 0 && version.minor <= 1) return false; + return true; }; /**