Skip to content

Commit

Permalink
fix: weight calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nesopie committed Mar 27, 2024
1 parent 30e1234 commit b1eb1a3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/features/transaction/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Transaction {
locktime: number;
vin: Input[] = [];
vout: Output[] = [];
isWitnessTx = false;
isSegwit = false;

constructor(version: number, locktime: number) {
this.version = version;
Expand All @@ -27,7 +27,7 @@ export class Transaction {

addInput(input: Input) {
this.resetState();
if (input.witness && input.witness.length > 0) this.isWitnessTx = true;
if (input.witness && input.witness.length > 0) this.isSegwit = true;
this.vin.push(input);
}

Expand Down Expand Up @@ -84,7 +84,7 @@ export class Transaction {
}

get wtxid() {
if (!this.isWitnessTx) return this.txid;
if (!this.isSegwit) return this.txid;
if (this._wtxid) return this._wtxid;
const wtxid = reversify(sha256(sha256(this.serializedWTx)));
this._wtxid = wtxid;
Expand All @@ -93,7 +93,7 @@ export class Transaction {

get weight() {
if (this._weight) return this._weight;
const weight = calculateWeight(this);
const weight = calculateWeight(this, this.isSegwit);
this._weight = weight;
return this._weight;
}
Expand Down
3 changes: 0 additions & 3 deletions src/features/transactionHex.ts

This file was deleted.

0 comments on commit b1eb1a3

Please sign in to comment.