Skip to content

Commit bec7f69

Browse files
afk11dcousens
authored andcommitted
Rename __hasWitnesses -> hasWitnesses, and add tests
1 parent e92ac1d commit bec7f69

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/transaction.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Transaction.fromBuffer = function (buffer, __noStrict) {
125125
}
126126

127127
// was this pointless?
128-
if (!tx.__hasWitnesses()) throw new Error('Transaction has superfluous witness data')
128+
if (!tx.hasWitnesses()) throw new Error('Transaction has superfluous witness data')
129129
}
130130

131131
tx.locktime = readUInt32()
@@ -184,7 +184,7 @@ Transaction.prototype.addOutput = function (scriptPubKey, value) {
184184
}) - 1)
185185
}
186186

187-
Transaction.prototype.__hasWitnesses = function () {
187+
Transaction.prototype.hasWitnesses = function () {
188188
return this.ins.some(function (x) {
189189
return x.witness.length !== 0
190190
})
@@ -195,7 +195,7 @@ Transaction.prototype.byteLength = function () {
195195
}
196196

197197
Transaction.prototype.__byteLength = function (__allowWitness) {
198-
var hasWitnesses = __allowWitness && this.__hasWitnesses()
198+
var hasWitnesses = __allowWitness && this.hasWitnesses()
199199

200200
return (
201201
(hasWitnesses ? 10 : 8) +
@@ -417,7 +417,7 @@ Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitne
417417

418418
writeInt32(this.version)
419419

420-
var hasWitnesses = __allowWitness && this.__hasWitnesses()
420+
var hasWitnesses = __allowWitness && this.hasWitnesses()
421421

422422
if (hasWitnesses) {
423423
writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)

test/transaction.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ describe('Transaction', function () {
119119
})
120120
})
121121

122+
describe('hasWitnesses', function () {
123+
fixtures.valid.forEach(function (f) {
124+
it('detects if the transaction has witnesses: ' + (f.whex ? 'true' : 'false'), function () {
125+
assert.strictEqual(Transaction.fromHex(f.whex ? f.whex : f.hex).hasWitnesses(), !!f.whex)
126+
})
127+
})
128+
})
129+
122130
describe('addInput', function () {
123131
var prevTxHash
124132
beforeEach(function () {

0 commit comments

Comments
 (0)