[FEATURE] allow per transaction fees to be set

This commit is contained in:
Bo Chen
2014-12-09 14:11:19 -08:00
parent 0835de983b
commit 9b22f279bc
3 changed files with 40 additions and 2 deletions

View File

@@ -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
*

View File

@@ -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();

View File

@@ -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();