remove pubkey cache from network and storage

This commit is contained in:
Matias Alejo Garcia 2014-08-19 11:48:29 -04:00
parent 73a2a9fba3
commit 20af614f40
4 changed files with 33 additions and 24 deletions

View File

@ -21,7 +21,7 @@ function PublicKeyRing(opts) {
this.requiredCopayers = opts.requiredCopayers || 3;
this.totalCopayers = opts.totalCopayers || 5;
this.copayersHK = opts.copayersHK || [];
this.copayersHK = [];
this.indexes = opts.indexes ? HDParams.fromList(opts.indexes) : HDParams.init(this.totalCopayers);
@ -32,20 +32,31 @@ function PublicKeyRing(opts) {
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) {
if (data instanceof PublicKeyRing) {
throw new Error('bad data format: Did you use .toObj()?');
}
var opts = PublicKeyRing.trim(data);
// Support old indexes schema
if (!Array.isArray(data.indexes)) {
data.indexes = HDParams.update(data.indexes, data.totalCopayers);
if (!Array.isArray(opts.indexes)) {
opts.indexes = HDParams.update(opts.indexes, opts.totalCopayers);
}
var ret = new PublicKeyRing(data);
var ret = new PublicKeyRing(opts);
for (var k in data.copayersExtPubKeys) {
ret.addCopayer(data.copayersExtPubKeys[k]);
for (var k in opts.copayersExtPubKeys) {
ret.addCopayer(opts.copayersExtPubKeys[k]);
}
return ret;
@ -365,8 +376,10 @@ PublicKeyRing.prototype._checkInPKR = function(inPKR, ignoreId) {
PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
var self = this;
var hasChanged = false;
var l = self.copayersHK.length;
if (self.isComplete())
return;
@ -421,7 +434,7 @@ PublicKeyRing.prototype.merge = function(inPKR, ignoreId) {
var hasChanged = false;
hasChanged |= this.mergeIndexes(inPKR.indexes);
hasChanged |= this._mergePubkeys(inPKR);
hasChanged |= this.mergeBackups(inPKR.copayersBackup);
hasChanged |= this._mergeBackups(inPKR.copayersBackup);
return !!hasChanged;
};
@ -438,7 +451,7 @@ PublicKeyRing.prototype.mergeIndexes = function(indexes) {
return !!hasChanged
}
PublicKeyRing.prototype.mergeBackups = function(backups) {
PublicKeyRing.prototype._mergeBackups = function(backups) {
var self = this;
var hasChanged = false;

View File

@ -228,12 +228,12 @@ describe('PublicKeyRing model', function() {
var hasChanged;
w.copayersBackup = ["a", "b"];
hasChanged = w.mergeBackups(["b", "c"]);
hasChanged = w._mergeBackups(["b", "c"]);
w.copayersBackup.length.should.equal(3);
hasChanged.should.equal(true);
w.copayersBackup = ["a", "b", "c"];
hasChanged = w.mergeBackups(["b", "c"]);
hasChanged = w._mergeBackups(["b", "c"]);
w.copayersBackup.length.should.equal(3);
hasChanged.should.equal(false);
});

File diff suppressed because one or more lines are too long

View File

@ -62,11 +62,9 @@ describe('Performance tests', function() {
generated.push(pubKeys);
}
var delta1 = new Date().getTime() - start1;
var backup = pkr1.toObj();
var pkr2 = PublicKeyRing.fromObj(backup);
var start2 = new Date().getTime();
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);
}
var delta2 = new Date().getTime() - start2;