From 8765bf5a6d58f810226f6d9ac39673b2ed6f4a0d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 17 Aug 2016 05:42:59 -0700 Subject: [PATCH] wallet: more refactoring. --- lib/bcoin/address.js | 6 ++++-- lib/bcoin/http/rpc.js | 4 ++-- lib/bcoin/wallet.js | 10 +++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/bcoin/address.js b/lib/bcoin/address.js index 816724cf..7807b10d 100644 --- a/lib/bcoin/address.js +++ b/lib/bcoin/address.js @@ -546,8 +546,10 @@ Address.validate = function validate(address, type) { Address.getHash = function getHash(data, enc) { var hash; - if (utils.isHex(data) && (data.length === 40 || data.length === 64)) - return enc === 'hex' ? data : new Buffer(data, 'hex'); + if (typeof data === 'string') { + if (data.length === 40 || data.length === 64) + return enc === 'hex' ? data : new Buffer(data, 'hex'); + } if (Buffer.isBuffer(data)) { hash = data; diff --git a/lib/bcoin/http/rpc.js b/lib/bcoin/http/rpc.js index 368cc0fd..e7a5a0a1 100644 --- a/lib/bcoin/http/rpc.js +++ b/lib/bcoin/http/rpc.js @@ -2322,7 +2322,7 @@ RPC.prototype.validateaddress = function validateaddress(args, callback) { }); } - this.wallet.getAddressPath(address.getHash('hex'), function(err, path) { + this.wallet.getPath(address.getHash('hex'), function(err, path) { if (err) return callback(err); @@ -2724,7 +2724,7 @@ RPC.prototype.getaccount = function getaccount(args, callback) { if (!hash) return callback(new RPCError('Invalid address.')); - this.wallet.getAddressPath(hash, function(err, path) { + this.wallet.getPath(hash, function(err, path) { if (err) return callback(err); diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 61be682c..afacb538 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -741,7 +741,7 @@ Wallet.prototype.hasAddress = function hasAddress(address, callback) { * @param {Function} callback - Returns [Error, {@link Path}]. */ -Wallet.prototype.getAddressPath = function getAddressPath(address, callback) { +Wallet.prototype.getPath = function getPath(address, callback) { var self = this; var hash = bcoin.address.getHash(address, 'hex'); @@ -1073,7 +1073,7 @@ Wallet.prototype.getKeyring = function getKeyring(address, callback) { if (!hash) return callback(); - this.getAddressPath(hash, function(err, path) { + this.getPath(hash, function(err, path) { if (err) return callback(err); @@ -1108,7 +1108,7 @@ Wallet.prototype.getInputPaths = function getInputPaths(tx, callback) { function done() { utils.forEachSerial(hashes, function(hash, next, i) { - self.getAddressPath(hash, function(err, path) { + self.getPath(hash, function(err, path) { if (err) return next(err); @@ -1166,7 +1166,7 @@ Wallet.prototype.getOutputPaths = function getOutputPaths(tx, callback) { } utils.forEachSerial(hashes, function(hash, next, i) { - self.getAddressPath(hash, function(err, path) { + self.getPath(hash, function(err, path) { if (err) return next(err); @@ -1331,7 +1331,7 @@ Wallet.prototype.getRedeem = function getRedeem(hash, callback) { if (typeof hash === 'string') hash = new Buffer(hash, 'hex'); - this.getAddressPath(hash.toString('hex'), function(err, path) { + this.getPath(hash.toString('hex'), function(err, path) { if (err) return callback(err);