Merge pull request #1717 from OttoAllmendinger/use-writeInt32

fix(transaction): use writeInt32 to write version in hashForWitnessV0
This commit is contained in:
Jonathan Underwood 2021-08-18 16:08:35 +09:00 committed by GitHub
commit 7b753caad6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View file

@ -316,7 +316,7 @@ class Transaction {
tbuffer = Buffer.allocUnsafe(156 + varSliceSize(prevOutScript)); tbuffer = Buffer.allocUnsafe(156 + varSliceSize(prevOutScript));
bufferWriter = new bufferutils_1.BufferWriter(tbuffer, 0); bufferWriter = new bufferutils_1.BufferWriter(tbuffer, 0);
const input = this.ins[inIndex]; const input = this.ins[inIndex];
bufferWriter.writeUInt32(this.version); bufferWriter.writeInt32(this.version);
bufferWriter.writeSlice(hashPrevouts); bufferWriter.writeSlice(hashPrevouts);
bufferWriter.writeSlice(hashSequence); bufferWriter.writeSlice(hashSequence);
bufferWriter.writeSlice(input.hash); bufferWriter.writeSlice(input.hash);

View file

@ -214,6 +214,16 @@ describe('Bitcoin-core', () => {
(hash.reverse() as Buffer).toString('hex'), (hash.reverse() as Buffer).toString('hex'),
expectedHash, expectedHash,
); );
assert.doesNotThrow(() =>
transaction.hashForWitnessV0(
inIndex,
script,
0,
// convert to UInt32
hashType < 0 ? 0x100000000 + hashType : hashType,
),
);
}, },
); );
}); });

View file

@ -416,7 +416,7 @@ export class Transaction {
bufferWriter = new BufferWriter(tbuffer, 0); bufferWriter = new BufferWriter(tbuffer, 0);
const input = this.ins[inIndex]; const input = this.ins[inIndex];
bufferWriter.writeUInt32(this.version); bufferWriter.writeInt32(this.version);
bufferWriter.writeSlice(hashPrevouts); bufferWriter.writeSlice(hashPrevouts);
bufferWriter.writeSlice(hashSequence); bufferWriter.writeSlice(hashSequence);
bufferWriter.writeSlice(input.hash); bufferWriter.writeSlice(input.hash);