Skip to content

Commit

Permalink
[FEATURE] allow per transaction fees to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbag committed Dec 10, 2014
1 parent 0835de9 commit 9b22f27
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/js/ripple/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ Transaction.prototype.lastLedger = function(sequence) {

/**
* Set max fee. Submission will abort if this is exceeded. Specified fee must
* be >= 0
* be >= 0.
*
* @param {Number} fee The proposed fee
*/
Expand All @@ -625,6 +625,23 @@ Transaction.prototype.maxFee = function(fee) {
return this;
};

/*
* Set the fee user will pay to the network for submitting this transaction.
* Specified fee must be >= 0.
*
* @param {Number} fee The proposed fee
*
* @returns {Transaction} calling instance for chaining
*/
Transaction.prototype.setFixedFee = function(fee) {
if (typeof fee === 'number' && fee >= 0) {
this._setFixedFee = true;
this.tx_json.Fee = String(fee);
}

return this;
};

/**
* Filter invalid properties from path objects in a path array
*
Expand Down
6 changes: 5 additions & 1 deletion src/js/ripple/transactionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ TransactionManager.prototype._adjustFees = function() {
};

this._pending.forEach(function(transaction) {
if (transaction._setFixedFee === true) {
return;
}

var oldFee = transaction.tx_json.Fee;
var newFee = transaction._computeFee();

Expand Down Expand Up @@ -239,7 +243,7 @@ TransactionManager.prototype._updatePendingStatus = function(ledger) {
assert.strictEqual(typeof ledger, 'object');
assert.strictEqual(typeof ledger.ledger_index, 'number');

this._pending.forEach(function(transaction) {
this._pending.forEach(function(transaction) {
switch (ledger.ledger_index - transaction.submitIndex) {
case 4:
transaction.emit('missing', ledger);
Expand Down
17 changes: 17 additions & 0 deletions test/transaction-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,23 @@ describe('Transaction', function() {
assert.strictEqual(transaction._setMaxFee, true);
});

it('Set Fixed Fee', function() {
var transaction = new Transaction();

transaction.setFixedFee('a');
assert(!transaction._setFixedFee);

transaction.setFixedFee(-1000);
assert(!transaction._setFixedFee);

transaction.setFixedFee(NaN);
assert(!transaction._setFixedFee);

transaction.setFixedFee(1000);
assert.strictEqual(transaction._setFixedFee, true);
assert.strictEqual(transaction.tx_json.Fee, '1000');
});

it('Rewrite transaction path', function() {
var transaction = new Transaction();

Expand Down

0 comments on commit 9b22f27

Please sign in to comment.