Skip to content

Commit

Permalink
refactor: rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcrazycoder committed Aug 3, 2023
1 parent 950ed7c commit d4e0f9f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/sdk/src/transactions/OrdTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class OrdTransaction {
redeem: redeemScript
})

// inscription tx always have 1 input and 1 output
const fees = calculateTxFee({
totalInputs: 1,
totalOutputs: 1,
Expand Down
7 changes: 3 additions & 4 deletions packages/sdk/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ECPairFactory from "ecpair"

import { AddressFormats, AddressTypes } from "../addresses/formats"
import { Network } from "../config/types"
import { CalculateTxFeeOptions, CalculateTxWeightOptions } from "./types"
import { CalculateTxFeeOptions, CalculateTxVirtualSizeOptions } from "./types"

export function getNetwork(value: Network) {
if (value === "mainnet") {
Expand Down Expand Up @@ -112,11 +112,11 @@ export function calculateTxFee({
type,
additional = {}
}: CalculateTxFeeOptions): number {
const txWeight = calculateTxWeight({ totalInputs, totalOutputs, type, additional })
const txWeight = calculateTxVirtualSize({ totalInputs, totalOutputs, type, additional })
return txWeight * satsPerByte
}

export function calculateTxWeight({ totalInputs, totalOutputs, type, additional }: CalculateTxWeightOptions) {
export function calculateTxVirtualSize({ totalInputs, totalOutputs, type, additional }: CalculateTxVirtualSizeOptions) {
const baseWeight = getInputOutputBaseWeightByType(type)

const inputVBytes = baseWeight.input * totalInputs
Expand All @@ -126,7 +126,6 @@ export function calculateTxWeight({ totalInputs, totalOutputs, type, additional
additional && Buffer.isBuffer(additional?.witnessScript) ? additional.witnessScript.byteLength : 0
const weight = 3 * baseVBytes + (baseVBytes + additionalVBytes)
const vSize = Math.ceil(weight / 4)
console.log("weight >>", inputVBytes, outputVBytes, baseVBytes, additionalVBytes, weight, vSize)

return vSize
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export interface CalculateTxFeeOptions {
}
}

export type CalculateTxWeightOptions = Omit<CalculateTxFeeOptions, "satsPerByte">
export type CalculateTxVirtualSizeOptions = Omit<CalculateTxFeeOptions, "satsPerByte">

0 comments on commit d4e0f9f

Please sign in to comment.