Browse Source

Rename __hasWitnesses -> hasWitnesses, and add tests

hk-custom-address
Thomas Kerin 8 years ago
committed by Daniel Cousens
parent
commit
bec7f690ce
  1. 8
      src/transaction.js
  2. 8
      test/transaction.js

8
src/transaction.js

@ -125,7 +125,7 @@ Transaction.fromBuffer = function (buffer, __noStrict) {
}
// was this pointless?
if (!tx.__hasWitnesses()) throw new Error('Transaction has superfluous witness data')
if (!tx.hasWitnesses()) throw new Error('Transaction has superfluous witness data')
}
tx.locktime = readUInt32()
@ -184,7 +184,7 @@ Transaction.prototype.addOutput = function (scriptPubKey, value) {
}) - 1)
}
Transaction.prototype.__hasWitnesses = function () {
Transaction.prototype.hasWitnesses = function () {
return this.ins.some(function (x) {
return x.witness.length !== 0
})
@ -195,7 +195,7 @@ Transaction.prototype.byteLength = function () {
}
Transaction.prototype.__byteLength = function (__allowWitness) {
var hasWitnesses = __allowWitness && this.__hasWitnesses()
var hasWitnesses = __allowWitness && this.hasWitnesses()
return (
(hasWitnesses ? 10 : 8) +
@ -417,7 +417,7 @@ Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitne
writeInt32(this.version)
var hasWitnesses = __allowWitness && this.__hasWitnesses()
var hasWitnesses = __allowWitness && this.hasWitnesses()
if (hasWitnesses) {
writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)

8
test/transaction.js

@ -119,6 +119,14 @@ describe('Transaction', function () {
})
})
describe('hasWitnesses', function () {
fixtures.valid.forEach(function (f) {
it('detects if the transaction has witnesses: ' + (f.whex ? 'true' : 'false'), function () {
assert.strictEqual(Transaction.fromHex(f.whex ? f.whex : f.hex).hasWitnesses(), !!f.whex)
})
})
})
describe('addInput', function () {
var prevTxHash
beforeEach(function () {

Loading…
Cancel
Save