mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
JS: Transaction: Fix multiple "final" events due to race condition.
This commit is contained in:
@@ -74,6 +74,7 @@ var Transaction = function (remote) {
|
|||||||
this.hash = undefined;
|
this.hash = undefined;
|
||||||
this.submit_index = undefined; // ledger_current_index was this when transaction was submited.
|
this.submit_index = undefined; // ledger_current_index was this when transaction was submited.
|
||||||
this.state = undefined; // Under construction.
|
this.state = undefined; // Under construction.
|
||||||
|
this.finalized = false;
|
||||||
|
|
||||||
this.on('success', function (message) {
|
this.on('success', function (message) {
|
||||||
if (message.engine_result) {
|
if (message.engine_result) {
|
||||||
@@ -257,15 +258,19 @@ Transaction.prototype.submit = function (callback) {
|
|||||||
self.remote.request_transaction_entry(self.hash)
|
self.remote.request_transaction_entry(self.hash)
|
||||||
.ledger_hash(ledger_hash)
|
.ledger_hash(ledger_hash)
|
||||||
.on('success', function (message) {
|
.on('success', function (message) {
|
||||||
|
if (self.finalized) return;
|
||||||
|
|
||||||
self.set_state(message.metadata.TransactionResult);
|
self.set_state(message.metadata.TransactionResult);
|
||||||
|
self.remote.removeListener('ledger_closed', on_ledger_closed);
|
||||||
self.emit('final', message);
|
self.emit('final', message);
|
||||||
|
self.finalized = true;
|
||||||
|
|
||||||
if (self.callback)
|
if (self.callback)
|
||||||
self.callback(message.metadata.TransactionResult, message);
|
self.callback(message.metadata.TransactionResult, message);
|
||||||
|
|
||||||
stop = true;
|
|
||||||
})
|
})
|
||||||
.on('error', function (message) {
|
.on('error', function (message) {
|
||||||
|
if (self.finalized) return;
|
||||||
|
|
||||||
if ('remoteError' === message.error
|
if ('remoteError' === message.error
|
||||||
&& 'transactionNotFound' === message.remote.error) {
|
&& 'transactionNotFound' === message.remote.error) {
|
||||||
if (self.submit_index + SUBMIT_LOST < ledger_index) {
|
if (self.submit_index + SUBMIT_LOST < ledger_index) {
|
||||||
@@ -275,7 +280,9 @@ Transaction.prototype.submit = function (callback) {
|
|||||||
if (self.callback)
|
if (self.callback)
|
||||||
self.callback('tejLost', message);
|
self.callback('tejLost', message);
|
||||||
|
|
||||||
stop = true;
|
self.remote.removeListener('ledger_closed', on_ledger_closed);
|
||||||
|
self.emit('final', message);
|
||||||
|
self.finalized = true;
|
||||||
}
|
}
|
||||||
else if (self.submit_index + SUBMIT_MISSING < ledger_index) {
|
else if (self.submit_index + SUBMIT_MISSING < ledger_index) {
|
||||||
self.set_state('client_missing'); // We don't know what happened to transaction, still might find.
|
self.set_state('client_missing'); // We don't know what happened to transaction, still might find.
|
||||||
@@ -288,11 +295,6 @@ Transaction.prototype.submit = function (callback) {
|
|||||||
// XXX Could log other unexpectedness.
|
// XXX Could log other unexpectedness.
|
||||||
})
|
})
|
||||||
.request();
|
.request();
|
||||||
|
|
||||||
if (stop) {
|
|
||||||
self.remote.removeListener('ledger_closed', on_ledger_closed);
|
|
||||||
self.emit('final', message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.remote.on('ledger_closed', on_ledger_closed);
|
this.remote.on('ledger_closed', on_ledger_closed);
|
||||||
|
|||||||
Reference in New Issue
Block a user