Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
JoelKatz
2012-10-18 09:19:15 -07:00

View File

@@ -539,19 +539,28 @@ Remote.prototype.submit = function (transaction) {
}
if (!transaction.transaction.Sequence) {
var cache_request = this.account_cache(transaction.transaction.Account);
cache_request.on('success_account_cache', function () {
// Look in the last closed ledger.
this.account_seq_cache(transaction.transaction.Account, false)
.on('success_account_seq_cache', function () {
// Try again.
self.submit(transaction);
});
})
.on('error', function (message) {
// XXX Maybe be smarter about this. Don't want to trust an untrusted server for this seq number.
cache_request.on('error', function (message) {
// Forward errors.
transaction.emit('error', message);
});
cache_request.request();
// Look in the current ledger.
self.account_seq_cache(transaction.transaction.Account, 'CURRENT')
.on('success_account_seq_cache', function () {
// Try again.
self.submit(transaction);
})
.on('error', function (message) {
// Forward errors.
transaction.emit('error', message);
})
.request();
})
.request();
}
else {
var submit_request = new Request(this, 'submit');
@@ -563,10 +572,6 @@ Remote.prototype.submit = function (transaction) {
submit_request.on('success', function (message) { transaction.emit('success', message); });
submit_request.on('error', function (message) { transaction.emit('error', message); });
// XXX If transaction has a 'final' event listeners, register transaction to listen to final results.
// XXX Final messages only happen if a transaction makes it into a ledger.
// XXX A transaction may be "lost" or even resubmitted in this case.
// XXX For when ledger closes, can look up transaction meta data.
submit_request.request();
}
}
@@ -639,16 +644,13 @@ Remote.prototype.account_seq = function (account, advance) {
}
// Return a request to refresh accounts[account].seq.
Remote.prototype.account_cache = function (account) {
Remote.prototype.account_seq_cache = function (account, current) {
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.
// YYY Might be more advanced and work with a changing current ledger.
request.ledger(this.ledger_closed); // XXX Requires active server_subscribe
request.account_root(account);
request.on('success', function (message) {
request
.account_root(account)
.on('success', function (message) {
var seq = message.node.Sequence;
if (!self.accounts[account])
@@ -657,10 +659,18 @@ Remote.prototype.account_cache = function (account) {
self.accounts[account].seq = seq;
// If the caller also waits for 'success', they might run before this.
request.emit('success_account_cache');
request.emit('success_account_seq_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.
@@ -675,7 +685,14 @@ Remote.prototype.transaction = function () {
//
// Transactions
//
// Transaction events:
// Construction:
// remote.transaction() // Build a transaction object.
// .offer_create(...) // Set major parameters.
// .flags() // Set optional parameters.
// .on() // Register for events.
// .submit(); // Send to network.
//
// Events:
// 'success' : Transaction submitted without error.
// 'error' : Error submitting transaction.
// 'proposed: Advisory proposed status transaction.
@@ -701,8 +718,8 @@ Remote.prototype.transaction = function () {
// \- 'tep...' - Transaction partially succeeded.
//
// Notes:
// - All transactions including locally errors and malformed errors may be
// forwarded.
// - All transactions including those with local and malformed errors may be
// forwarded anyway.
// - A malicous server can:
// - give any proposed result.
// - it may declare something correct as incorrect or something correct as incorrect.
@@ -922,18 +939,6 @@ Transaction.prototype.flags = function (flags) {
//
// Transactions
//
// Construction:
// remote.transaction() // Build a transaction object.
// .offer_create(...) // Set major parameters.
// .flags() // Set optional parameters.
// .on() // Register for events.
// .submit(); // Send to network.
//
// Events:
// 'success' // Transaction was successfully submitted: hash, proposed TER
// 'error' // Error submitting transaction.
// 'closed' // Result from closed ledger: TER
//
// Allow config account defaults to be used.
Transaction.prototype.account_default = function (account) {