more refactoring.
This commit is contained in:
parent
cde8fdafa6
commit
aa163bce33
@ -800,22 +800,23 @@ Wallet.prototype.syncOutputDepth = function syncOutputDepth(tx, callback) {
|
|||||||
|
|
||||||
utils.forEachSerial(Object.keys(accounts), function(index, next) {
|
utils.forEachSerial(Object.keys(accounts), function(index, next) {
|
||||||
var paths = accounts[index];
|
var paths = accounts[index];
|
||||||
var depth = { changeDepth: -1, receiveDepth: -1 };
|
var receiveDepth = -1;
|
||||||
|
var changeDepth = -1;
|
||||||
|
|
||||||
for (i = 0; i < paths.length; i++) {
|
for (i = 0; i < paths.length; i++) {
|
||||||
path = paths[i];
|
path = paths[i];
|
||||||
|
|
||||||
if (path.change) {
|
if (path.change) {
|
||||||
if (path.index > depth.changeDepth)
|
if (path.index > changeDepth)
|
||||||
depth.changeDepth = path.index;
|
changeDepth = path.index;
|
||||||
} else {
|
} else {
|
||||||
if (path.index > depth.receiveDepth)
|
if (path.index > receiveDepth)
|
||||||
depth.receiveDepth = path.index;
|
receiveDepth = path.index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
depth.changeDepth++;
|
receiveDepth += 2;
|
||||||
depth.receiveDepth++;
|
changeDepth += 2;
|
||||||
|
|
||||||
self.getAccount(+index, function(err, account) {
|
self.getAccount(+index, function(err, account) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -824,7 +825,7 @@ Wallet.prototype.syncOutputDepth = function syncOutputDepth(tx, callback) {
|
|||||||
if (!account)
|
if (!account)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
account.setDepth(depth.receiveDepth + 1, depth.changeDepth + 1, function(err, rec, chng) {
|
account.setDepth(receiveDepth, changeDepth, function(err, rec, chng) {
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
@ -1547,8 +1548,8 @@ function Account(options) {
|
|||||||
this.witness = options.witness || false;
|
this.witness = options.witness || false;
|
||||||
this.accountKey = options.accountKey;
|
this.accountKey = options.accountKey;
|
||||||
this.accountIndex = options.accountIndex;
|
this.accountIndex = options.accountIndex;
|
||||||
this.receiveDepth = options.receiveDepth || 1;
|
this.receiveDepth = options.receiveDepth || 0;
|
||||||
this.changeDepth = options.changeDepth || 1;
|
this.changeDepth = options.changeDepth || 0;
|
||||||
this.type = options.type || 'pubkeyhash';
|
this.type = options.type || 'pubkeyhash';
|
||||||
this.keys = [];
|
this.keys = [];
|
||||||
this.m = options.m || 1;
|
this.m = options.m || 1;
|
||||||
@ -1670,29 +1671,10 @@ Account.prototype.init = function init(callback) {
|
|||||||
|
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
|
|
||||||
for (i = 0; i < this.receiveDepth - 1; i++)
|
assert(this.receiveDepth === 0);
|
||||||
addresses.push(this.deriveReceive(i));
|
assert(this.changeDepth === 0);
|
||||||
|
|
||||||
for (i = 0; i < this.changeDepth - 1; i++)
|
this.setDepth(1, 1, callback);
|
||||||
addresses.push(this.deriveChange(i));
|
|
||||||
|
|
||||||
for (i = this.receiveDepth; i < this.receiveDepth + this.lookahead; i++)
|
|
||||||
addresses.push(this.deriveReceive(i));
|
|
||||||
|
|
||||||
for (i = this.changeDepth; i < this.changeDepth + this.lookahead; i++)
|
|
||||||
addresses.push(this.deriveChange(i));
|
|
||||||
|
|
||||||
this.receiveAddress = this.deriveReceive(this.receiveDepth - 1);
|
|
||||||
this.changeAddress = this.deriveChange(this.changeDepth - 1);
|
|
||||||
|
|
||||||
addresses.push(this.receiveAddress);
|
|
||||||
addresses.push(this.changeAddress);
|
|
||||||
|
|
||||||
return this.saveAddress(addresses, function(err) {
|
|
||||||
if (err)
|
|
||||||
return callback(err);
|
|
||||||
return self.save(callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1882,7 +1864,7 @@ Account.prototype.createChange = function createChange(callback) {
|
|||||||
/**
|
/**
|
||||||
* Create a new address (increments depth).
|
* Create a new address (increments depth).
|
||||||
* @param {Boolean} change
|
* @param {Boolean} change
|
||||||
* @returns {KeyRing}
|
* @param {Function} callback - Returns [Error, {@link KeyRing}].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Account.prototype.createAddress = function createAddress(change, callback) {
|
Account.prototype.createAddress = function createAddress(change, callback) {
|
||||||
@ -2028,7 +2010,7 @@ Account.prototype.setDepth = function setDepth(receiveDepth, changeDepth, callba
|
|||||||
if (changeDepth > this.changeDepth) {
|
if (changeDepth > this.changeDepth) {
|
||||||
for (i = this.changeDepth; i < changeDepth; i++) {
|
for (i = this.changeDepth; i < changeDepth; i++) {
|
||||||
change = this.deriveChange(i);
|
change = this.deriveChange(i);
|
||||||
addresses.push(this.changeAddress);
|
addresses.push(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = changeDepth; i < changeDepth + this.lookahead; i++)
|
for (i = changeDepth; i < changeDepth + this.lookahead; i++)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user