wallet: more refactoring.

This commit is contained in:
Christopher Jeffrey 2016-08-17 05:42:59 -07:00
parent 90349b8244
commit 8765bf5a6d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 11 additions and 9 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);