|
|
@ -157,7 +157,8 @@ WalletService.handleIncomingNotification = function(notification, cb) { |
|
|
|
cb = cb || function() {}; |
|
|
|
|
|
|
|
if (!notification || notification.type != 'NewBlock') return cb(); |
|
|
|
WalletService._clearBlockchainHeightCache(); |
|
|
|
|
|
|
|
WalletService._clearBlockchainHeightCache(notification.data.network); |
|
|
|
return cb(); |
|
|
|
}; |
|
|
|
|
|
|
@ -2448,16 +2449,31 @@ WalletService.prototype._normalizeTxHistory = function(txs) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
WalletService._cachedBlockheight = {}; |
|
|
|
WalletService._clearBlockchainHeightCache = function() { |
|
|
|
WalletService._cachedBlockheight.current = null; |
|
|
|
WalletService._cachedBlockheight; |
|
|
|
|
|
|
|
WalletService._initBlockchainHeightCache = function() { |
|
|
|
if (WalletService._cachedBlockheight) return; |
|
|
|
WalletService._cachedBlockheight = { |
|
|
|
livenet: {}, |
|
|
|
testnet: {} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
WalletService._clearBlockchainHeightCache = function(network) { |
|
|
|
WalletService._initBlockchainHeightCache(); |
|
|
|
if (!_.contains(['livenet', 'testnet'], network)) { |
|
|
|
log.error('Incorrect network in new block: ' + network); |
|
|
|
return; |
|
|
|
} |
|
|
|
WalletService._cachedBlockheight[network].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); |
|
|
|