add AddressIndex model
This commit is contained in:
parent
88df346c51
commit
51d5d7164e
8 changed files with 104 additions and 16 deletions
|
|
@ -37,7 +37,7 @@ AddressIndex.prototype.toObj = function() {
|
|||
};
|
||||
};
|
||||
|
||||
AddressIndex.prototype._checkIndexRange = function(index, isChange) {
|
||||
AddressIndex.prototype.checkRange = function(index, isChange) {
|
||||
if ((isChange && index > this.changeIndex) ||
|
||||
(!isChange && index > this.receiveIndex)) {
|
||||
throw new Error('Out of bounds at index %d isChange: %d', index, isChange);
|
||||
|
|
@ -45,10 +45,10 @@ AddressIndex.prototype._checkIndexRange = function(index, isChange) {
|
|||
};
|
||||
|
||||
|
||||
AddressIndex.prorotype.getChangeIndex = function() {
|
||||
AddressIndex.prototype.getChangeIndex = function() {
|
||||
return this.changeIndex;
|
||||
};
|
||||
AddressIndex.prorotype.getReceiveIndex = function() {
|
||||
AddressIndex.prototype.getReceiveIndex = function() {
|
||||
return this.receiveIndex;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,9 @@ PrivateKey.prototype.get = function(index,isChange) {
|
|||
};
|
||||
|
||||
PrivateKey.prototype.getAll = function(receiveIndex, changeIndex) {
|
||||
if (typeof receiveIndex === 'undefined' || typeof changeIndex === 'undefined')
|
||||
throw new Error('Invalid parameters');
|
||||
|
||||
var ret = [];
|
||||
for(var i=0;i<receiveIndex; i++) {
|
||||
ret.push(this.get(i,false));
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ function PublicKeyRing(opts) {
|
|||
|
||||
this.copayersHK = opts.copayersHK || [];
|
||||
|
||||
this.indexes = opts.indexes || new ;
|
||||
this.indexes = AddressIndex.fromObj(opts.indexes) || new AddressIndex(opts);
|
||||
|
||||
this.publicKeysCache = opts.publicKeysCache || {};
|
||||
this.nicknameFor = opts.nicknameFor || {};
|
||||
|
|
@ -159,7 +159,7 @@ PublicKeyRing.prototype.getPubKeys = function(index, isChange) {
|
|||
|
||||
// TODO this could be cached
|
||||
PublicKeyRing.prototype.getRedeemScript = function (index, isChange) {
|
||||
this._checkIndexRange(index, isChange);
|
||||
this.indexes.checkRange(index, isChange);
|
||||
|
||||
var pubKeys = this.getPubKeys(index, isChange);
|
||||
var script = Script.createMultisig(this.requiredCopayers, pubKeys);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue