Skip to content

Fix tx version from int32 to uint32 #2219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cjs/transaction.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Transaction {
static fromBuffer(buffer, _NO_STRICT) {
const bufferReader = new bufferutils_js_1.BufferReader(buffer);
const tx = new Transaction();
tx.version = bufferReader.readInt32();
tx.version = bufferReader.readUInt32();
const marker = bufferReader.readUInt8();
const flag = bufferReader.readUInt8();
let hasWitnesses = false;
Expand Down Expand Up @@ -414,7 +414,7 @@ class Transaction {
const sigMsgWriter = bufferutils_js_1.BufferWriter.withCapacity(sigMsgSize);
sigMsgWriter.writeUInt8(hashType);
// Transaction
sigMsgWriter.writeInt32(this.version);
sigMsgWriter.writeUInt32(this.version);
sigMsgWriter.writeUInt32(this.locktime);
sigMsgWriter.writeSlice(hashPrevouts);
sigMsgWriter.writeSlice(hashAmounts);
Expand Down Expand Up @@ -523,7 +523,7 @@ class Transaction {
tbuffer = new Uint8Array(156 + varSliceSize(prevOutScript));
bufferWriter = new bufferutils_js_1.BufferWriter(tbuffer, 0);
const input = this.ins[inIndex];
bufferWriter.writeInt32(this.version);
bufferWriter.writeUInt32(this.version);
bufferWriter.writeSlice(hashPrevouts);
bufferWriter.writeSlice(hashSequence);
bufferWriter.writeSlice(input.hash);
Expand Down Expand Up @@ -570,7 +570,7 @@ class Transaction {
buffer,
initialOffset || 0,
);
bufferWriter.writeInt32(this.version);
bufferWriter.writeUInt32(this.version);
const hasWitnesses = _ALLOW_WITNESS && this.hasWitnesses();
if (hasWitnesses) {
bufferWriter.writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER);
Expand Down
8 changes: 4 additions & 4 deletions src/esm/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Transaction {
static fromBuffer(buffer, _NO_STRICT) {
const bufferReader = new BufferReader(buffer);
const tx = new Transaction();
tx.version = bufferReader.readInt32();
tx.version = bufferReader.readUInt32();
const marker = bufferReader.readUInt8();
const flag = bufferReader.readUInt8();
let hasWitnesses = false;
Expand Down Expand Up @@ -365,7 +365,7 @@ export class Transaction {
const sigMsgWriter = BufferWriter.withCapacity(sigMsgSize);
sigMsgWriter.writeUInt8(hashType);
// Transaction
sigMsgWriter.writeInt32(this.version);
sigMsgWriter.writeUInt32(this.version);
sigMsgWriter.writeUInt32(this.locktime);
sigMsgWriter.writeSlice(hashPrevouts);
sigMsgWriter.writeSlice(hashAmounts);
Expand Down Expand Up @@ -472,7 +472,7 @@ export class Transaction {
tbuffer = new Uint8Array(156 + varSliceSize(prevOutScript));
bufferWriter = new BufferWriter(tbuffer, 0);
const input = this.ins[inIndex];
bufferWriter.writeInt32(this.version);
bufferWriter.writeUInt32(this.version);
bufferWriter.writeSlice(hashPrevouts);
bufferWriter.writeSlice(hashSequence);
bufferWriter.writeSlice(input.hash);
Expand Down Expand Up @@ -514,7 +514,7 @@ export class Transaction {
__toBuffer(buffer, initialOffset, _ALLOW_WITNESS = false) {
if (!buffer) buffer = new Uint8Array(this.byteLength(_ALLOW_WITNESS));
const bufferWriter = new BufferWriter(buffer, initialOffset || 0);
bufferWriter.writeInt32(this.version);
bufferWriter.writeUInt32(this.version);
const hasWitnesses = _ALLOW_WITNESS && this.hasWitnesses();
if (hasWitnesses) {
bufferWriter.writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER);
Expand Down
4 changes: 2 additions & 2 deletions test/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ describe('Transaction', () => {
});
});

it('.version should be interpreted as an int32le', () => {
it('.version should be interpreted as an uint32le', () => {
const txHex = 'ffffffff0000ffffffff';
const tx = Transaction.fromHex(txHex);
assert.strictEqual(-1, tx.version);
assert.strictEqual(0xffffffff, tx.version);
assert.strictEqual(0xffffffff, tx.locktime);
});
});
Expand Down
8 changes: 4 additions & 4 deletions ts_src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Transaction {
const bufferReader = new BufferReader(buffer);

const tx = new Transaction();
tx.version = bufferReader.readInt32();
tx.version = bufferReader.readUInt32();

const marker = bufferReader.readUInt8();
const flag = bufferReader.readUInt8();
Expand Down Expand Up @@ -464,7 +464,7 @@ export class Transaction {

sigMsgWriter.writeUInt8(hashType);
// Transaction
sigMsgWriter.writeInt32(this.version);
sigMsgWriter.writeUInt32(this.version);
sigMsgWriter.writeUInt32(this.locktime);
sigMsgWriter.writeSlice(hashPrevouts);
sigMsgWriter.writeSlice(hashAmounts);
Expand Down Expand Up @@ -594,7 +594,7 @@ export class Transaction {
bufferWriter = new BufferWriter(tbuffer, 0);

const input = this.ins[inIndex];
bufferWriter.writeInt32(this.version);
bufferWriter.writeUInt32(this.version);
bufferWriter.writeSlice(hashPrevouts);
bufferWriter.writeSlice(hashSequence);
bufferWriter.writeSlice(input.hash);
Expand Down Expand Up @@ -652,7 +652,7 @@ export class Transaction {

const bufferWriter = new BufferWriter(buffer, initialOffset || 0);

bufferWriter.writeInt32(this.version);
bufferWriter.writeUInt32(this.version);

const hasWitnesses = _ALLOW_WITNESS && this.hasWitnesses();

Expand Down
Loading