comments. refactor.

This commit is contained in:
Christopher Jeffrey 2016-05-14 14:53:40 -07:00
parent 31c4b4622a
commit d68509da1d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 23 additions and 3 deletions

View File

@ -10,6 +10,7 @@ var bn = require('bn.js');
var utils = require('./utils');
var assert = utils.assert;
var BufferWriter = require('./writer');
var Framer = bcoin.protocol.framer;
/**
* Represents a transaction output.
@ -152,8 +153,14 @@ Output.prototype.toJSON = function toJSON() {
};
};
/**
* Calculate the dust threshold for this
* output, based on serialize size and rate.
* @param {Number?} rate
* @returns {BN}
*/
Output.prototype.getDustThreshold = function getDustThreshold(rate) {
var framer = bcoin.protocol.framer;
var size;
if (rate == null)
@ -162,12 +169,18 @@ Output.prototype.getDustThreshold = function getDustThreshold(rate) {
if (this.script.isUnspendable())
return new bn(0);
size = framer.output(this, new BufferWriter()).written;
size = Framer.output(this, new BufferWriter()).written;
size += 148;
return bcoin.tx.getMinFee(size, rate).muln(3);
};
/**
* Test whether the output should be considered dust.
* @param {Number?} rate
* @returns {Boolean}
*/
Output.prototype.isDust = function isDust(rate) {
return this.value.cmp(this.getDustThreshold(rate)) < 0;
};
@ -203,7 +216,7 @@ Output.fromJSON = function fromJSON(json) {
*/
Output.prototype.toRaw = function toRaw(enc) {
var data = bcoin.protocol.framer.output(this);
var data = Framer.output(this);
if (enc === 'hex')
data = data.toString('hex');

View File

@ -1470,6 +1470,13 @@ TX.prototype.getMinFee = function getMinFee(size, rate) {
return TX.getMinFee(size, rate);
};
/**
* Calculate minimum fee based on rate and size.
* @param {Number?} size
* @param {Number?} rate - Rate of satoshi per kB.
* @returns {BN} fee
*/
TX.getMinFee = function getMinFee(size, rate) {
var fee;