Rename __hasWitnesses -> hasWitnesses, and add tests
This commit is contained in:
parent
e92ac1d01b
commit
bec7f690ce
2 changed files with 12 additions and 4 deletions
|
@ -125,7 +125,7 @@ Transaction.fromBuffer = function (buffer, __noStrict) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// was this pointless?
|
// 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()
|
tx.locktime = readUInt32()
|
||||||
|
@ -184,7 +184,7 @@ Transaction.prototype.addOutput = function (scriptPubKey, value) {
|
||||||
}) - 1)
|
}) - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.__hasWitnesses = function () {
|
Transaction.prototype.hasWitnesses = function () {
|
||||||
return this.ins.some(function (x) {
|
return this.ins.some(function (x) {
|
||||||
return x.witness.length !== 0
|
return x.witness.length !== 0
|
||||||
})
|
})
|
||||||
|
@ -195,7 +195,7 @@ Transaction.prototype.byteLength = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.__byteLength = function (__allowWitness) {
|
Transaction.prototype.__byteLength = function (__allowWitness) {
|
||||||
var hasWitnesses = __allowWitness && this.__hasWitnesses()
|
var hasWitnesses = __allowWitness && this.hasWitnesses()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(hasWitnesses ? 10 : 8) +
|
(hasWitnesses ? 10 : 8) +
|
||||||
|
@ -417,7 +417,7 @@ Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitne
|
||||||
|
|
||||||
writeInt32(this.version)
|
writeInt32(this.version)
|
||||||
|
|
||||||
var hasWitnesses = __allowWitness && this.__hasWitnesses()
|
var hasWitnesses = __allowWitness && this.hasWitnesses()
|
||||||
|
|
||||||
if (hasWitnesses) {
|
if (hasWitnesses) {
|
||||||
writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)
|
writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)
|
||||||
|
|
|
@ -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 () {
|
describe('addInput', function () {
|
||||||
var prevTxHash
|
var prevTxHash
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue