mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 09:17:57 +00:00
JS: Move transaction preparation logic to Transaction class.
This commit is contained in:
@@ -220,6 +220,12 @@ var Remote = function (opts, trace) {
|
|||||||
this._reserve_inc = undefined;
|
this._reserve_inc = undefined;
|
||||||
this._server_status = undefined;
|
this._server_status = undefined;
|
||||||
|
|
||||||
|
// Local signing implies local fees and sequences
|
||||||
|
if (this.local_signing) {
|
||||||
|
this.local_sequence = true;
|
||||||
|
this.local_fee = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Cache information for accounts.
|
// Cache information for accounts.
|
||||||
this.accounts = {
|
this.accounts = {
|
||||||
// Consider sequence numbers stable if you know you're not generating bad transactions.
|
// Consider sequence numbers stable if you know you're not generating bad transactions.
|
||||||
@@ -864,58 +870,12 @@ Remote.prototype.request_sign = function (secret, tx_json) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Submit a transaction.
|
// Submit a transaction.
|
||||||
Remote.prototype.submit = function (transaction) {
|
Remote.prototype.request_submit = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (transaction._secret && !this.trusted)
|
var request = new Request(this, 'submit');
|
||||||
{
|
|
||||||
transaction.emit('error', {
|
|
||||||
'result' : 'tejServerUntrusted',
|
|
||||||
'result_message' : "Attempt to give a secret to an untrusted server."
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (self.local_sequence && !transaction.tx_json.Sequence) {
|
|
||||||
transaction.tx_json.Sequence = this.account_seq(transaction.tx_json.Account, 'ADVANCE');
|
|
||||||
// console.log("Sequence: %s", transaction.tx_json.Sequence);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.local_sequence && !transaction.tx_json.Sequence) {
|
return request;
|
||||||
// Look in the last closed ledger.
|
|
||||||
this.account_seq_cache(transaction.tx_json.Account, false)
|
|
||||||
.on('success_account_seq_cache', function () {
|
|
||||||
// Try again.
|
|
||||||
self.submit(transaction);
|
|
||||||
})
|
|
||||||
.on('error_account_seq_cache', function (message) {
|
|
||||||
// XXX Maybe be smarter about this. Don't want to trust an untrusted server for this seq number.
|
|
||||||
|
|
||||||
// Look in the current ledger.
|
|
||||||
self.account_seq_cache(transaction.tx_json.Account, 'CURRENT')
|
|
||||||
.on('success_account_seq_cache', function () {
|
|
||||||
// Try again.
|
|
||||||
self.submit(transaction);
|
|
||||||
})
|
|
||||||
.on('error_account_seq_cache', function (message) {
|
|
||||||
// Forward errors.
|
|
||||||
transaction.emit('error', message);
|
|
||||||
})
|
|
||||||
.request();
|
|
||||||
})
|
|
||||||
.request();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Convert the transaction into a request and submit it.
|
|
||||||
|
|
||||||
(new Request(this, 'submit'))
|
|
||||||
.build_path(transaction._build_path)
|
|
||||||
.tx_json(transaction.tx_json)
|
|
||||||
.secret(transaction._secret)
|
|
||||||
.on('success', function (message) { transaction.emit('success', message); }) // Forward successes and errors.
|
|
||||||
.on('error', function (message) { transaction.emit('error', message); })
|
|
||||||
.request();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -929,7 +889,7 @@ Remote.prototype._server_subscribe = function () {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var feeds = [ 'ledger', 'server' ];
|
var feeds = [ 'ledger', 'server' ];
|
||||||
|
|
||||||
if (this._transaction_subs)
|
if (this._transaction_subs)
|
||||||
feeds.push('transactions');
|
feeds.push('transactions');
|
||||||
|
|
||||||
|
|||||||
@@ -219,6 +219,7 @@ Transaction.prototype.sign = function () {
|
|||||||
// // status is final status. Only works under a ledger_accepting conditions.
|
// // status is final status. Only works under a ledger_accepting conditions.
|
||||||
// switch status:
|
// switch status:
|
||||||
// case 'tesSUCCESS': all is well.
|
// case 'tesSUCCESS': all is well.
|
||||||
|
// case 'tejSecretUnknown': unable to sign transaction - secret unknown
|
||||||
// case 'tejServerUntrusted': sending secret to untrusted server.
|
// case 'tejServerUntrusted': sending secret to untrusted server.
|
||||||
// case 'tejInvalidAccount': locally detected error.
|
// case 'tejInvalidAccount': locally detected error.
|
||||||
// case 'tejLost': locally gave up looking
|
// case 'tejLost': locally gave up looking
|
||||||
@@ -236,7 +237,7 @@ Transaction.prototype.submit = function (callback) {
|
|||||||
'error' : 'tejInvalidAccount',
|
'error' : 'tejInvalidAccount',
|
||||||
'error_message' : 'Bad account.'
|
'error_message' : 'Bad account.'
|
||||||
});
|
});
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// YYY Might check paths for invalid accounts.
|
// YYY Might check paths for invalid accounts.
|
||||||
@@ -308,7 +309,68 @@ Transaction.prototype.submit = function (callback) {
|
|||||||
|
|
||||||
this.set_state('client_submitted');
|
this.set_state('client_submitted');
|
||||||
|
|
||||||
this.remote.submit(this);
|
if (self.remote.local_sequence && !self.tx_json.Sequence) {
|
||||||
|
self.tx_json.Sequence = this.remote.account_seq(self.tx_json.Account, 'ADVANCE');
|
||||||
|
// console.log("Sequence: %s", self.tx_json.Sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.remote.local_sequence && !self.tx_json.Sequence) {
|
||||||
|
// Look in the last closed ledger.
|
||||||
|
this.remote.account_seq_cache(self.tx_json.Account, false)
|
||||||
|
.on('success_account_seq_cache', function () {
|
||||||
|
// Try again.
|
||||||
|
self.submit();
|
||||||
|
})
|
||||||
|
.on('error_account_seq_cache', function (message) {
|
||||||
|
// XXX Maybe be smarter about this. Don't want to trust an untrusted server for this seq number.
|
||||||
|
|
||||||
|
// Look in the current ledger.
|
||||||
|
self.remote.account_seq_cache(self.tx_json.Account, 'CURRENT')
|
||||||
|
.on('success_account_seq_cache', function () {
|
||||||
|
// Try again.
|
||||||
|
self.submit();
|
||||||
|
})
|
||||||
|
.on('error_account_seq_cache', function (message) {
|
||||||
|
// Forward errors.
|
||||||
|
self.emit('error', message);
|
||||||
|
})
|
||||||
|
.request();
|
||||||
|
})
|
||||||
|
.request();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare request
|
||||||
|
|
||||||
|
var request = this.remote.request_submit();
|
||||||
|
|
||||||
|
// Forward successes and errors.
|
||||||
|
request.on('success', function (message) { self.emit('success', message); });
|
||||||
|
request.on('error', function (message) { self.emit('error', message); });
|
||||||
|
|
||||||
|
if (!this._secret && !this.tx_json.Signature) {
|
||||||
|
this.emit('error', {
|
||||||
|
'result' : 'tejSecretUnknown',
|
||||||
|
'result_message' : "Could not sign transactions because we."
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
} else if (this.remote.local_signing) {
|
||||||
|
this.sign();
|
||||||
|
} else {
|
||||||
|
if (!this.remote.trusted) {
|
||||||
|
this.emit('error', {
|
||||||
|
'result' : 'tejServerUntrusted',
|
||||||
|
'result_message' : "Attempt to give a secret to an untrusted server."
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
request.secret(this._secret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
request.build_path(this._build_path);
|
||||||
|
request.tx_json(this.tx_json);
|
||||||
|
request.request();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user