mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 07:35:52 +00:00
Fix ledger index argument to transactionEntry, add flexibility to remote.transaction
This commit is contained in:
@@ -1497,9 +1497,6 @@ Remote.prototype.transaction = function(source, options, callback) {
|
|||||||
|
|
||||||
transaction = transaction[transactionType](options);
|
transaction = transaction[transactionType](options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
throw new Error('Argument must be string or object: ' + source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastArg = arguments[arguments.length - 1];
|
var lastArg = arguments[arguments.length - 1];
|
||||||
|
|||||||
@@ -54,35 +54,36 @@ var RippleError = require('./rippleerror').RippleError;
|
|||||||
var hashprefixes = require('./hashprefixes');
|
var hashprefixes = require('./hashprefixes');
|
||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
|
|
||||||
// A class to implement transactions.
|
|
||||||
// - Collects parameters
|
|
||||||
// - Allow event listeners to be attached to determine the outcome.
|
|
||||||
function Transaction(remote) {
|
function Transaction(remote) {
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.remote = remote;
|
this.remote = remote;
|
||||||
this._secret = void(0);
|
|
||||||
this._build_path = false;
|
|
||||||
|
|
||||||
// Transaction data.
|
this._secret = void(0);
|
||||||
this.tx_json = { Flags: 0 };
|
|
||||||
|
|
||||||
// ledger_current_index was this when transaction was submited.
|
// Transaction data
|
||||||
this.submit_index = void(0);
|
this.tx_json = { Flags: 0 };
|
||||||
|
|
||||||
// Under construction.
|
this._build_path = false;
|
||||||
this.state = void(0);
|
|
||||||
|
|
||||||
this.finalized = false;
|
// Index at which transaction was submitted
|
||||||
this._previous_signing_hash = void(0);
|
this.submitIndex = void(0);
|
||||||
|
|
||||||
|
this.state = void(0);
|
||||||
|
|
||||||
|
this.finalized = false;
|
||||||
|
|
||||||
|
this.previousSigningHash = void(0);
|
||||||
|
|
||||||
// We aren't clever enough to eschew preventative measures so we keep an array
|
// We aren't clever enough to eschew preventative measures so we keep an array
|
||||||
// of all submitted transactionIDs (which can change due to load_factor
|
// of all submitted transactionIDs (which can change due to load_factor
|
||||||
// effecting the Fee amount). This should be populated with a transactionID
|
// effecting the Fee amount). This should be populated with a transactionID
|
||||||
// any time it goes on the network
|
// any time it goes on the network
|
||||||
this.submittedTxnIDs = [ ]
|
this.submittedTxnIDs = [ ]
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(Transaction, EventEmitter);
|
util.inherits(Transaction, EventEmitter);
|
||||||
@@ -137,6 +138,11 @@ Transaction.from_json = function(j) {
|
|||||||
return (new Transaction()).parse_json(j);
|
return (new Transaction()).parse_json(j);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Transaction.prototype.parseJson = function(v) {
|
||||||
|
this.tx_json = v;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
Transaction.prototype.isTelLocal = function(ter) {
|
Transaction.prototype.isTelLocal = function(ter) {
|
||||||
return ter >= this.consts.telLOCAL_ERROR && ter < this.consts.temMALFORMED;
|
return ter >= this.consts.telLOCAL_ERROR && ter < this.consts.temMALFORMED;
|
||||||
};
|
};
|
||||||
@@ -172,6 +178,10 @@ Transaction.prototype.setState = function(state) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Transaction.prototype._accountSecret = function(account) {
|
||||||
|
return this.remote.secrets[account];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of fee units this transaction will cost.
|
* Returns the number of fee units this transaction will cost.
|
||||||
*
|
*
|
||||||
@@ -250,23 +260,6 @@ Transaction.prototype.signingHash = function() {
|
|||||||
return this.hash(config.testnet ? 'HASH_TX_SIGN_TESTNET' : 'HASH_TX_SIGN');
|
return this.hash(config.testnet ? 'HASH_TX_SIGN_TESTNET' : 'HASH_TX_SIGN');
|
||||||
};
|
};
|
||||||
|
|
||||||
Transaction.prototype.addSubmittedTxnID = function(hash) {
|
|
||||||
if (this.submittedTxnIDs.indexOf(hash) === -1) {
|
|
||||||
this.submittedTxnIDs.unshift(hash);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Transaction.prototype.findResultInCache = function(cache) {
|
|
||||||
var result;
|
|
||||||
|
|
||||||
for (var i=0; i<this.submittedTxnIDs.length; i++) {
|
|
||||||
var hash = this.submittedTxnIDs[i];
|
|
||||||
if (result = cache[hash]) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
Transaction.prototype.hash = function(prefix, as_uint256) {
|
Transaction.prototype.hash = function(prefix, as_uint256) {
|
||||||
if (typeof prefix === 'string') {
|
if (typeof prefix === 'string') {
|
||||||
if (typeof hashprefixes[prefix] === 'undefined') {
|
if (typeof hashprefixes[prefix] === 'undefined') {
|
||||||
@@ -291,7 +284,7 @@ Transaction.prototype.sign = function() {
|
|||||||
var hash = this.signing_hash();
|
var hash = this.signing_hash();
|
||||||
|
|
||||||
// If the hash is the same, we can re-use the previous signature
|
// If the hash is the same, we can re-use the previous signature
|
||||||
if (prev_sig && hash === this._previous_signing_hash) {
|
if (prev_sig && hash === this.previousSigningHash) {
|
||||||
this.tx_json.TxnSignature = prev_sig;
|
this.tx_json.TxnSignature = prev_sig;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -301,11 +294,28 @@ Transaction.prototype.sign = function() {
|
|||||||
var hex = sjcl.codec.hex.fromBits(sig).toUpperCase();
|
var hex = sjcl.codec.hex.fromBits(sig).toUpperCase();
|
||||||
|
|
||||||
this.tx_json.TxnSignature = hex;
|
this.tx_json.TxnSignature = hex;
|
||||||
this._previous_signing_hash = hash;
|
this.previousSigningHash = hash;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Transaction.prototype.addSubmittedTxnID = function(hash) {
|
||||||
|
if (this.submittedTxnIDs.indexOf(hash) === -1) {
|
||||||
|
this.submittedTxnIDs.unshift(hash);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Transaction.prototype.findResultInCache = function(cache) {
|
||||||
|
var result;
|
||||||
|
|
||||||
|
for (var i=0; i<this.submittedTxnIDs.length; i++) {
|
||||||
|
var hash = this.submittedTxnIDs[i];
|
||||||
|
if (result = cache[hash]) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set options for Transactions
|
// Set options for Transactions
|
||||||
//
|
//
|
||||||
@@ -433,11 +443,6 @@ Transaction.prototype.setFlags = function(flags) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Transaction.prototype._accountSecret = function(account) {
|
|
||||||
// Fill in secret from remote, if available.
|
|
||||||
return this.remote.secrets[account];
|
|
||||||
};
|
|
||||||
|
|
||||||
// Options:
|
// Options:
|
||||||
// .domain() NYI
|
// .domain() NYI
|
||||||
// .flags()
|
// .flags()
|
||||||
@@ -720,11 +725,6 @@ Transaction.prototype.abort = function(callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Transaction.prototype.parseJson = function(v) {
|
|
||||||
this.tx_json = v;
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.Transaction = Transaction;
|
exports.Transaction = Transaction;
|
||||||
|
|
||||||
// vim:sw=2:sts=2:ts=8:et
|
// vim:sw=2:sts=2:ts=8:et
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ function TransactionManager(account) {
|
|||||||
switch (ledger.ledger_index - pending.submitIndex) {
|
switch (ledger.ledger_index - pending.submitIndex) {
|
||||||
case 8:
|
case 8:
|
||||||
pending.emit('lost', ledger);
|
pending.emit('lost', ledger);
|
||||||
pending.emit('error', new RippleError('tejLost', 'Transaction lost'));
|
|
||||||
self._remote._trace('transactionmanager: update_pending:', pending.tx_json);
|
self._remote._trace('transactionmanager: update_pending:', pending.tx_json);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -261,9 +260,6 @@ TransactionManager.prototype._resubmit = function(ledgers, pending) {
|
|||||||
this._waitLedgers(ledgers, resubmitTransactions);
|
this._waitLedgers(ledgers, resubmitTransactions);
|
||||||
};
|
};
|
||||||
|
|
||||||
TransactionManager.prototype._selectServer = function() {
|
|
||||||
};
|
|
||||||
|
|
||||||
TransactionManager.prototype._waitLedgers = function(ledgers, callback) {
|
TransactionManager.prototype._waitLedgers = function(ledgers, callback) {
|
||||||
if (ledgers < 1) {
|
if (ledgers < 1) {
|
||||||
return callback();
|
return callback();
|
||||||
|
|||||||
Reference in New Issue
Block a user