Add update indexes and support old indexes schema

This commit is contained in:
Yemel Jardi 2014-07-03 16:42:03 -03:00
commit 2abc35ae57
5 changed files with 56 additions and 35 deletions

View file

@ -40,8 +40,7 @@ PublicKeyRing.fromObj = function(data) {
// Support old indexes schema
if (!Array.isArray(data.indexes)) {
data.indexes.cosigner = Structure.SHARED_INDEX;
data.indexes = [data.indexes];
data.indexes = AddressIndex.update(data.indexes, data.totalCopayers);
}
var ret = new PublicKeyRing(data);
@ -59,7 +58,7 @@ PublicKeyRing.prototype.toObj = function() {
networkName: this.network.name,
requiredCopayers: this.requiredCopayers,
totalCopayers: this.totalCopayers,
indexes: this.getIndexesObj(),
indexes: AddressIndex.serialize(this.indexes),
copayersExtPubKeys: this.copayersHK.map(function(b) {
return b.extendedPublicKeyString();
@ -69,10 +68,6 @@ PublicKeyRing.prototype.toObj = function() {
};
};
PublicKeyRing.prototype.getIndexesObj = function(i) {
return this.indexes.map(function(i) { return i.toObj(); });
}
PublicKeyRing.prototype.getCopayerId = function(i) {
preconditions.checkArgument(typeof i !== 'undefined');
return this.copayerIds[i];