wallet: rename some methods. cleanup.
This commit is contained in:
parent
49f56f786f
commit
7f936ade4d
@ -1948,6 +1948,9 @@ TXDB.prototype.abandon = function abandon(hash, callback, force) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function Details(info) {
|
function Details(info) {
|
||||||
|
if (!(this instanceof Details))
|
||||||
|
return new Details(info);
|
||||||
|
|
||||||
this.db = info.db;
|
this.db = info.db;
|
||||||
this.network = info.db.network;
|
this.network = info.db.network;
|
||||||
this.wid = info.wid;
|
this.wid = info.wid;
|
||||||
@ -1963,6 +1966,7 @@ function Details(info) {
|
|||||||
this.tx = info.tx;
|
this.tx = info.tx;
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
this.outputs = [];
|
this.outputs = [];
|
||||||
|
|
||||||
this.init(info.table);
|
this.init(info.table);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2033,6 +2037,9 @@ Details.prototype.toJSON = function toJSON() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function DetailsMember() {
|
function DetailsMember() {
|
||||||
|
if (!(this instanceof DetailsMember))
|
||||||
|
return new DetailsMember();
|
||||||
|
|
||||||
this.value = 0;
|
this.value = 0;
|
||||||
this.address = null;
|
this.address = null;
|
||||||
this.path = null;
|
this.path = null;
|
||||||
@ -2055,6 +2062,9 @@ DetailsMember.prototype.toJSON = function toJSON(network) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function Balance(wallet) {
|
function Balance(wallet) {
|
||||||
|
if (!(this instanceof Balance))
|
||||||
|
return new Balance(wallet);
|
||||||
|
|
||||||
this.wid = wallet.wid;
|
this.wid = wallet.wid;
|
||||||
this.id = wallet.id;
|
this.id = wallet.id;
|
||||||
this.unconfirmed = 0;
|
this.unconfirmed = 0;
|
||||||
|
|||||||
@ -119,7 +119,7 @@ Wallet.prototype.fromOptions = function fromOptions(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!id)
|
if (!id)
|
||||||
id = this.getLabel();
|
id = this.getID();
|
||||||
|
|
||||||
if (options.token) {
|
if (options.token) {
|
||||||
assert(Buffer.isBuffer(options.token));
|
assert(Buffer.isBuffer(options.token));
|
||||||
@ -428,7 +428,7 @@ Wallet.prototype.unlock = function unlock(passphrase, timeout, callback) {
|
|||||||
* @returns {Base58String}
|
* @returns {Base58String}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getLabel = function getLabel() {
|
Wallet.prototype.getID = function getID() {
|
||||||
var key, p, hash;
|
var key, p, hash;
|
||||||
|
|
||||||
assert(this.master.key, 'Cannot derive id.');
|
assert(this.master.key, 'Cannot derive id.');
|
||||||
@ -2379,7 +2379,7 @@ Account.prototype._checkKeys = function _checkKeys(callback) {
|
|||||||
|
|
||||||
address = this.deriveReceive(0).getScriptAddress();
|
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)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
@ -2570,7 +2570,7 @@ Account.prototype.setDepth = function setDepth(receiveDepth, changeDepth, callba
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (addresses.length === 0)
|
if (addresses.length === 0)
|
||||||
return callback(null, false);
|
return callback();
|
||||||
|
|
||||||
this.saveAddress(addresses, function(err) {
|
this.saveAddress(addresses, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -2596,11 +2596,8 @@ Account.prototype.inspect = function inspect() {
|
|||||||
type: keyTypesByVal[this.type].toLowerCase(),
|
type: keyTypesByVal[this.type].toLowerCase(),
|
||||||
m: this.m,
|
m: this.m,
|
||||||
n: this.n,
|
n: this.n,
|
||||||
keyAddress: this.initialized
|
address: this.initialized
|
||||||
? this.receiveAddress.getKeyAddress()
|
? this.receiveAddress.getAddress()
|
||||||
: null,
|
|
||||||
scriptAddress: this.initialized
|
|
||||||
? this.receiveAddress.getScriptAddress()
|
|
||||||
: null,
|
: null,
|
||||||
programAddress: this.initialized
|
programAddress: this.initialized
|
||||||
? this.receiveAddress.getProgramAddress()
|
? this.receiveAddress.getProgramAddress()
|
||||||
|
|||||||
@ -846,7 +846,7 @@ WalletDB.prototype.saveAddress = function saveAddress(wid, addresses, callback)
|
|||||||
|
|
||||||
self.emit('save address', address, path);
|
self.emit('save address', address, path);
|
||||||
|
|
||||||
self._getPaths(hash, function(err, paths) {
|
self.getPaths(hash, function(err, paths) {
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
@ -873,7 +873,7 @@ WalletDB.prototype.saveAddress = function saveAddress(wid, addresses, callback)
|
|||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WalletDB.prototype._getPaths = function _getPaths(hash, callback) {
|
WalletDB.prototype.getPaths = function getPaths(hash, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var paths;
|
var paths;
|
||||||
|
|
||||||
@ -907,7 +907,7 @@ WalletDB.prototype._getPaths = function _getPaths(hash, callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
WalletDB.prototype.hasAddress = function hasAddress(wid, address, callback) {
|
WalletDB.prototype.hasAddress = function hasAddress(wid, address, callback) {
|
||||||
this.getAddress(address, function(err, paths) {
|
this.getPaths(address, function(err, paths) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(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.
|
* Get all address hashes.
|
||||||
* @param {WalletID} wid
|
* @param {WalletID} wid
|
||||||
@ -1081,7 +1071,7 @@ WalletDB.prototype.getTable = function getTable(addresses, callback) {
|
|||||||
var i, keys, values;
|
var i, keys, values;
|
||||||
|
|
||||||
utils.forEachSerial(addresses, function(address, next) {
|
utils.forEachSerial(addresses, function(address, next) {
|
||||||
self.getAddress(address, function(err, paths) {
|
self.getPaths(address, function(err, paths) {
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
@ -1421,7 +1411,7 @@ WalletDB.prototype.addTX = function addTX(tx, callback, force) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
WalletDB.prototype.getPath = function getPath(wid, address, callback) {
|
WalletDB.prototype.getPath = function getPath(wid, address, callback) {
|
||||||
this.getAddress(address, function(err, paths) {
|
this.getPaths(address, function(err, paths) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
@ -1645,8 +1635,9 @@ function PathInfo(db, wid, tx, table) {
|
|||||||
|
|
||||||
PathInfo.map = function map(db, tx, table) {
|
PathInfo.map = function map(db, tx, table) {
|
||||||
var hashes = Object.keys(table);
|
var hashes = Object.keys(table);
|
||||||
var wallets = {};
|
var wallets = [];
|
||||||
var info = [];
|
var info = [];
|
||||||
|
var uniq = {};
|
||||||
var i, j, hash, paths, path, wid;
|
var i, j, hash, paths, path, wid;
|
||||||
|
|
||||||
for (i = 0; i < hashes.length; i++) {
|
for (i = 0; i < hashes.length; i++) {
|
||||||
@ -1654,17 +1645,18 @@ PathInfo.map = function map(db, tx, table) {
|
|||||||
paths = table[hash];
|
paths = table[hash];
|
||||||
for (j = 0; j < paths.length; j++) {
|
for (j = 0; j < paths.length; j++) {
|
||||||
path = paths[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)
|
if (wallets.length === 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < wallets.length; i++) {
|
for (i = 0; i < wallets.length; i++) {
|
||||||
wid = +wallets[i];
|
wid = wallets[i];
|
||||||
info.push(new PathInfo(db, wid, tx, table));
|
info.push(new PathInfo(db, wid, tx, table));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user