1
0

Refactoring and added common utils

This commit is contained in:
Scott E. Graves
2017-02-17 18:58:06 -06:00
parent 6b425fc5ca
commit 9b44d435f8
9 changed files with 101 additions and 30 deletions

View File

@@ -2,4 +2,35 @@
#include "SiaCommon.h"
#include <ttmath/ttmath.h>
using namespace Sia::Api;
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)))
}
*/