remove pubkey cache from network and storage
This commit is contained in:
parent
73a2a9fba3
commit
20af614f40
4 changed files with 33 additions and 24 deletions
|
|
@ -21,7 +21,7 @@ function PublicKeyRing(opts) {
|
||||||
this.requiredCopayers = opts.requiredCopayers || 3;
|
this.requiredCopayers = opts.requiredCopayers || 3;
|
||||||
this.totalCopayers = opts.totalCopayers || 5;
|
this.totalCopayers = opts.totalCopayers || 5;
|
||||||
|
|
||||||
this.copayersHK = opts.copayersHK || [];
|
this.copayersHK = [];
|
||||||
|
|
||||||
this.indexes = opts.indexes ? HDParams.fromList(opts.indexes) : HDParams.init(this.totalCopayers);
|
this.indexes = opts.indexes ? HDParams.fromList(opts.indexes) : HDParams.init(this.totalCopayers);
|
||||||
|
|
||||||
|
|
@ -32,20 +32,31 @@ function PublicKeyRing(opts) {
|
||||||
this.addressToPath = {};
|
this.addressToPath = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PublicKeyRing.trim = function(data) {
|
||||||
|
var opts = {};
|
||||||
|
['walletId', 'networkName', 'requiredCopayers', 'totalCopayers','indexes','nicknameFor','copayersBackup', 'copayersExtPubKeys' ].forEach(function(k){
|
||||||
|
opts[k] = data[k];
|
||||||
|
});
|
||||||
|
|
||||||
|
return opts;
|
||||||
|
};
|
||||||
|
|
||||||
PublicKeyRing.fromObj = function(data) {
|
PublicKeyRing.fromObj = function(data) {
|
||||||
if (data instanceof PublicKeyRing) {
|
if (data instanceof PublicKeyRing) {
|
||||||
throw new Error('bad data format: Did you use .toObj()?');
|
throw new Error('bad data format: Did you use .toObj()?');
|
||||||
}
|
}
|
||||||
|
var opts = PublicKeyRing.trim(data);
|
||||||
|
|
||||||
// Support old indexes schema
|
// Support old indexes schema
|
||||||
if (!Array.isArray(data.indexes)) {
|
if (!Array.isArray(opts.indexes)) {
|
||||||
data.indexes = HDParams.update(data.indexes, data.totalCopayers);
|
opts.indexes = HDParams.update(opts.indexes, opts.totalCopayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret = new PublicKeyRing(data);
|
var ret = new PublicKeyRing(opts);
|
||||||
|
|
||||||
for (var k in data.copayersExtPubKeys) {
|
for (var k in opts.copayersExtPubKeys) {
|
||||||
ret.addCopayer(data.copayersExtPubKeys[k]);
|
ret.addCopayer(opts.copayersExtPubKeys[k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -365,8 +376,10 @@ PublicKeyRing.prototype._checkInPKR = function(inPKR, ignoreId) {
|
||||||
|
|
||||||
PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var hasChanged = false;
|
var hasChanged = false;
|
||||||
var l = self.copayersHK.length;
|
var l = self.copayersHK.length;
|
||||||
|
|
||||||
if (self.isComplete())
|
if (self.isComplete())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -421,7 +434,7 @@ PublicKeyRing.prototype.merge = function(inPKR, ignoreId) {
|
||||||
var hasChanged = false;
|
var hasChanged = false;
|
||||||
hasChanged |= this.mergeIndexes(inPKR.indexes);
|
hasChanged |= this.mergeIndexes(inPKR.indexes);
|
||||||
hasChanged |= this._mergePubkeys(inPKR);
|
hasChanged |= this._mergePubkeys(inPKR);
|
||||||
hasChanged |= this.mergeBackups(inPKR.copayersBackup);
|
hasChanged |= this._mergeBackups(inPKR.copayersBackup);
|
||||||
|
|
||||||
return !!hasChanged;
|
return !!hasChanged;
|
||||||
};
|
};
|
||||||
|
|
@ -438,7 +451,7 @@ PublicKeyRing.prototype.mergeIndexes = function(indexes) {
|
||||||
return !!hasChanged
|
return !!hasChanged
|
||||||
}
|
}
|
||||||
|
|
||||||
PublicKeyRing.prototype.mergeBackups = function(backups) {
|
PublicKeyRing.prototype._mergeBackups = function(backups) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var hasChanged = false;
|
var hasChanged = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,12 +228,12 @@ describe('PublicKeyRing model', function() {
|
||||||
var hasChanged;
|
var hasChanged;
|
||||||
|
|
||||||
w.copayersBackup = ["a", "b"];
|
w.copayersBackup = ["a", "b"];
|
||||||
hasChanged = w.mergeBackups(["b", "c"]);
|
hasChanged = w._mergeBackups(["b", "c"]);
|
||||||
w.copayersBackup.length.should.equal(3);
|
w.copayersBackup.length.should.equal(3);
|
||||||
hasChanged.should.equal(true);
|
hasChanged.should.equal(true);
|
||||||
|
|
||||||
w.copayersBackup = ["a", "b", "c"];
|
w.copayersBackup = ["a", "b", "c"];
|
||||||
hasChanged = w.mergeBackups(["b", "c"]);
|
hasChanged = w._mergeBackups(["b", "c"]);
|
||||||
w.copayersBackup.length.should.equal(3);
|
w.copayersBackup.length.should.equal(3);
|
||||||
hasChanged.should.equal(false);
|
hasChanged.should.equal(false);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -62,11 +62,9 @@ describe('Performance tests', function() {
|
||||||
generated.push(pubKeys);
|
generated.push(pubKeys);
|
||||||
}
|
}
|
||||||
var delta1 = new Date().getTime() - start1;
|
var delta1 = new Date().getTime() - start1;
|
||||||
var backup = pkr1.toObj();
|
|
||||||
var pkr2 = PublicKeyRing.fromObj(backup);
|
|
||||||
var start2 = new Date().getTime();
|
var start2 = new Date().getTime();
|
||||||
for (var i = 0; i < generateN; i++) {
|
for (var i = 0; i < generateN; i++) {
|
||||||
var pubKeys = JSON.stringify(pkr2.getPubKeys(i, false));
|
var pubKeys = JSON.stringify(pkr1.getPubKeys(i, false));
|
||||||
generated[i].should.equal(pubKeys);
|
generated[i].should.equal(pubKeys);
|
||||||
}
|
}
|
||||||
var delta2 = new Date().getTime() - start2;
|
var delta2 = new Date().getTime() - start2;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue