Fix transaction finalize

This commit is contained in:
wltsmrz
2014-04-15 12:27:33 -07:00
parent b14fab8aa7
commit 1e3c96b14f

View File

@@ -81,23 +81,16 @@ function Transaction(remote) {
// any time it goes on the network
this.submittedIDs = [ ];
function finalize(message) {
if (!self.finalized) {
self.finalized = true;
self.emit('cleanup', message);
}
};
this.once('success', function(message) {
self.finalized = true;
self.setState('validated');
finalize(message);
self.finalize(message);
self.emit('cleanup', message);
});
this.once('error', function(message) {
self.finalized = true;
self.setState('failed');
finalize(message);
self.finalize(message);
self.emit('cleanup', message);
});
this.once('submitted', function() {
@@ -207,6 +200,20 @@ Transaction.prototype.setState = function(state) {
}
};
Transaction.prototype.finalize = function(message) {
this.finalized = true;
if (this.result) {
this.result.ledger_index = message.ledger_index;
this.result.ledger_hash = message.ledger_hash;
} else {
this.result = message;
this.result.tx_json = this.tx_json;
}
return this;
};
Transaction.prototype._accountSecret = function(account) {
return this.remote.secrets[account];
};