Skip to content

Commit 14d10c7

Browse files
committed
Remove VSize, can get from Transaction
1 parent 139197e commit 14d10c7

File tree

4 files changed

+1
-35
lines changed

4 files changed

+1
-35
lines changed

src/psbt.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ class Psbt {
154154
addNonWitnessTxCache(this.__CACHE, input, inputIndex);
155155
}
156156
c.__FEE = undefined;
157-
c.__VSIZE = undefined;
158157
c.__FEE_RATE = undefined;
159158
c.__EXTRACTED_TX = undefined;
160159
return this;
@@ -174,7 +173,6 @@ class Psbt {
174173
const c = this.__CACHE;
175174
this.data.addOutput(outputData);
176175
c.__FEE = undefined;
177-
c.__VSIZE = undefined;
178176
c.__FEE_RATE = undefined;
179177
c.__EXTRACTED_TX = undefined;
180178
return this;
@@ -201,14 +199,6 @@ class Psbt {
201199
getFee() {
202200
return getTxCacheValue('__FEE', 'fee', this.data.inputs, this.__CACHE);
203201
}
204-
getVSize() {
205-
return getTxCacheValue(
206-
'__VSIZE',
207-
'virtual size',
208-
this.data.inputs,
209-
this.__CACHE,
210-
);
211-
}
212202
finalizeAllInputs() {
213203
utils_1.checkForInput(this.data.inputs, 0); // making sure we have at least one
214204
range(this.data.inputs.length).forEach(idx => this.finalizeInput(idx));
@@ -736,7 +726,6 @@ function getTxCacheValue(key, name, inputs, c) {
736726
throw new Error(`PSBT must be finalized to calculate ${name}`);
737727
if (key === '__FEE_RATE' && c.__FEE_RATE) return c.__FEE_RATE;
738728
if (key === '__FEE' && c.__FEE) return c.__FEE;
739-
if (key === '__VSIZE' && c.__VSIZE) return c.__VSIZE;
740729
let tx;
741730
let mustFinalize = true;
742731
if (c.__EXTRACTED_TX) {
@@ -748,7 +737,6 @@ function getTxCacheValue(key, name, inputs, c) {
748737
inputFinalizeGetAmts(inputs, tx, c, mustFinalize);
749738
if (key === '__FEE_RATE') return c.__FEE_RATE;
750739
else if (key === '__FEE') return c.__FEE;
751-
else if (key === '__VSIZE') return c.__VSIZE;
752740
}
753741
function getFinalScripts(
754742
script,
@@ -1150,7 +1138,6 @@ function inputFinalizeGetAmts(inputs, tx, cache, mustFinalize) {
11501138
throw new Error('Outputs are spending more than Inputs');
11511139
}
11521140
const bytes = tx.virtualSize();
1153-
cache.__VSIZE = bytes;
11541141
cache.__FEE = fee;
11551142
cache.__EXTRACTED_TX = tx;
11561143
cache.__FEE_RATE = Math.floor(fee / bytes);

test/psbt.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ describe(`Psbt`, () => {
154154
const f1 = psbt6.getFee()
155155
const f2 = psbt6.getFee()
156156
assert.strictEqual(f1, f2)
157-
158-
const psbt7 = Psbt.fromBase64(f.psbt)
159-
const vs1 = psbt7.getVSize()
160-
const vs2 = psbt7.getVSize()
161-
assert.strictEqual(vs1, vs2)
162157
})
163158
})
164159
})

ts_src/psbt.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ export class Psbt {
195195
addNonWitnessTxCache(this.__CACHE, input, inputIndex);
196196
}
197197
c.__FEE = undefined;
198-
c.__VSIZE = undefined;
199198
c.__FEE_RATE = undefined;
200199
c.__EXTRACTED_TX = undefined;
201200
return this;
@@ -217,7 +216,6 @@ export class Psbt {
217216
const c = this.__CACHE;
218217
this.data.addOutput(outputData);
219218
c.__FEE = undefined;
220-
c.__VSIZE = undefined;
221219
c.__FEE_RATE = undefined;
222220
c.__EXTRACTED_TX = undefined;
223221
return this;
@@ -248,15 +246,6 @@ export class Psbt {
248246
return getTxCacheValue('__FEE', 'fee', this.data.inputs, this.__CACHE)!;
249247
}
250248

251-
getVSize(): number {
252-
return getTxCacheValue(
253-
'__VSIZE',
254-
'virtual size',
255-
this.data.inputs,
256-
this.__CACHE,
257-
)!;
258-
}
259-
260249
finalizeAllInputs(): this {
261250
checkForInput(this.data.inputs, 0); // making sure we have at least one
262251
range(this.data.inputs.length).forEach(idx => this.finalizeInput(idx));
@@ -620,7 +609,6 @@ interface PsbtCache {
620609
__TX: Transaction;
621610
__FEE_RATE?: number;
622611
__FEE?: number;
623-
__VSIZE?: number;
624612
__EXTRACTED_TX?: Transaction;
625613
}
626614

@@ -931,7 +919,7 @@ const checkWitnessScript = scriptCheckerFactory(
931919
'Witness script',
932920
);
933921

934-
type TxCacheNumberKey = '__FEE_RATE' | '__FEE' | '__VSIZE';
922+
type TxCacheNumberKey = '__FEE_RATE' | '__FEE';
935923
function getTxCacheValue(
936924
key: TxCacheNumberKey,
937925
name: string,
@@ -942,7 +930,6 @@ function getTxCacheValue(
942930
throw new Error(`PSBT must be finalized to calculate ${name}`);
943931
if (key === '__FEE_RATE' && c.__FEE_RATE) return c.__FEE_RATE;
944932
if (key === '__FEE' && c.__FEE) return c.__FEE;
945-
if (key === '__VSIZE' && c.__VSIZE) return c.__VSIZE;
946933
let tx: Transaction;
947934
let mustFinalize = true;
948935
if (c.__EXTRACTED_TX) {
@@ -954,7 +941,6 @@ function getTxCacheValue(
954941
inputFinalizeGetAmts(inputs, tx, c, mustFinalize);
955942
if (key === '__FEE_RATE') return c.__FEE_RATE!;
956943
else if (key === '__FEE') return c.__FEE!;
957-
else if (key === '__VSIZE') return c.__VSIZE!;
958944
}
959945

960946
function getFinalScripts(
@@ -1435,7 +1421,6 @@ function inputFinalizeGetAmts(
14351421
throw new Error('Outputs are spending more than Inputs');
14361422
}
14371423
const bytes = tx.virtualSize();
1438-
cache.__VSIZE = bytes;
14391424
cache.__FEE = fee;
14401425
cache.__EXTRACTED_TX = tx;
14411426
cache.__FEE_RATE = Math.floor(fee / bytes);

types/psbt.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export declare class Psbt {
5858
extractTransaction(disableFeeCheck?: boolean): Transaction;
5959
getFeeRate(): number;
6060
getFee(): number;
61-
getVSize(): number;
6261
finalizeAllInputs(): this;
6362
finalizeInput(inputIndex: number): this;
6463
validateSignaturesOfAllInputs(): boolean;

0 commit comments

Comments
 (0)