Skip to content

Commit 24587fa

Browse files
committed
[FEATURE] set max fee the submitter of a transaction is willing to pay
1 parent 0248475 commit 24587fa

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/js/ripple/transaction.js

+18
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,24 @@ Transaction.prototype.lastLedger = function(sequence) {
491491
return this;
492492
};
493493

494+
/*
495+
* Set the transaction's proposed fee. No op when fee parameter
496+
* is not 0 or a positive number
497+
*
498+
* @param {Number} fee The proposed fee
499+
*
500+
* @returns {Transaction} calling instance for chaining
501+
*/
502+
Transaction.prototype.maxFee = function(fee) {
503+
if (typeof fee === 'number' && fee >= 0) {
504+
this._setMaxFee = true;
505+
this.tx_json.Fee = String(fee);
506+
this._maxFee = fee;
507+
}
508+
509+
return this;
510+
};
511+
494512
Transaction._pathRewrite = function(path) {
495513
if (!Array.isArray(path)) {
496514
return;

test/transaction-test.js

+17
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,23 @@ describe('Transaction', function() {
835835
assert(transaction._setLastLedger);
836836
});
837837

838+
it('Set Max Fee', function() {
839+
var transaction = new Transaction();
840+
841+
transaction.maxFee('a');
842+
assert.strictEqual(transaction.tx_json.Fee, void(0));
843+
assert(!transaction._setLastLedger);
844+
845+
transaction.maxFee(NaN);
846+
assert.strictEqual(transaction.tx_json.Fee, void(0));
847+
assert(!transaction._setLastLedger);
848+
849+
transaction.maxFee(1000);
850+
assert.strictEqual(transaction.tx_json.Fee, '1000');
851+
assert.strictEqual(transaction._maxFee, 1000);
852+
assert.strictEqual(transaction._setMaxFee, true);
853+
});
854+
838855
it('Rewrite transaction path', function() {
839856
var transaction = new Transaction();
840857

0 commit comments

Comments
 (0)