Hold on backup page until all copayers made a full backup
This commit is contained in:
parent
f9fad5d62f
commit
49ac6dfcf4
4 changed files with 48 additions and 11 deletions
|
|
@ -30,6 +30,7 @@ function PublicKeyRing(opts) {
|
|||
this.publicKeysCache = opts.publicKeysCache || {};
|
||||
this.nicknameFor = opts.nicknameFor || {};
|
||||
this.copayerIds = [];
|
||||
this.copayersBackup = opts.copayersBackup || [];
|
||||
this.addressToPath = {};
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +60,7 @@ PublicKeyRing.prototype.toObj = function() {
|
|||
requiredCopayers: this.requiredCopayers,
|
||||
totalCopayers: this.totalCopayers,
|
||||
indexes: AddressIndex.serialize(this.indexes),
|
||||
copayersBackup: this.copayersBackup,
|
||||
|
||||
copayersExtPubKeys: this.copayersHK.map(function(b) {
|
||||
return b.extendedPublicKeyString();
|
||||
|
|
@ -350,12 +352,30 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
|||
return hasChanged;
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.setBackupReady = function(copayerId) {
|
||||
if (this.isBackupReady()) return false;
|
||||
|
||||
var cid = this.myCopayerId();
|
||||
this.copayersBackup.push(cid);
|
||||
return true;
|
||||
}
|
||||
|
||||
PublicKeyRing.prototype.isBackupReady = function(copayerId) {
|
||||
var cid = this.myCopayerId();
|
||||
return this.copayersBackup.indexOf(cid) != -1;
|
||||
}
|
||||
|
||||
PublicKeyRing.prototype.isFullyBackup = function(copayerId) {
|
||||
return this.copayersBackup.length == this.totalCopayers;
|
||||
}
|
||||
|
||||
PublicKeyRing.prototype.merge = function(inPKR, ignoreId) {
|
||||
this._checkInPKR(inPKR, ignoreId);
|
||||
|
||||
var hasChanged = false;
|
||||
hasChanged |= this.mergeIndexes(inPKR.indexes);
|
||||
hasChanged |= this._mergePubkeys(inPKR);
|
||||
hasChanged |= this.mergeBackups(inPKR.copayersBackup);
|
||||
|
||||
return !!hasChanged;
|
||||
};
|
||||
|
|
@ -372,4 +392,18 @@ PublicKeyRing.prototype.mergeIndexes = function(indexes) {
|
|||
return !!hasChanged
|
||||
}
|
||||
|
||||
PublicKeyRing.prototype.mergeBackups = function(backups) {
|
||||
var self = this;
|
||||
var hasChanged = false;
|
||||
|
||||
backups.forEach(function(cid) {
|
||||
var isNew = self.copayersBackup.indexOf(cid) == -1;
|
||||
if (isNew) self.copayersBackup.push(cid);
|
||||
hasChanged |= isNew;
|
||||
});
|
||||
|
||||
return !!hasChanged
|
||||
}
|
||||
|
||||
|
||||
module.exports = require('soop')(PublicKeyRing);
|
||||
|
|
|
|||
|
|
@ -879,13 +879,13 @@ Wallet.prototype.toggleAddressBookEntry = function(key) {
|
|||
};
|
||||
|
||||
Wallet.prototype.isReady = function() {
|
||||
var ret = this.publicKeyRing.isComplete() && this.backupOffered;
|
||||
var ret = this.publicKeyRing.isComplete() && this.publicKeyRing.isFullyBackup();
|
||||
return ret;
|
||||
};
|
||||
|
||||
Wallet.prototype.offerBackup = function() {
|
||||
this.backupOffered = true;
|
||||
this.store();
|
||||
Wallet.prototype.setBackupReady = function() {
|
||||
this.publicKeyRing.setBackupReady();
|
||||
this.emit('publicKeyRingUpdated', false);
|
||||
};
|
||||
|
||||
Wallet.prototype.signJson = function(payload) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue