diff --git a/src/js/ripple/transaction.js b/src/js/ripple/transaction.js index 9cf5537e..fcc0012c 100644 --- a/src/js/ripple/transaction.js +++ b/src/js/ripple/transaction.js @@ -281,8 +281,25 @@ Transaction.prototype._getServer = function() { Transaction.prototype.complete = function() { // Try to auto-fill the secret - if (!this._secret && !(this._secret = this._account_secret(this.tx_json.Account))) { - return this.emit('error', new RippleError('tejSecretUnknown', 'Missing secret')); + if (!this._secret && !(this._secret = this._accountSecret(this.tx_json.Account))) { + this.emit('error', new RippleError('tejSecretUnknown', 'Missing secret')); + return false; + } + + if (typeof this.tx_json.SigningPubKey === 'undefined') { + try { + var seed = Seed.from_json(this._secret); + var key = seed.get_key(this.tx_json.Account); + this.tx_json.SigningPubKey = key.to_hex_pub(); + } catch(e) { + this.emit('error', new RippleError('tejSecretInvalid', 'Invalid secret')); + return false; + } + } + + if (!this.remote.trusted && !this.remote.local_signing) { + this.emit('error', new RippleError('tejServerUntrusted', 'Attempt to give secret to untrusted server')); + return false; } // If the Fee hasn't been set, one needs to be computed by @@ -294,14 +311,9 @@ Transaction.prototype.complete = function() { } } - if (typeof this.tx_json.SigningPubKey === 'undefined') { - try { - var seed = Seed.from_json(this._secret); - var key = seed.get_key(this.tx_json.Account); - this.tx_json.SigningPubKey = key.to_hex_pub(); - } catch(e) { - return this.emit('error', new RippleError('tejSecretInvalid', 'Invalid secret')); - } + if (Number(this.tx_json.Fee) > this._maxFee) { + tx.emit('error', new RippleError('tejMaxFeeExceeded', 'Max fee exceeded')); + return false; } // Set canonical flag - this enables canonicalized signature checking diff --git a/src/js/ripple/transactionmanager.js b/src/js/ripple/transactionmanager.js index 4e484486..57637b29 100644 --- a/src/js/ripple/transactionmanager.js +++ b/src/js/ripple/transactionmanager.js @@ -184,24 +184,20 @@ TransactionManager.prototype._fillSequence = function(tx, callback) { fill.account_set(self._accountID); fill.tx_json.Sequence = sequence; fill.once('submitted', callback); + + // Secrets may be set on a per-transaction basis + if (tx._secret) { + fill.secret(tx._secret); + } + fill.submit(); }; function sequenceLoaded(err, sequence) { if (typeof sequence !== 'number') { callback(new Error('Failed to fetch account transaction sequence')); - return; - } - - var sequenceDif = tx.tx_json.Sequence - sequence; - var submitted = 0; - - for (var i=sequence; i this._maxFee) { - tx.emit('error', new RippleError('tejMaxFeeExceeded', 'Max fee exceeded')); - } else { - // ND: this is the ONLY place we put the tx into the queue. The - // TransactionQueue queue is merely a list, so any mutations to tx._hash - // will cause subsequent look ups (eg. inside 'transaction-outbound' - // validated transaction clearing) to fail. - this._pending.push(tx); - this._request(tx); - } + // ND: this is the ONLY place we put the tx into the queue. The + // TransactionQueue queue is merely a list, so any mutations to tx._hash + // will cause subsequent look ups (eg. inside 'transaction-outbound' + // validated transaction clearing) to fail. + this._pending.push(tx); + this._request(tx); }; exports.TransactionManager = TransactionManager; diff --git a/src/js/ripple/transactionqueue.js b/src/js/ripple/transactionqueue.js index 4b3758d3..b9968dd9 100644 --- a/src/js/ripple/transactionqueue.js +++ b/src/js/ripple/transactionqueue.js @@ -4,46 +4,17 @@ */ var Transaction = require('./transaction').Transaction; +var LRU = require('lru-cache'); function TransactionQueue() { var self = this; this._queue = [ ]; - this._idCache = { }; - this._sequenceCache = { }; + this._idCache = LRU({ max: 100 }); + this._sequenceCache = LRU({ max: 100 }); this._save = void(0); }; -TransactionQueue.prototype.clearCache = function() { - this._idCache = { }; - this._sequenceCache = { }; -}; - -TransactionQueue.prototype.getMinLedger = function() { - var minLedger = Infinity; - - for (var i=0; i