From 51d5d7164ec652fcab39e958afc89014b78f28da Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Wed, 4 Jun 2014 13:44:32 -0300 Subject: [PATCH] add AddressIndex model --- copay.js | 1 + js/models/core/AddressIndex.js | 6 +-- js/models/core/PrivateKey.js | 3 ++ js/models/core/PublicKeyRing.js | 4 +- test/test.AddressIndex.js | 84 +++++++++++++++++++++++++++++++++ test/test.PublicKeyRing.js | 12 ++--- test/test.TxProposals.js | 7 ++- test/test.WalletFactory.js | 3 +- 8 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 test/test.AddressIndex.js diff --git a/copay.js b/copay.js index 9149fa071..585fc1677 100644 --- a/copay.js +++ b/copay.js @@ -5,6 +5,7 @@ module.exports.TxProposals = require('./js/models/core/TxProposals'); module.exports.PrivateKey = require('./js/models/core/PrivateKey'); module.exports.Passphrase = require('./js/models/core/Passphrase'); module.exports.Structure = require('./js/models/core/Structure'); +module.exports.AddressIndex = require('./js/models/core/AddressIndex'); // components diff --git a/js/models/core/AddressIndex.js b/js/models/core/AddressIndex.js index b5a4aab68..14e42ffc6 100644 --- a/js/models/core/AddressIndex.js +++ b/js/models/core/AddressIndex.js @@ -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; }; diff --git a/js/models/core/PrivateKey.js b/js/models/core/PrivateKey.js index d324f1831..7475f9146 100644 --- a/js/models/core/PrivateKey.js +++ b/js/models/core/PrivateKey.js @@ -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