diff --git a/lib/server.js b/lib/server.js index d30bedd..ad1c871 100644 --- a/lib/server.js +++ b/lib/server.js @@ -2448,16 +2448,28 @@ WalletService.prototype._normalizeTxHistory = function(txs) { }); }; -WalletService._cachedBlockheight = {}; +WalletService._cachedBlockheight; + +WalletService._initBlockchainHeightCache = function() { + if (WalletService._cachedBlockheight) return; + WalletService._cachedBlockheight = { + livenet: {}, + testnet: {} + }; +}; + WalletService._clearBlockchainHeightCache = function() { - WalletService._cachedBlockheight.current = null; + WalletService._initBlockchainHeightCache(); + WalletService._cachedBlockheight.livenet.current = null; + WalletService._cachedBlockheight.testnet.current = null; }; WalletService.prototype._getBlockchainHeight = function(network, cb) { var self = this; var now = Date.now(); - var cache = WalletService._cachedBlockheight; + WalletService._initBlockchainHeightCache(); + var cache = WalletService._cachedBlockheight[network]; function fetchFromBlockchain(cb) { var bc = self._getBlockchainExplorer(network); diff --git a/test/integration/server.js b/test/integration/server.js index 9d61314..b032293 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -5930,7 +5930,7 @@ describe('Wallet service', function() { it('should get real # of confirmations based on current block height', function(done) { var _confirmations = Defaults.CONFIRMATIONS_TO_START_CACHING; Defaults.CONFIRMATIONS_TO_START_CACHING = 6; - WalletService._cachedBlockheight = {}; + WalletService._cachedBlockheight = null; var h = helpers.historyCacheTest(20); _.each(h, function(x, i) { @@ -5989,7 +5989,7 @@ describe('Wallet service', function() { it('should get cached # of confirmations if current height unknown', function(done) { var _confirmations = Defaults.CONFIRMATIONS_TO_START_CACHING; Defaults.CONFIRMATIONS_TO_START_CACHING = 6; - WalletService._cachedBlockheight = {}; + WalletService._cachedBlockheight = null; var h = helpers.historyCacheTest(20); helpers.stubHistory(h);