This commit is contained in:
wltsmrz
2014-02-19 14:06:55 -08:00
parent 573b38cc19
commit c3ceba1f05
2 changed files with 55 additions and 23 deletions

View File

@@ -104,8 +104,8 @@ function TransactionManager(account) {
filter: 'outbound' filter: 'outbound'
} }
self._remote.requestAccountTx(options, function(err, transactions) { function accountTx(err, transactions) {
if (!err && transactions.transactions) { if (!err && Array.isArray(transactions.transactions)) {
transactions.transactions.forEach(transactionReceived); transactions.transactions.forEach(transactionReceived);
} }
@@ -117,7 +117,9 @@ function TransactionManager(account) {
}); });
callback(); callback();
}); };
self._remote.requestAccountTx(options, accountTx);
self.emit('reconnect'); self.emit('reconnect');
}; };
@@ -130,20 +132,22 @@ function TransactionManager(account) {
this._remote.on('disconnect', remoteDisconnected); this._remote.on('disconnect', remoteDisconnected);
function resendPending(callback) { function resendPending(callback) {
self._remote.storage.loadAccount(self._accountID, function(err, data) { var callback = typeof callback === 'function' ? callback : function(){};
if (err || !data) return;
(data || [ ]).forEach(function(tx) { function accountLoaded(err, data) {
if (err || !(Array.isArray(data))) return;
data.forEach(function(tx) {
var transaction = self._remote.transaction(); var transaction = self._remote.transaction();
transaction.parseJson(tx.tx_json); transaction.parseJson(tx.tx_json);
transaction.submittedIDs = tx.submittedIDs; transaction.submittedIDs = tx.submittedIDs;
self.submit(transaction); self.submit(transaction);
}); });
if (typeof callback === 'function') { callback();
callback(); };
}
}); self._remote.storage.loadAccount(self._accountID, accountLoaded);
}; };
function savePending(pending) { function savePending(pending) {
@@ -436,7 +440,20 @@ TransactionManager.prototype._request = function(tx) {
} }
}; };
submitRequest.timeout(this._submissionTimeout, function requestTimeout() {
submitRequest.once('error', submitted);
submitRequest.once('success', submitted);
if (tx._server) {
submitRequest.server = tx._server;
}
submitRequest.request();
tx.setState('client_submitted');
tx.attempts++;
function requestTimeout() {
// ND: What if the response is just slow and we get a response that // ND: What if the response is just slow and we get a response that
// `submitted` above will cause to have concurrent resubmit logic streams? // `submitted` above will cause to have concurrent resubmit logic streams?
// It's simpler to just mute handlers and look out for finalized // It's simpler to just mute handlers and look out for finalized
@@ -455,19 +472,9 @@ TransactionManager.prototype._request = function(tx) {
remote._trace('transactionmanager: timeout:', tx.tx_json); remote._trace('transactionmanager: timeout:', tx.tx_json);
self._resubmit(3, tx); self._resubmit(3, tx);
} }
}); };
submitRequest.once('error', submitted); submitRequest.timeout(this._submissionTimeout, requestTimeout);
submitRequest.once('success', submitted);
if (tx._server) {
submitRequest.server = tx._server;
}
submitRequest.request();
tx.setState('client_submitted');
tx.attempts++;
return submitRequest; return submitRequest;
}; };

View File

@@ -19,6 +19,31 @@ TransactionQueue.prototype.clearCache = function() {
this._sequenceCache = { }; this._sequenceCache = { };
}; };
TransactionQueue.prototype.getMinLedger = function() {
var minLedger = Infinity;
for (var i=0; i<this._queue.length; i++) {
var submitIndex = this._queue[i].submitIndex;
if (typeof submitIndex !== 'number') {
// If any pending transactions don't have a submit index,
// return -1 for scanning all previous transactions
minLedger = -1;
break;
}
if (submitIndex < minLedger) {
minLedger = submitIndex;
}
};
if (!isFinite(minLedger)) minLedger = -1;
if (minLedger !== -1) minLedger -= 1;
return minLedger;
};
TransactionQueue.prototype.save = function() { TransactionQueue.prototype.save = function() {
if (typeof this._save !== 'function') return; if (typeof this._save !== 'function') return;