mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
[FEATURE] set max fee the submitter of a transaction is willing to pay
This commit is contained in:
@@ -491,6 +491,24 @@ Transaction.prototype.lastLedger = function(sequence) {
|
||||
return this;
|
||||
};
|
||||
|
||||
/*
|
||||
* Set the transaction's proposed fee. No op when fee parameter
|
||||
* is not 0 or a positive number
|
||||
*
|
||||
* @param {Number} fee The proposed fee
|
||||
*
|
||||
* @returns {Transaction} calling instance for chaining
|
||||
*/
|
||||
Transaction.prototype.maxFee = function(fee) {
|
||||
if (typeof fee === 'number' && fee >= 0) {
|
||||
this._setMaxFee = true;
|
||||
this.tx_json.Fee = String(fee);
|
||||
this._maxFee = fee;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Transaction._pathRewrite = function(path) {
|
||||
if (!Array.isArray(path)) {
|
||||
return;
|
||||
|
||||
@@ -835,6 +835,23 @@ describe('Transaction', function() {
|
||||
assert(transaction._setLastLedger);
|
||||
});
|
||||
|
||||
it('Set Max Fee', function() {
|
||||
var transaction = new Transaction();
|
||||
|
||||
transaction.maxFee('a');
|
||||
assert.strictEqual(transaction.tx_json.Fee, void(0));
|
||||
assert(!transaction._setLastLedger);
|
||||
|
||||
transaction.maxFee(NaN);
|
||||
assert.strictEqual(transaction.tx_json.Fee, void(0));
|
||||
assert(!transaction._setLastLedger);
|
||||
|
||||
transaction.maxFee(1000);
|
||||
assert.strictEqual(transaction.tx_json.Fee, '1000');
|
||||
assert.strictEqual(transaction._maxFee, 1000);
|
||||
assert.strictEqual(transaction._setMaxFee, true);
|
||||
});
|
||||
|
||||
it('Rewrite transaction path', function() {
|
||||
var transaction = new Transaction();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user