mirror of https://github.com/BTCPrivate/copay.git
fix backup restore + tests
This commit is contained in:
parent
411ebbe2d7
commit
c7d04418b0
|
@ -1611,12 +1611,12 @@ Wallet.prototype.updateIndexes = function(callback) {
|
||||||
Wallet.prototype.updateIndex = function(index, callback) {
|
Wallet.prototype.updateIndex = function(index, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var SCANN_WINDOW = 20;
|
var SCANN_WINDOW = 20;
|
||||||
self.indexDiscovery(index.changeIndex, true, index.cosigner, SCANN_WINDOW, function(err, changeIndex) {
|
self.indexDiscovery(index.changeIndex, true, index.copayerIndex, SCANN_WINDOW, function(err, changeIndex) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
if (changeIndex != -1)
|
if (changeIndex != -1)
|
||||||
index.changeIndex = changeIndex + 1;
|
index.changeIndex = changeIndex + 1;
|
||||||
|
|
||||||
self.indexDiscovery(index.receiveIndex, false, index.cosigner, SCANN_WINDOW, function(err, receiveIndex) {
|
self.indexDiscovery(index.receiveIndex, false, index.copayerIndex, SCANN_WINDOW, function(err, receiveIndex) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
if (receiveIndex != -1)
|
if (receiveIndex != -1)
|
||||||
index.receiveIndex = receiveIndex + 1;
|
index.receiveIndex = receiveIndex + 1;
|
||||||
|
@ -1625,12 +1625,13 @@ Wallet.prototype.updateIndex = function(index, callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Wallet.prototype.deriveAddresses = function(index, amount, isChange, cosigner) {
|
Wallet.prototype.deriveAddresses = function(index, amount, isChange, copayerIndex) {
|
||||||
preconditions.checkArgument(cosigner);
|
preconditions.checkArgument(amount);
|
||||||
|
preconditions.shouldBeDefined(copayerIndex);
|
||||||
|
|
||||||
var ret = new Array(amount);
|
var ret = new Array(amount);
|
||||||
for (var i = 0; i < amount; i++) {
|
for (var i = 0; i < amount; i++) {
|
||||||
ret[i] = this.publicKeyRing.getAddress(index + i, isChange, cosigner).toString();
|
ret[i] = this.publicKeyRing.getAddress(index + i, isChange, copayerIndex).toString();
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1638,7 +1639,9 @@ Wallet.prototype.deriveAddresses = function(index, amount, isChange, cosigner) {
|
||||||
// This function scans the publicKeyRing branch starting at index @start and reports the index with last activity,
|
// This function scans the publicKeyRing branch starting at index @start and reports the index with last activity,
|
||||||
// using a scan window of @gap. The argument @change defines the branch to scan: internal or external.
|
// using a scan window of @gap. The argument @change defines the branch to scan: internal or external.
|
||||||
// Returns -1 if no activity is found in range.
|
// Returns -1 if no activity is found in range.
|
||||||
Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) {
|
Wallet.prototype.indexDiscovery = function(start, change, copayerIndex, gap, cb) {
|
||||||
|
preconditions.shouldBeDefined(copayerIndex);
|
||||||
|
preconditions.checkArgument(gap);
|
||||||
var scanIndex = start;
|
var scanIndex = start;
|
||||||
var lastActive = -1;
|
var lastActive = -1;
|
||||||
var hasActivity = false;
|
var hasActivity = false;
|
||||||
|
@ -1648,7 +1651,7 @@ Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) {
|
||||||
function _do(next) {
|
function _do(next) {
|
||||||
// Optimize window to minimize the derivations.
|
// Optimize window to minimize the derivations.
|
||||||
var scanWindow = (lastActive == -1) ? gap : gap - (scanIndex - lastActive) + 1;
|
var scanWindow = (lastActive == -1) ? gap : gap - (scanIndex - lastActive) + 1;
|
||||||
var addresses = self.deriveAddresses(scanIndex, scanWindow, change, cosigner);
|
var addresses = self.deriveAddresses(scanIndex, scanWindow, change, copayerIndex);
|
||||||
self.blockchain.checkActivity(addresses, function(err, actives) {
|
self.blockchain.checkActivity(addresses, function(err, actives) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
|
|
|
@ -814,6 +814,9 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
sinon.assert.callCount(updateIndex, 4);
|
sinon.assert.callCount(updateIndex, 4);
|
||||||
|
sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[0] );
|
||||||
|
sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[1] );
|
||||||
|
sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[2] );
|
||||||
w.updateIndex.restore();
|
w.updateIndex.restore();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -837,6 +840,8 @@ describe('Wallet model', function() {
|
||||||
index.receiveIndex.should.equal(9);
|
index.receiveIndex.should.equal(9);
|
||||||
index.changeIndex.should.equal(9);
|
index.changeIndex.should.equal(9);
|
||||||
indexDiscovery.callCount.should.equal(2);
|
indexDiscovery.callCount.should.equal(2);
|
||||||
|
sinon.assert.calledWith(indexDiscovery, 1, true, 2, 20 );
|
||||||
|
sinon.assert.calledWith(indexDiscovery, 2, false, 2, 20 );
|
||||||
w.indexDiscovery.restore();
|
w.indexDiscovery.restore();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue