Skip to content

Commit

Permalink
refcator: add default value to nested object arg prop
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcrazycoder committed Aug 6, 2023
1 parent 55cb51d commit 2541f08
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/sdk/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2541f08

Please sign in to comment.