calculator

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const UnitFactor = 1e7

UnitFactor represents the smallest unit conversion factor for both USD and TFT 1 USD = 10,000,000 unit-USD 1 TFT = 10,000,000 unit-TFT (TFT's Planck)

Variables

View Source
var ErrContractDeleted = errors.New("contract is deleted")

Functions

This section is empty.

Types

type Calculator

type Calculator struct {
	// contains filtered or unexported fields
}

Calculator struct for calculating the cost of resources

func NewCalculator

func NewCalculator(substrateConn subi.SubstrateExt, identity substrate.Identity) Calculator

NewCalculator creates a new Calculator

func (Calculator) CalculateContractOverdue added in v0.16.10

func (c Calculator) CalculateContractOverdue(id uint64, allowance time.Duration) (int64, error)

Calculates the overdue amount in TFT.

The overdue amount basically is the sum of three parts:

1- Total over draft: is the sum of additional overdraft and standard overdraft.
2- Unbilled NU: is the unbilled amount of network usage.
3- The estimated cost of the contract for the total period: this part is dependant on the contract type and if the contract is on rented node or not.

If the contract is rent contract, will add both of ipv4 cost and the total overdue of all associated contracts. The total period is the time since the last billing added to Allowance period. The resulting overdue amount represents the amount that needs to be addressed.

func (*Calculator) CalculateCost

func (c *Calculator) CalculateCost(cru, mru, hru, sru uint64, publicIP, certified bool) (float64, error)

CalculateCost calculates the cost in $ per month of the given resources without a discount

func (*Calculator) CalculatePricesAfterDiscount added in v0.16.10

func (c *Calculator) CalculatePricesAfterDiscount(cost float64) (dedicatedPrice, sharedPrice float64, err error)

CalculatePricesAfterDiscount calculates the prices after discount it takes the cost in USD and returns the prices after discount

func (*Calculator) TFTtoUSD added in v0.16.10

func (c *Calculator) TFTtoUSD(tft float64) (float64, error)

TFTtoUSD converts TFT amount to USD based on the current price

func (*Calculator) USDtoTFT added in v0.16.10

func (c *Calculator) USDtoTFT(usd float64) (float64, error)

USDtoTFT converts USD amount to TFT based on the current price

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL