Skip to content

Commit 9b22f27

Browse files
committed
[FEATURE] allow per transaction fees to be set
1 parent 0835de9 commit 9b22f27

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/js/ripple/transaction.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ Transaction.prototype.lastLedger = function(sequence) {
612612

613613
/**
614614
* Set max fee. Submission will abort if this is exceeded. Specified fee must
615-
* be >= 0
615+
* be >= 0.
616616
*
617617
* @param {Number} fee The proposed fee
618618
*/
@@ -625,6 +625,23 @@ Transaction.prototype.maxFee = function(fee) {
625625
return this;
626626
};
627627

628+
/*
629+
* Set the fee user will pay to the network for submitting this transaction.
630+
* Specified fee must be >= 0.
631+
*
632+
* @param {Number} fee The proposed fee
633+
*
634+
* @returns {Transaction} calling instance for chaining
635+
*/
636+
Transaction.prototype.setFixedFee = function(fee) {
637+
if (typeof fee === 'number' && fee >= 0) {
638+
this._setFixedFee = true;
639+
this.tx_json.Fee = String(fee);
640+
}
641+
642+
return this;
643+
};
644+
628645
/**
629646
* Filter invalid properties from path objects in a path array
630647
*

src/js/ripple/transactionmanager.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ TransactionManager.prototype._adjustFees = function() {
200200
};
201201

202202
this._pending.forEach(function(transaction) {
203+
if (transaction._setFixedFee === true) {
204+
return;
205+
}
206+
203207
var oldFee = transaction.tx_json.Fee;
204208
var newFee = transaction._computeFee();
205209

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

242-
this._pending.forEach(function(transaction) {
246+
this._pending.forEach(function(transaction) {
243247
switch (ledger.ledger_index - transaction.submitIndex) {
244248
case 4:
245249
transaction.emit('missing', ledger);

test/transaction-test.js

+17
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,23 @@ describe('Transaction', function() {
828828
assert.strictEqual(transaction._setMaxFee, true);
829829
});
830830

831+
it('Set Fixed Fee', function() {
832+
var transaction = new Transaction();
833+
834+
transaction.setFixedFee('a');
835+
assert(!transaction._setFixedFee);
836+
837+
transaction.setFixedFee(-1000);
838+
assert(!transaction._setFixedFee);
839+
840+
transaction.setFixedFee(NaN);
841+
assert(!transaction._setFixedFee);
842+
843+
transaction.setFixedFee(1000);
844+
assert.strictEqual(transaction._setFixedFee, true);
845+
assert.strictEqual(transaction.tx_json.Fee, '1000');
846+
});
847+
831848
it('Rewrite transaction path', function() {
832849
var transaction = new Transaction();
833850

0 commit comments

Comments
 (0)