mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
[FEATURE] allow per transaction fees to be set
This commit is contained in:
@@ -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
|
||||
*/
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user