wallet: rename some methods. cleanup.

This commit is contained in:
Christopher Jeffrey 2016-08-15 08:07:49 -07:00
parent 49f56f786f
commit 7f936ade4d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 28 additions and 29 deletions

View File

@ -1948,6 +1948,9 @@ TXDB.prototype.abandon = function abandon(hash, callback, force) {
*/
function Details(info) {
if (!(this instanceof Details))
return new Details(info);
this.db = info.db;
this.network = info.db.network;
this.wid = info.wid;
@ -1963,6 +1966,7 @@ function Details(info) {
this.tx = info.tx;
this.inputs = [];
this.outputs = [];
this.init(info.table);
}
@ -2033,6 +2037,9 @@ Details.prototype.toJSON = function toJSON() {
*/
function DetailsMember() {
if (!(this instanceof DetailsMember))
return new DetailsMember();
this.value = 0;
this.address = null;
this.path = null;
@ -2055,6 +2062,9 @@ DetailsMember.prototype.toJSON = function toJSON(network) {
*/
function Balance(wallet) {
if (!(this instanceof Balance))
return new Balance(wallet);
this.wid = wallet.wid;
this.id = wallet.id;
this.unconfirmed = 0;

View File

@ -119,7 +119,7 @@ Wallet.prototype.fromOptions = function fromOptions(options) {
}
if (!id)
id = this.getLabel();
id = this.getID();
if (options.token) {
assert(Buffer.isBuffer(options.token));
@ -428,7 +428,7 @@ Wallet.prototype.unlock = function unlock(passphrase, timeout, callback) {
* @returns {Base58String}
*/
Wallet.prototype.getLabel = function getLabel() {
Wallet.prototype.getID = function getID() {
var key, p, hash;
assert(this.master.key, 'Cannot derive id.');
@ -2379,7 +2379,7 @@ Account.prototype._checkKeys = function _checkKeys(callback) {
address = this.deriveReceive(0).getScriptAddress();
this.db._getPaths(address.getHash('hex'), function(err, paths) {
this.db.getPaths(address.getHash('hex'), function(err, paths) {
if (err)
return callback(err);
@ -2570,7 +2570,7 @@ Account.prototype.setDepth = function setDepth(receiveDepth, changeDepth, callba
}
if (addresses.length === 0)
return callback(null, false);
return callback();
this.saveAddress(addresses, function(err) {
if (err)
@ -2596,11 +2596,8 @@ Account.prototype.inspect = function inspect() {
type: keyTypesByVal[this.type].toLowerCase(),
m: this.m,
n: this.n,
keyAddress: this.initialized
? this.receiveAddress.getKeyAddress()
: null,
scriptAddress: this.initialized
? this.receiveAddress.getScriptAddress()
address: this.initialized
? this.receiveAddress.getAddress()
: null,
programAddress: this.initialized
? this.receiveAddress.getProgramAddress()

View File

@ -846,7 +846,7 @@ WalletDB.prototype.saveAddress = function saveAddress(wid, addresses, callback)
self.emit('save address', address, path);
self._getPaths(hash, function(err, paths) {
self.getPaths(hash, function(err, paths) {
if (err)
return next(err);
@ -873,7 +873,7 @@ WalletDB.prototype.saveAddress = function saveAddress(wid, addresses, callback)
* @param {Function} callback
*/
WalletDB.prototype._getPaths = function _getPaths(hash, callback) {
WalletDB.prototype.getPaths = function getPaths(hash, callback) {
var self = this;
var paths;
@ -907,7 +907,7 @@ WalletDB.prototype._getPaths = function _getPaths(hash, callback) {
*/
WalletDB.prototype.hasAddress = function hasAddress(wid, address, callback) {
this.getAddress(address, function(err, paths) {
this.getPaths(address, function(err, paths) {
if (err)
return callback(err);
@ -918,16 +918,6 @@ WalletDB.prototype.hasAddress = function hasAddress(wid, address, callback) {
});
};
/**
* Get path data for the specified address hash.
* @param {Hash} address
* @param {Function} callback
*/
WalletDB.prototype.getAddress = function getAddress(address, callback) {
this._getPaths(address, callback);
};
/**
* Get all address hashes.
* @param {WalletID} wid
@ -1081,7 +1071,7 @@ WalletDB.prototype.getTable = function getTable(addresses, callback) {
var i, keys, values;
utils.forEachSerial(addresses, function(address, next) {
self.getAddress(address, function(err, paths) {
self.getPaths(address, function(err, paths) {
if (err)
return next(err);
@ -1421,7 +1411,7 @@ WalletDB.prototype.addTX = function addTX(tx, callback, force) {
*/
WalletDB.prototype.getPath = function getPath(wid, address, callback) {
this.getAddress(address, function(err, paths) {
this.getPaths(address, function(err, paths) {
if (err)
return callback(err);
@ -1645,8 +1635,9 @@ function PathInfo(db, wid, tx, table) {
PathInfo.map = function map(db, tx, table) {
var hashes = Object.keys(table);
var wallets = {};
var wallets = [];
var info = [];
var uniq = {};
var i, j, hash, paths, path, wid;
for (i = 0; i < hashes.length; i++) {
@ -1654,17 +1645,18 @@ PathInfo.map = function map(db, tx, table) {
paths = table[hash];
for (j = 0; j < paths.length; j++) {
path = paths[j];
wallets[path.wid] = true;
if (!uniq[path.wid]) {
uniq[path.wid] = true;
wallets.push(path.wid);
}
}
}
wallets = Object.keys(wallets);
if (wallets.length === 0)
return;
for (i = 0; i < wallets.length; i++) {
wid = +wallets[i];
wid = wallets[i];
info.push(new PathInfo(db, wid, tx, table));
}