Use account_tx outbound filter, only query account_tx if the pending queue is non-empty

This commit is contained in:
wltsmrz
2014-02-18 16:33:31 -08:00
parent 5c8550b364
commit 7f13a71252

View File

@@ -89,12 +89,19 @@ function TransactionManager(account) {
this._remote.on('ledger_closed', updatePendingStatus); this._remote.on('ledger_closed', updatePendingStatus);
function remoteReconnected(callback) { function remoteReconnected(callback) {
var callback = typeof callback === 'function' ? callback : function(){};
if (!self._pending.length) {
return callback();
}
//Load account transaction history //Load account transaction history
var options = { var options = {
account: self._accountID, account: self._accountID,
ledger_index_min: -1, ledger_index_min: -1,
ledger_index_max: -1, ledger_index_max: -1,
limit: 100 limit: 100,
filter: 'outbound'
} }
self._remote.requestAccountTx(options, function(err, transactions) { self._remote.requestAccountTx(options, function(err, transactions) {
@@ -109,9 +116,7 @@ function TransactionManager(account) {
self._resubmit(); self._resubmit();
}); });
if (typeof callback === 'function') { callback();
callback();
}
}); });
self.emit('reconnect'); self.emit('reconnect');
@@ -124,7 +129,7 @@ function TransactionManager(account) {
this._remote.on('disconnect', remoteDisconnected); this._remote.on('disconnect', remoteDisconnected);
function resendPending() { function resendPending(callback) {
self._remote.storage.loadAccount(self._accountID, function(err, data) { self._remote.storage.loadAccount(self._accountID, function(err, data) {
if (err || !data) return; if (err || !data) return;
@@ -134,6 +139,10 @@ function TransactionManager(account) {
transaction.submittedIDs = tx.submittedIDs; transaction.submittedIDs = tx.submittedIDs;
self.submit(transaction); self.submit(transaction);
}); });
if (typeof callback === 'function') {
callback();
}
}); });
}; };
@@ -143,7 +152,7 @@ function TransactionManager(account) {
}; };
if (this._remote.storage) { if (this._remote.storage) {
remoteReconnected(resendPending); resendPending(remoteReconnected);
this._pending._save = savePending; this._pending._save = savePending;
} }
}; };