Skip to content

Commit

Permalink
fix TxFetcher._sync
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Feb 19, 2015
1 parent 6645c51 commit 7676b19
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/tx/TxFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ TxFetcher.prototype._sync = function (address) {
return
}

var promise = self._wallet.getBlockchain().getHistory(address)
var deferred = {}
deferred.promise = new Promise(function (resolve) {
deferred.resolve = resolve
})

self._syncAddresses.set(address, {count: 0, promise: deferred.promise})

self._wallet.getBlockchain().getHistory(address)
.then(function (entries) {
/** @todo Upgrade 0 to null for unconfirmed */
entries = entries.map(function (entry) {
Expand All @@ -102,18 +109,16 @@ TxFetcher.prototype._sync = function (address) {

return self._wallet.getStateManager().historySync(address, entries)
})
.then(function () {
self._syncExit()
deferred.resolve()

self._syncAddresses.set(address, {count: 0, promise: promise})

return promise
})
.then(function () {
self._syncExit()

}, function (error) {
self._syncExit()
self.emit('error', error)
}, function (error) {
self._syncExit()
deferred.resolve()
self.emit('error', error)

})
})
}

Expand Down

0 comments on commit 7676b19

Please sign in to comment.