Skip to content

Commit 1a65435

Browse files
committed
Merge pull request #1123 from matiu/bug/backup1
Bug/backup1
2 parents 563da59 + c7d0441 commit 1a65435

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

js/models/core/Wallet.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,12 +1611,12 @@ Wallet.prototype.updateIndexes = function(callback) {
16111611
Wallet.prototype.updateIndex = function(index, callback) {
16121612
var self = this;
16131613
var SCANN_WINDOW = 20;
1614-
self.indexDiscovery(index.changeIndex, true, index.cosigner, SCANN_WINDOW, function(err, changeIndex) {
1614+
self.indexDiscovery(index.changeIndex, true, index.copayerIndex, SCANN_WINDOW, function(err, changeIndex) {
16151615
if (err) return callback(err);
16161616
if (changeIndex != -1)
16171617
index.changeIndex = changeIndex + 1;
16181618

1619-
self.indexDiscovery(index.receiveIndex, false, index.cosigner, SCANN_WINDOW, function(err, receiveIndex) {
1619+
self.indexDiscovery(index.receiveIndex, false, index.copayerIndex, SCANN_WINDOW, function(err, receiveIndex) {
16201620
if (err) return callback(err);
16211621
if (receiveIndex != -1)
16221622
index.receiveIndex = receiveIndex + 1;
@@ -1625,18 +1625,23 @@ Wallet.prototype.updateIndex = function(index, callback) {
16251625
});
16261626
}
16271627

1628-
Wallet.prototype.deriveAddresses = function(index, amout, isChange, cosigner) {
1629-
var ret = new Array(amout);
1630-
for (var i = 0; i < amout; i++) {
1631-
ret[i] = this.publicKeyRing.getAddress(index + i, isChange, cosigner).toString();
1628+
Wallet.prototype.deriveAddresses = function(index, amount, isChange, copayerIndex) {
1629+
preconditions.checkArgument(amount);
1630+
preconditions.shouldBeDefined(copayerIndex);
1631+
1632+
var ret = new Array(amount);
1633+
for (var i = 0; i < amount; i++) {
1634+
ret[i] = this.publicKeyRing.getAddress(index + i, isChange, copayerIndex).toString();
16321635
}
16331636
return ret;
16341637
}
16351638

16361639
// This function scans the publicKeyRing branch starting at index @start and reports the index with last activity,
16371640
// using a scan window of @gap. The argument @change defines the branch to scan: internal or external.
16381641
// Returns -1 if no activity is found in range.
1639-
Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) {
1642+
Wallet.prototype.indexDiscovery = function(start, change, copayerIndex, gap, cb) {
1643+
preconditions.shouldBeDefined(copayerIndex);
1644+
preconditions.checkArgument(gap);
16401645
var scanIndex = start;
16411646
var lastActive = -1;
16421647
var hasActivity = false;
@@ -1646,7 +1651,7 @@ Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) {
16461651
function _do(next) {
16471652
// Optimize window to minimize the derivations.
16481653
var scanWindow = (lastActive == -1) ? gap : gap - (scanIndex - lastActive) + 1;
1649-
var addresses = self.deriveAddresses(scanIndex, scanWindow, change, cosigner);
1654+
var addresses = self.deriveAddresses(scanIndex, scanWindow, change, copayerIndex);
16501655
self.blockchain.checkActivity(addresses, function(err, actives) {
16511656
if (err) throw err;
16521657

test/test.Wallet.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@ describe('Wallet model', function() {
814814
});
815815

816816
sinon.assert.callCount(updateIndex, 4);
817+
sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[0] );
818+
sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[1] );
819+
sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[2] );
817820
w.updateIndex.restore();
818821
done();
819822
});
@@ -837,6 +840,8 @@ describe('Wallet model', function() {
837840
index.receiveIndex.should.equal(9);
838841
index.changeIndex.should.equal(9);
839842
indexDiscovery.callCount.should.equal(2);
843+
sinon.assert.calledWith(indexDiscovery, 1, true, 2, 20 );
844+
sinon.assert.calledWith(indexDiscovery, 2, false, 2, 20 );
840845
w.indexDiscovery.restore();
841846
done();
842847
});

0 commit comments

Comments
 (0)