JS: Have remote look in the current ledger to get Sequence for new accounts.

This commit is contained in:
Arthur Britto
2012-10-18 00:12:48 -07:00
committed by Stefan Thomas
parent 0f80fa79e2
commit eca2631491

View File

@@ -539,19 +539,26 @@ Remote.prototype.submit = function (transaction) {
} }
if (!transaction.transaction.Sequence) { if (!transaction.transaction.Sequence) {
var cache_request = this.account_cache(transaction.transaction.Account); // Look in the last closed ledger.
this.account_cache(transaction.transaction.Account, false)
cache_request.on('success_account_cache', function () { .on('success_account_cache', function () {
// Try again. // Try again.
self.submit(transaction); self.submit(transaction);
}); })
.on('error', function (message) {
cache_request.on('error', function (message) { // Look in the current ledger.
// Forward errors. self.account_cache(transaction.transaction.Account, true)
transaction.emit('error', message); .on('success_account_cache', function () {
}); // Try again.
self.submit(transaction);
cache_request.request(); })
.on('error', function (message) {
// Forward errors.
transaction.emit('error', message);
})
.request();
})
.request();
} }
else { else {
var submit_request = new Request(this, 'submit'); var submit_request = new Request(this, 'submit');
@@ -639,16 +646,13 @@ Remote.prototype.account_seq = function (account, advance) {
} }
// Return a request to refresh accounts[account].seq. // Return a request to refresh accounts[account].seq.
Remote.prototype.account_cache = function (account) { Remote.prototype.account_cache = function (account, current) {
var self = this; var self = this;
var request = this.request_ledger_entry('account_root') var request = this.request_ledger_entry('account_root');
// Only care about a closed ledger. request
// YYY Might be more advanced and work with a changing current ledger. .account_root(account)
request.ledger(this.ledger_closed); // XXX Requires active server_subscribe .on('success', function (message) {
request.account_root(account);
request.on('success', function (message) {
var seq = message.node.Sequence; var seq = message.node.Sequence;
if (!self.accounts[account]) if (!self.accounts[account])
@@ -660,7 +664,15 @@ Remote.prototype.account_cache = function (account) {
request.emit('success_account_cache'); request.emit('success_account_cache');
}); });
return request; if (current)
{
request.ledger_index(this.ledger_current_index);
}
else {
request.ledger(this.ledger_closed);
}
return request;
}; };
// Mark an account's root node as dirty. // Mark an account's root node as dirty.