Skip to content

Commit 7b753ca

Browse files
authored
Merge pull request #1717 from OttoAllmendinger/use-writeInt32
fix(transaction): use writeInt32 to write version in hashForWitnessV0
2 parents 27a840a + 6b71eb0 commit 7b753ca

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/transaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class Transaction {
316316
tbuffer = Buffer.allocUnsafe(156 + varSliceSize(prevOutScript));
317317
bufferWriter = new bufferutils_1.BufferWriter(tbuffer, 0);
318318
const input = this.ins[inIndex];
319-
bufferWriter.writeUInt32(this.version);
319+
bufferWriter.writeInt32(this.version);
320320
bufferWriter.writeSlice(hashPrevouts);
321321
bufferWriter.writeSlice(hashSequence);
322322
bufferWriter.writeSlice(input.hash);

test/bitcoin.core.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ describe('Bitcoin-core', () => {
214214
(hash.reverse() as Buffer).toString('hex'),
215215
expectedHash,
216216
);
217+
218+
assert.doesNotThrow(() =>
219+
transaction.hashForWitnessV0(
220+
inIndex,
221+
script,
222+
0,
223+
// convert to UInt32
224+
hashType < 0 ? 0x100000000 + hashType : hashType,
225+
),
226+
);
217227
},
218228
);
219229
});

ts_src/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export class Transaction {
416416
bufferWriter = new BufferWriter(tbuffer, 0);
417417

418418
const input = this.ins[inIndex];
419-
bufferWriter.writeUInt32(this.version);
419+
bufferWriter.writeInt32(this.version);
420420
bufferWriter.writeSlice(hashPrevouts);
421421
bufferWriter.writeSlice(hashSequence);
422422
bufferWriter.writeSlice(input.hash);

0 commit comments

Comments
 (0)