Change PublicKeyRing index to array of AddressIndex

This commit is contained in:
Yemel Jardi 2014-07-01 09:41:28 -03:00
commit e9f20b5de6
8 changed files with 104 additions and 61 deletions

View file

@ -2,27 +2,28 @@
var imports = require('soop').imports();
var preconditions = require('preconditions').singleton();
var Structure = require('./Structure');
function AddressIndex(opts) {
opts = opts || {};
this.walletId = opts.walletId;
this.cosigner = opts.cosigner || 0;
this.cosigner = opts.cosigner || Structure.SHARED_INDEX;
this.changeIndex = opts.changeIndex || 0;
this.receiveIndex = opts.receiveIndex || 0;
}
AddressIndex.fromList = function(indexes) {
return indexes.map(function(i) { return AddressIndex.fromObj(i); });
}
AddressIndex.fromObj = function(data) {
if (data instanceof AddressIndex) {
throw new Error('bad data format: Did you use .toObj()?');
}
var ret = new AddressIndex(data);
return ret;
return new AddressIndex(data);
};
AddressIndex.prototype.toObj = function() {
return {
walletId: this.walletId,
cosigner: this.cosigner,
changeIndex: this.changeIndex,
receiveIndex: this.receiveIndex
@ -54,7 +55,6 @@ AddressIndex.prototype.increment = function(isChange) {
AddressIndex.prototype.merge = function(inAddressIndex) {
preconditions.shouldBeObject(inAddressIndex)
.checkArgument(this.walletId == inAddressIndex.walletId)
.checkArgument(this.cosigner == inAddressIndex.cosigner);
var hasChanged = false;