From 2541f08bbec763d5933f3556abd42d80a3885ae4 Mon Sep 17 00:00:00 2001 From: Nishant Ghodke Date: Sun, 6 Aug 2023 14:11:25 +0530 Subject: [PATCH] refcator: add default value to nested object arg prop --- packages/sdk/src/utils/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/sdk/src/utils/index.ts b/packages/sdk/src/utils/index.ts index 09ce9c6b..f588e2cb 100644 --- a/packages/sdk/src/utils/index.ts +++ b/packages/sdk/src/utils/index.ts @@ -95,19 +95,24 @@ export function calculateTxFee({ totalOutputs, satsPerByte, type, - additional = {} + additional: { witnessScripts = [] } = {} }: CalculateTxFeeOptions): number { - const txWeight = calculateTxVirtualSize({ totalInputs, totalOutputs, type, additional }) + const txWeight = calculateTxVirtualSize({ totalInputs, totalOutputs, type, additional: { witnessScripts } }) return txWeight * satsPerByte } -export function calculateTxVirtualSize({ totalInputs, totalOutputs, type, additional }: CalculateTxVirtualSizeOptions) { +export function calculateTxVirtualSize({ + totalInputs, + totalOutputs, + type, + additional: { witnessScripts = [] } = {} +}: CalculateTxVirtualSizeOptions) { const baseWeight = getInputOutputBaseSizeByType(type) const inputVBytes = baseWeight.input * totalInputs const outputVBytes = baseWeight.output * totalOutputs const baseVBytes = inputVBytes + outputVBytes + baseWeight.txHeader - const additionalVBytes = additional?.witnessScripts?.reduce((acc, script) => (acc += script.byteLength), 0) || 0 + const additionalVBytes = witnessScripts.reduce((acc, script) => (acc += script.byteLength), 0) || 0 const weight = 3 * baseVBytes + (baseVBytes + additionalVBytes) const vSize = Math.ceil(weight / 4)