Skip to content

Commit 32e08aa

Browse files
authored
Merge pull request #2170 from JacksonDMiller/JacksonDMiller-addStripWitnessToTransactionMaster
Add stripWitness to Transaction Issue 2169
2 parents 34e1644 + 1538f8c commit 32e08aa

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

src/cjs/transaction.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ class Transaction {
203203
return x.witness.length !== 0;
204204
});
205205
}
206+
stripWitnesses() {
207+
this.ins.forEach(input => {
208+
input.witness = EMPTY_WITNESS; // Set witness data to an empty array
209+
});
210+
}
206211
weight() {
207212
const base = this.byteLength(false);
208213
const total = this.byteLength(true);

src/cjs/transaction.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export declare class Transaction {
3434
addInput(hash: Uint8Array, index: number, sequence?: number, scriptSig?: Uint8Array): number;
3535
addOutput(scriptPubKey: Uint8Array, value: bigint): number;
3636
hasWitnesses(): boolean;
37+
stripWitnesses(): void;
3738
weight(): number;
3839
virtualSize(): number;
3940
byteLength(_ALLOW_WITNESS?: boolean): number;

src/esm/transaction.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ export class Transaction {
161161
return x.witness.length !== 0;
162162
});
163163
}
164+
stripWitnesses() {
165+
this.ins.forEach(input => {
166+
input.witness = EMPTY_WITNESS; // Set witness data to an empty array
167+
});
168+
}
164169
weight() {
165170
const base = this.byteLength(false);
166171
const total = this.byteLength(true);

test/transaction.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ describe('Transaction', () => {
135135
});
136136
});
137137

138+
describe('stripWitnesses', () => {
139+
fixtures.valid.forEach(f => {
140+
it('removes witness from the transaction if it exists', () => {
141+
const T = Transaction.fromHex(f.whex ? f.whex : f.hex);
142+
T.stripWitnesses();
143+
assert.strictEqual(T.hasWitnesses(), false);
144+
});
145+
});
146+
});
147+
138148
describe('weight/virtualSize', () => {
139149
it('computes virtual size', () => {
140150
fixtures.valid.forEach(f => {

ts_src/transaction.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ export class Transaction {
208208
});
209209
}
210210

211+
stripWitnesses(): void {
212+
this.ins.forEach(input => {
213+
input.witness = EMPTY_WITNESS; // Set witness data to an empty array
214+
});
215+
}
216+
211217
weight(): number {
212218
const base = this.byteLength(false);
213219
const total = this.byteLength(true);

0 commit comments

Comments
 (0)