From cf1732fc44ce31dd974f3c13d300c5a8f8117ac5 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 27 Mar 2014 01:18:29 -0300 Subject: [PATCH] add getAddresses to return all wallet\'s addresses --- js/models/wallet.js | 46 +++++++++++++++++++++++++++++++++++---------- test/test.wallet.js | 22 +++++++++++++++++++++- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/js/models/wallet.js b/js/models/wallet.js index 857d06a0b..3fb113c37 100644 --- a/js/models/wallet.js +++ b/js/models/wallet.js @@ -1,15 +1,16 @@ 'use strict'; -var imports = require('soop').imports(); -var bitcore = require('bitcore'); -var BIP32 = bitcore.BIP32; -var Address = bitcore.Address; -var Script = bitcore.Script; -var coinUtil= bitcore.util; +var imports = require('soop').imports(); +var bitcore = require('bitcore'); +var BIP32 = bitcore.BIP32; +var Address = bitcore.Address; +var Script = bitcore.Script; +var coinUtil = bitcore.util; +var Transaction = bitcore.Transaction; -var Storage = imports.Storage || require('./Storage'); -var log = imports.log || console.log; +var Storage = imports.Storage || require('./Storage'); +var log = imports.log || console.log; -var storage = Storage.default(); +var storage = Storage.default(); /* * This follow Electrum convetion, as described on @@ -220,6 +221,12 @@ Wallet.prototype.getCosignersSortedPubKeys = function(index, isChange) { Wallet.prototype.getAddress = function (index, isChange) { + if ( (isChange && index > this.changeAddressIndex) + || (!isChange && index > this.addressIndex)) { + log('Out of bounds at getAddress: Index %d isChange: %d', index, isChange); + throw new Error('index out of bound'); + } + var pubKeys = this.getCosignersSortedPubKeys(index, isChange); var version = this.network.addressScript; @@ -244,7 +251,26 @@ Wallet.prototype.createAddress = function(isChange) { return ret; }; - + +Wallet.prototype.getAddresses = function() { + var ret = []; + + for (var i=0; i