1
0
This repository has been archived on 2025-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
Files
siadrive/SiaDrive.Api/SiaCommon.cpp
2017-02-17 18:58:06 -06:00

36 lines
1.2 KiB
C++

#include "stdafx.h"
#include "SiaCommon.h"
#include <ttmath/ttmath.h>
using namespace Sia::Api;
/*
// avgHostMetric computes the average of the metric given by `metric` on the
// list of `hosts`.
const avgHostMetric = (hosts, metric) = >
hosts.reduce((sum, host) = > sum.add(host[metric]), new BigNumber(0))
.dividedBy(hosts.size)
// avgStorageCost returns the average storage cost from a list of hosts given a
// period (blocks) and redundancy.
const avgStorageCost = (hosts, period, redundancy) = >
avgHostMetric(hosts, 'storageprice')
.times(period)
.plus(avgHostMetric(hosts, 'uploadbandwidthprice'))
.times(redundancy)
.plus(avgHostMetric(hosts, 'downloadbandwidthprice'))
// Compute an estimated amount of storage from an amount of funds (Hastings)
// and a list of hosts.
export const estimatedStorage = (funds, hosts) = > {
const validHosts = List(hosts).take(28)
const avgStorage = avgStorageCost(validHosts, allowancePeriod, baseRedundancy)
let fee = SiaAPI.siacoinsToHastings(baseFee)
fee = fee.plus(avgHostMetric(validHosts, 'contractprice').times(ncontracts))
fee = fee.plus(funds.minus(fee).times(siafundRate))
return '~' + readableFilesize(Math.max(0, funds.minus(fee).dividedBy(avgStorage).toNumber().toPrecision(1)))
}
*/