allow configuration of fee per kb
This commit is contained in:
parent
d9d5a26085
commit
0e6aec1c94
|
@ -634,6 +634,21 @@ Transaction.prototype.fee = function(amount) {
|
|||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Manually set the fee per KB for this transaction. Beware that this resets all the signatures
|
||||
* for inputs (in further versions, SIGHASH_SINGLE or SIGHASH_NONE signatures will not
|
||||
* be reset).
|
||||
*
|
||||
* @param {number} amount satoshis per KB to be sent
|
||||
* @return {Transaction} this, for chaining
|
||||
*/
|
||||
Transaction.prototype.feePerKb = function(amount) {
|
||||
$.checkArgument(_.isNumber(amount), 'amount must be a number');
|
||||
this._feePerKb = amount;
|
||||
this._updateChangeOutput();
|
||||
return this;
|
||||
};
|
||||
|
||||
/* Output management */
|
||||
|
||||
/**
|
||||
|
@ -831,7 +846,7 @@ Transaction.prototype.getFee = function() {
|
|||
Transaction.prototype._estimateFee = function() {
|
||||
var estimatedSize = this._estimateSize();
|
||||
var available = this._getUnspentValue();
|
||||
return Transaction._estimateFee(estimatedSize, available);
|
||||
return Transaction._estimateFee(estimatedSize, available, this._feePerKb);
|
||||
};
|
||||
|
||||
Transaction.prototype._getUnspentValue = function() {
|
||||
|
@ -844,12 +859,12 @@ Transaction.prototype._clearSignatures = function() {
|
|||
});
|
||||
};
|
||||
|
||||
Transaction._estimateFee = function(size, amountAvailable) {
|
||||
var fee = Math.ceil(size / 1000) * Transaction.FEE_PER_KB;
|
||||
Transaction._estimateFee = function(size, amountAvailable, feePerKb) {
|
||||
var fee = Math.ceil(size / 1000) * (feePerKb || Transaction.FEE_PER_KB);
|
||||
if (amountAvailable > fee) {
|
||||
size += Transaction.CHANGE_OUTPUT_MAX_SIZE;
|
||||
}
|
||||
return Math.ceil(size / 1000) * Transaction.FEE_PER_KB;
|
||||
return Math.ceil(size / 1000) * (feePerKb || Transaction.FEE_PER_KB);
|
||||
};
|
||||
|
||||
Transaction.prototype._estimateSize = function() {
|
||||
|
|
Loading…
Reference in New Issue