mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
JS: Have remote look in the current ledger to get Sequence for new accounts.
This commit is contained in:
committed by
Stefan Thomas
parent
0f80fa79e2
commit
eca2631491
46
js/remote.js
46
js/remote.js
@@ -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.
|
||||||
|
self.account_cache(transaction.transaction.Account, true)
|
||||||
|
.on('success_account_cache', function () {
|
||||||
|
// Try again.
|
||||||
|
self.submit(transaction);
|
||||||
|
})
|
||||||
|
.on('error', function (message) {
|
||||||
// Forward errors.
|
// Forward errors.
|
||||||
transaction.emit('error', message);
|
transaction.emit('error', message);
|
||||||
});
|
})
|
||||||
|
.request();
|
||||||
cache_request.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,6 +664,14 @@ Remote.prototype.account_cache = function (account) {
|
|||||||
request.emit('success_account_cache');
|
request.emit('success_account_cache');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (current)
|
||||||
|
{
|
||||||
|
request.ledger_index(this.ledger_current_index);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
request.ledger(this.ledger_closed);
|
||||||
|
}
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user