networks: use byteLength over toBuffer
This commit is contained in:
parent
9cda36fc76
commit
607b3b7983
2 changed files with 5 additions and 6 deletions
|
@ -123,7 +123,7 @@ var networks = {
|
||||||
|
|
||||||
function estimateFee (tx, network) {
|
function estimateFee (tx, network) {
|
||||||
var baseFee = network.feePerKb
|
var baseFee = network.feePerKb
|
||||||
var byteSize = tx.toBuffer().length
|
var byteSize = tx.byteLength()
|
||||||
|
|
||||||
var fee = baseFee * Math.ceil(byteSize / 1000)
|
var fee = baseFee * Math.ceil(byteSize / 1000)
|
||||||
if (network.dustSoftThreshold === undefined) return fee
|
if (network.dustSoftThreshold === undefined) return fee
|
||||||
|
|
|
@ -10,13 +10,13 @@ var Transaction = require('../src/transaction')
|
||||||
var fixtures = require('./fixtures/network')
|
var fixtures = require('./fixtures/network')
|
||||||
|
|
||||||
describe('networks', function () {
|
describe('networks', function () {
|
||||||
var txToBuffer
|
var txByteLength
|
||||||
before(function () {
|
before(function () {
|
||||||
txToBuffer = sinon.stub(Transaction.prototype, 'toBuffer')
|
txByteLength = sinon.stub(Transaction.prototype, 'byteLength')
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
Transaction.prototype.toBuffer.restore()
|
Transaction.prototype.byteLength.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('constants', function () {
|
describe('constants', function () {
|
||||||
|
@ -39,8 +39,7 @@ describe('networks', function () {
|
||||||
var network = networks[f.network]
|
var network = networks[f.network]
|
||||||
|
|
||||||
it('calculates the fee correctly for ' + f.description, function () {
|
it('calculates the fee correctly for ' + f.description, function () {
|
||||||
var buffer = new Buffer(f.txSize)
|
txByteLength.returns(f.txSize)
|
||||||
txToBuffer.returns(buffer)
|
|
||||||
|
|
||||||
var estimateFee = network.estimateFee
|
var estimateFee = network.estimateFee
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
|
|
Loading…
Reference in a new issue