[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 * Set max fee. Submission will abort if this is exceeded. Specified fee must
* be >= 0 * be >= 0.
* *
* @param {Number} fee The proposed fee * @param {Number} fee The proposed fee
*/ */
@@ -625,6 +625,23 @@ Transaction.prototype.maxFee = function(fee) {
return this; 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 * 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) { this._pending.forEach(function(transaction) {
if (transaction._setFixedFee === true) {
return;
}
var oldFee = transaction.tx_json.Fee; var oldFee = transaction.tx_json.Fee;
var newFee = transaction._computeFee(); var newFee = transaction._computeFee();
@@ -239,7 +243,7 @@ TransactionManager.prototype._updatePendingStatus = function(ledger) {
assert.strictEqual(typeof ledger, 'object'); assert.strictEqual(typeof ledger, 'object');
assert.strictEqual(typeof ledger.ledger_index, 'number'); assert.strictEqual(typeof ledger.ledger_index, 'number');
this._pending.forEach(function(transaction) { this._pending.forEach(function(transaction) {
switch (ledger.ledger_index - transaction.submitIndex) { switch (ledger.ledger_index - transaction.submitIndex) {
case 4: case 4:
transaction.emit('missing', ledger); transaction.emit('missing', ledger);

View File

@@ -828,6 +828,23 @@ describe('Transaction', function() {
assert.strictEqual(transaction._setMaxFee, true); 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() { it('Rewrite transaction path', function() {
var transaction = new Transaction(); var transaction = new Transaction();