當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Currency.Div64方法代碼示例

本文整理匯總了Golang中github.com/NebulousLabs/Sia/types.Currency.Div64方法的典型用法代碼示例。如果您正苦於以下問題:Golang Currency.Div64方法的具體用法?Golang Currency.Div64怎麽用?Golang Currency.Div64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/NebulousLabs/Sia/types.Currency的用法示例。


在下文中一共展示了Currency.Div64方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: maxSectors

// maxSectors is the estimated maximum number of sectors that the allowance
// can support.
func maxSectors(a modules.Allowance, hdb hostDB) (uint64, error) {
	if a.Hosts == 0 || a.Period == 0 {
		return 0, errors.New("invalid allowance")
	}

	// Sample at least 10 hosts.
	nRandomHosts := int(a.Hosts)
	if nRandomHosts < 10 {
		nRandomHosts = 10
	}
	hosts := hdb.RandomHosts(nRandomHosts, nil)
	if len(hosts) < int(a.Hosts) {
		return 0, errors.New("not enough hosts")
	}

	// Calculate cost of storing 1 sector per host for the allowance period.
	var sum types.Currency
	for _, h := range hosts {
		sum = sum.Add(h.StoragePrice)
	}
	averagePrice := sum.Div64(uint64(len(hosts)))
	costPerSector := averagePrice.Mul64(a.Hosts).Mul64(modules.SectorSize).Mul64(uint64(a.Period))

	// Divide total funds by cost per sector.
	numSectors, err := a.Funds.Div(costPerSector).Uint64()
	if err != nil {
		// if there was an overflow, something is definitely wrong
		return 0, errors.New("allowance can fund suspiciously large number of sectors")
	}
	return numSectors, nil
}
開發者ID:robvanmieghem,項目名稱:Sia,代碼行數:33,代碼來源:formcontract.go

示例2: CalculateFee

// CalculateFee returns the fee-per-byte of a transaction set.
func CalculateFee(ts []types.Transaction) types.Currency {
	var sum types.Currency
	for _, t := range ts {
		for _, fee := range t.MinerFees {
			sum = sum.Add(fee)
		}
	}
	size := len(encoding.Marshal(ts))
	return sum.Div64(uint64(size))
}
開發者ID:CSSZiegler,項目名稱:Sia,代碼行數:11,代碼來源:transactionpool.go

示例3: AverageContractPrice

// AverageContractPrice returns the average price of a host.
func (hdb *HostDB) AverageContractPrice() types.Currency {
	// maybe a more sophisticated way of doing this
	var totalPrice types.Currency
	sampleSize := 18
	hosts := hdb.RandomHosts(sampleSize, nil)
	if len(hosts) == 0 {
		return totalPrice
	}
	for _, host := range hosts {
		totalPrice = totalPrice.Add(host.ContractPrice)
	}
	return totalPrice.Div64(uint64(len(hosts)))
}
開發者ID:robvanmieghem,項目名稱:Sia,代碼行數:14,代碼來源:hostentry.go

示例4: hostcmd

// hostcmd is the handler for the command `siac host`.
// Prints info about the host and its storage folders.
func hostcmd() {
	hg := new(api.HostGET)
	err := getAPI("/host", hg)
	if err != nil {
		die("Could not fetch host settings:", err)
	}
	sg := new(api.StorageGET)
	err = getAPI("/host/storage", sg)
	if err != nil {
		die("Could not fetch storage info:", err)
	}

	// Determine the competitive price string.
	ah := new(api.ActiveHosts)
	var competitivePrice string
	err = getAPI("/hostdb/active?numhosts=24", ah)
	if err != nil || len(ah.Hosts) == 0 {
		competitivePrice = "Unavailable"
	} else {
		var sum types.Currency
		for _, host := range ah.Hosts {
			sum = sum.Add(host.StoragePrice)
		}

		// Divide by the number of hosts to get the average price, and then
		// trim 5% to present what would be a competitive edge.
		competitivePrice = currencyUnits(sum.Div64(uint64(len(ah.Hosts))).MulFloat(0.95).Mul(modules.BlockBytesPerMonthTerabyte))
	}

	es := hg.ExternalSettings
	fm := hg.FinancialMetrics
	is := hg.InternalSettings
	nm := hg.NetworkMetrics

	// calculate total storage available and remaining
	var totalstorage, storageremaining uint64
	for _, folder := range sg.Folders {
		totalstorage += folder.Capacity
		storageremaining += folder.CapacityRemaining
	}

	// convert price from bytes/block to TB/Month
	price := currencyUnits(is.MinStoragePrice.Mul(modules.BlockBytesPerMonthTerabyte))
	// calculate total revenue
	totalRevenue := fm.ContractCompensation.
		Add(fm.StorageRevenue).
		Add(fm.DownloadBandwidthRevenue).
		Add(fm.UploadBandwidthRevenue)
	totalPotentialRevenue := fm.PotentialContractCompensation.
		Add(fm.PotentialStorageRevenue).
		Add(fm.PotentialDownloadBandwidthRevenue).
		Add(fm.PotentialUploadBandwidthRevenue)
	// determine the display method for the net address.
	netaddr := es.NetAddress
	if is.NetAddress == "" {
		netaddr += " (automatically determined)"
	} else {
		netaddr += " (manually specified)"
	}

	if hostVerbose {
		// describe net address
		fmt.Printf(`General Info:
	Estimated Competitive Price: %v

Host Internal Settings:
	acceptingcontracts:   %v
	maxduration:          %v Weeks
	maxdownloadbatchsize: %v
	maxrevisebatchsize:   %v
	netaddress:           %v
	windowsize:           %v Hours

	collateral:       %v / TB / Month
	collateralbudget: %v 
	maxcollateral:    %v Per Contract

	mincontractprice:          %v
	mindownloadbandwidthprice: %v / TB
	minstorageprice:           %v / TB / Month
	minuploadbandwidthprice:   %v / TB

Host Financials:
	Contract Count:               %v
	Transaction Fee Compensation: %v
	Potential Fee Compensation:   %v
	Transaction Fee Expenses:     %v

	Storage Revenue:           %v
	Potential Storage Revenue: %v

	Locked Collateral: %v
	Risked Collateral: %v
	Lost Collateral:   %v

	Download Revenue:           %v
	Potential Download Revenue: %v
	Upload Revenue :            %v
//.........這裏部分代碼省略.........
開發者ID:robvanmieghem,項目名稱:Sia,代碼行數:101,代碼來源:hostcmd.go


注:本文中的github.com/NebulousLabs/Sia/types.Currency.Div64方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。