comments. refactor.
This commit is contained in:
parent
31c4b4622a
commit
d68509da1d
@ -10,6 +10,7 @@ var bn = require('bn.js');
|
|||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var BufferWriter = require('./writer');
|
var BufferWriter = require('./writer');
|
||||||
|
var Framer = bcoin.protocol.framer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a transaction output.
|
* 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) {
|
Output.prototype.getDustThreshold = function getDustThreshold(rate) {
|
||||||
var framer = bcoin.protocol.framer;
|
|
||||||
var size;
|
var size;
|
||||||
|
|
||||||
if (rate == null)
|
if (rate == null)
|
||||||
@ -162,12 +169,18 @@ Output.prototype.getDustThreshold = function getDustThreshold(rate) {
|
|||||||
if (this.script.isUnspendable())
|
if (this.script.isUnspendable())
|
||||||
return new bn(0);
|
return new bn(0);
|
||||||
|
|
||||||
size = framer.output(this, new BufferWriter()).written;
|
size = Framer.output(this, new BufferWriter()).written;
|
||||||
size += 148;
|
size += 148;
|
||||||
|
|
||||||
return bcoin.tx.getMinFee(size, rate).muln(3);
|
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) {
|
Output.prototype.isDust = function isDust(rate) {
|
||||||
return this.value.cmp(this.getDustThreshold(rate)) < 0;
|
return this.value.cmp(this.getDustThreshold(rate)) < 0;
|
||||||
};
|
};
|
||||||
@ -203,7 +216,7 @@ Output.fromJSON = function fromJSON(json) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Output.prototype.toRaw = function toRaw(enc) {
|
Output.prototype.toRaw = function toRaw(enc) {
|
||||||
var data = bcoin.protocol.framer.output(this);
|
var data = Framer.output(this);
|
||||||
|
|
||||||
if (enc === 'hex')
|
if (enc === 'hex')
|
||||||
data = data.toString('hex');
|
data = data.toString('hex');
|
||||||
|
|||||||
@ -1470,6 +1470,13 @@ TX.prototype.getMinFee = function getMinFee(size, rate) {
|
|||||||
return TX.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) {
|
TX.getMinFee = function getMinFee(size, rate) {
|
||||||
var fee;
|
var fee;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user