Remove VSize, can get from Transaction
This commit is contained in:
parent
139197e545
commit
14d10c74a5
4 changed files with 1 additions and 35 deletions
13
src/psbt.js
13
src/psbt.js
|
@ -154,7 +154,6 @@ class Psbt {
|
||||||
addNonWitnessTxCache(this.__CACHE, input, inputIndex);
|
addNonWitnessTxCache(this.__CACHE, input, inputIndex);
|
||||||
}
|
}
|
||||||
c.__FEE = undefined;
|
c.__FEE = undefined;
|
||||||
c.__VSIZE = undefined;
|
|
||||||
c.__FEE_RATE = undefined;
|
c.__FEE_RATE = undefined;
|
||||||
c.__EXTRACTED_TX = undefined;
|
c.__EXTRACTED_TX = undefined;
|
||||||
return this;
|
return this;
|
||||||
|
@ -174,7 +173,6 @@ class Psbt {
|
||||||
const c = this.__CACHE;
|
const c = this.__CACHE;
|
||||||
this.data.addOutput(outputData);
|
this.data.addOutput(outputData);
|
||||||
c.__FEE = undefined;
|
c.__FEE = undefined;
|
||||||
c.__VSIZE = undefined;
|
|
||||||
c.__FEE_RATE = undefined;
|
c.__FEE_RATE = undefined;
|
||||||
c.__EXTRACTED_TX = undefined;
|
c.__EXTRACTED_TX = undefined;
|
||||||
return this;
|
return this;
|
||||||
|
@ -201,14 +199,6 @@ class Psbt {
|
||||||
getFee() {
|
getFee() {
|
||||||
return getTxCacheValue('__FEE', 'fee', this.data.inputs, this.__CACHE);
|
return getTxCacheValue('__FEE', 'fee', this.data.inputs, this.__CACHE);
|
||||||
}
|
}
|
||||||
getVSize() {
|
|
||||||
return getTxCacheValue(
|
|
||||||
'__VSIZE',
|
|
||||||
'virtual size',
|
|
||||||
this.data.inputs,
|
|
||||||
this.__CACHE,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
finalizeAllInputs() {
|
finalizeAllInputs() {
|
||||||
utils_1.checkForInput(this.data.inputs, 0); // making sure we have at least one
|
utils_1.checkForInput(this.data.inputs, 0); // making sure we have at least one
|
||||||
range(this.data.inputs.length).forEach(idx => this.finalizeInput(idx));
|
range(this.data.inputs.length).forEach(idx => this.finalizeInput(idx));
|
||||||
|
@ -736,7 +726,6 @@ function getTxCacheValue(key, name, inputs, c) {
|
||||||
throw new Error(`PSBT must be finalized to calculate ${name}`);
|
throw new Error(`PSBT must be finalized to calculate ${name}`);
|
||||||
if (key === '__FEE_RATE' && c.__FEE_RATE) return c.__FEE_RATE;
|
if (key === '__FEE_RATE' && c.__FEE_RATE) return c.__FEE_RATE;
|
||||||
if (key === '__FEE' && c.__FEE) return c.__FEE;
|
if (key === '__FEE' && c.__FEE) return c.__FEE;
|
||||||
if (key === '__VSIZE' && c.__VSIZE) return c.__VSIZE;
|
|
||||||
let tx;
|
let tx;
|
||||||
let mustFinalize = true;
|
let mustFinalize = true;
|
||||||
if (c.__EXTRACTED_TX) {
|
if (c.__EXTRACTED_TX) {
|
||||||
|
@ -748,7 +737,6 @@ function getTxCacheValue(key, name, inputs, c) {
|
||||||
inputFinalizeGetAmts(inputs, tx, c, mustFinalize);
|
inputFinalizeGetAmts(inputs, tx, c, mustFinalize);
|
||||||
if (key === '__FEE_RATE') return c.__FEE_RATE;
|
if (key === '__FEE_RATE') return c.__FEE_RATE;
|
||||||
else if (key === '__FEE') return c.__FEE;
|
else if (key === '__FEE') return c.__FEE;
|
||||||
else if (key === '__VSIZE') return c.__VSIZE;
|
|
||||||
}
|
}
|
||||||
function getFinalScripts(
|
function getFinalScripts(
|
||||||
script,
|
script,
|
||||||
|
@ -1150,7 +1138,6 @@ function inputFinalizeGetAmts(inputs, tx, cache, mustFinalize) {
|
||||||
throw new Error('Outputs are spending more than Inputs');
|
throw new Error('Outputs are spending more than Inputs');
|
||||||
}
|
}
|
||||||
const bytes = tx.virtualSize();
|
const bytes = tx.virtualSize();
|
||||||
cache.__VSIZE = bytes;
|
|
||||||
cache.__FEE = fee;
|
cache.__FEE = fee;
|
||||||
cache.__EXTRACTED_TX = tx;
|
cache.__EXTRACTED_TX = tx;
|
||||||
cache.__FEE_RATE = Math.floor(fee / bytes);
|
cache.__FEE_RATE = Math.floor(fee / bytes);
|
||||||
|
|
|
@ -154,11 +154,6 @@ describe(`Psbt`, () => {
|
||||||
const f1 = psbt6.getFee()
|
const f1 = psbt6.getFee()
|
||||||
const f2 = psbt6.getFee()
|
const f2 = psbt6.getFee()
|
||||||
assert.strictEqual(f1, f2)
|
assert.strictEqual(f1, f2)
|
||||||
|
|
||||||
const psbt7 = Psbt.fromBase64(f.psbt)
|
|
||||||
const vs1 = psbt7.getVSize()
|
|
||||||
const vs2 = psbt7.getVSize()
|
|
||||||
assert.strictEqual(vs1, vs2)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -195,7 +195,6 @@ export class Psbt {
|
||||||
addNonWitnessTxCache(this.__CACHE, input, inputIndex);
|
addNonWitnessTxCache(this.__CACHE, input, inputIndex);
|
||||||
}
|
}
|
||||||
c.__FEE = undefined;
|
c.__FEE = undefined;
|
||||||
c.__VSIZE = undefined;
|
|
||||||
c.__FEE_RATE = undefined;
|
c.__FEE_RATE = undefined;
|
||||||
c.__EXTRACTED_TX = undefined;
|
c.__EXTRACTED_TX = undefined;
|
||||||
return this;
|
return this;
|
||||||
|
@ -217,7 +216,6 @@ export class Psbt {
|
||||||
const c = this.__CACHE;
|
const c = this.__CACHE;
|
||||||
this.data.addOutput(outputData);
|
this.data.addOutput(outputData);
|
||||||
c.__FEE = undefined;
|
c.__FEE = undefined;
|
||||||
c.__VSIZE = undefined;
|
|
||||||
c.__FEE_RATE = undefined;
|
c.__FEE_RATE = undefined;
|
||||||
c.__EXTRACTED_TX = undefined;
|
c.__EXTRACTED_TX = undefined;
|
||||||
return this;
|
return this;
|
||||||
|
@ -248,15 +246,6 @@ export class Psbt {
|
||||||
return getTxCacheValue('__FEE', 'fee', this.data.inputs, this.__CACHE)!;
|
return getTxCacheValue('__FEE', 'fee', this.data.inputs, this.__CACHE)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
getVSize(): number {
|
|
||||||
return getTxCacheValue(
|
|
||||||
'__VSIZE',
|
|
||||||
'virtual size',
|
|
||||||
this.data.inputs,
|
|
||||||
this.__CACHE,
|
|
||||||
)!;
|
|
||||||
}
|
|
||||||
|
|
||||||
finalizeAllInputs(): this {
|
finalizeAllInputs(): this {
|
||||||
checkForInput(this.data.inputs, 0); // making sure we have at least one
|
checkForInput(this.data.inputs, 0); // making sure we have at least one
|
||||||
range(this.data.inputs.length).forEach(idx => this.finalizeInput(idx));
|
range(this.data.inputs.length).forEach(idx => this.finalizeInput(idx));
|
||||||
|
@ -620,7 +609,6 @@ interface PsbtCache {
|
||||||
__TX: Transaction;
|
__TX: Transaction;
|
||||||
__FEE_RATE?: number;
|
__FEE_RATE?: number;
|
||||||
__FEE?: number;
|
__FEE?: number;
|
||||||
__VSIZE?: number;
|
|
||||||
__EXTRACTED_TX?: Transaction;
|
__EXTRACTED_TX?: Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,7 +919,7 @@ const checkWitnessScript = scriptCheckerFactory(
|
||||||
'Witness script',
|
'Witness script',
|
||||||
);
|
);
|
||||||
|
|
||||||
type TxCacheNumberKey = '__FEE_RATE' | '__FEE' | '__VSIZE';
|
type TxCacheNumberKey = '__FEE_RATE' | '__FEE';
|
||||||
function getTxCacheValue(
|
function getTxCacheValue(
|
||||||
key: TxCacheNumberKey,
|
key: TxCacheNumberKey,
|
||||||
name: string,
|
name: string,
|
||||||
|
@ -942,7 +930,6 @@ function getTxCacheValue(
|
||||||
throw new Error(`PSBT must be finalized to calculate ${name}`);
|
throw new Error(`PSBT must be finalized to calculate ${name}`);
|
||||||
if (key === '__FEE_RATE' && c.__FEE_RATE) return c.__FEE_RATE;
|
if (key === '__FEE_RATE' && c.__FEE_RATE) return c.__FEE_RATE;
|
||||||
if (key === '__FEE' && c.__FEE) return c.__FEE;
|
if (key === '__FEE' && c.__FEE) return c.__FEE;
|
||||||
if (key === '__VSIZE' && c.__VSIZE) return c.__VSIZE;
|
|
||||||
let tx: Transaction;
|
let tx: Transaction;
|
||||||
let mustFinalize = true;
|
let mustFinalize = true;
|
||||||
if (c.__EXTRACTED_TX) {
|
if (c.__EXTRACTED_TX) {
|
||||||
|
@ -954,7 +941,6 @@ function getTxCacheValue(
|
||||||
inputFinalizeGetAmts(inputs, tx, c, mustFinalize);
|
inputFinalizeGetAmts(inputs, tx, c, mustFinalize);
|
||||||
if (key === '__FEE_RATE') return c.__FEE_RATE!;
|
if (key === '__FEE_RATE') return c.__FEE_RATE!;
|
||||||
else if (key === '__FEE') return c.__FEE!;
|
else if (key === '__FEE') return c.__FEE!;
|
||||||
else if (key === '__VSIZE') return c.__VSIZE!;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFinalScripts(
|
function getFinalScripts(
|
||||||
|
@ -1435,7 +1421,6 @@ function inputFinalizeGetAmts(
|
||||||
throw new Error('Outputs are spending more than Inputs');
|
throw new Error('Outputs are spending more than Inputs');
|
||||||
}
|
}
|
||||||
const bytes = tx.virtualSize();
|
const bytes = tx.virtualSize();
|
||||||
cache.__VSIZE = bytes;
|
|
||||||
cache.__FEE = fee;
|
cache.__FEE = fee;
|
||||||
cache.__EXTRACTED_TX = tx;
|
cache.__EXTRACTED_TX = tx;
|
||||||
cache.__FEE_RATE = Math.floor(fee / bytes);
|
cache.__FEE_RATE = Math.floor(fee / bytes);
|
||||||
|
|
1
types/psbt.d.ts
vendored
1
types/psbt.d.ts
vendored
|
@ -58,7 +58,6 @@ export declare class Psbt {
|
||||||
extractTransaction(disableFeeCheck?: boolean): Transaction;
|
extractTransaction(disableFeeCheck?: boolean): Transaction;
|
||||||
getFeeRate(): number;
|
getFeeRate(): number;
|
||||||
getFee(): number;
|
getFee(): number;
|
||||||
getVSize(): number;
|
|
||||||
finalizeAllInputs(): this;
|
finalizeAllInputs(): this;
|
||||||
finalizeInput(inputIndex: number): this;
|
finalizeInput(inputIndex: number): this;
|
||||||
validateSignaturesOfAllInputs(): boolean;
|
validateSignaturesOfAllInputs(): boolean;
|
||||||
|
|
Loading…
Reference in a new issue