1
0

More changes

This commit is contained in:
Scott E. Graves
2017-04-10 17:49:44 -05:00
parent 0975ed41d6
commit feadab847e
8 changed files with 230 additions and 41 deletions

View File

@@ -30,8 +30,8 @@
#define _WIN32_WINNT_WIN10 0x0A00 // Windows 10
// Windows 8.1 or above supported
#define WINVER _WIN32_WINNT_WINBLUE
#define _WIN32_WINNT _WIN32_WINNT_WINBLUE
#define WINVER _WIN32_WINNT_WIN7
#define _WIN32_WINNT _WIN32_WINNT_WIN7
#define _WINSOCKAPI_
#include <Windows.h>
#include <Shlwapi.h>
@@ -68,6 +68,8 @@ using json = nlohmann::json;
#define NS_END(c) NS_END##c()
#define COMMA ,
NS_BEGIN(Sia)
NS_BEGIN(Api)
@@ -87,7 +89,7 @@ typedef ttmath::Big<1, 30> SiaCurrency;
const std::uint8_t SIA_BLOCK_TIME_MINS = 10;
const std::uint32_t MINUTES_PER_MONTH = (730 * 60);
const std::uint32_t SIA_BLOCKS_PER_MONTH = MINUTES_PER_MONTH / SIA_BLOCK_TIME_MINS;
const std::uint32_t SIA_DEFAULT_HOST_COUNT = 50;
const std::uint32_t SIA_DEFAULT_HOST_COUNT = 24;
const std::uint32_t SIA_DEFAULT_RENEW_WINDOW = ((1440 / SIA_BLOCK_TIME_MINS) * 14);
const SiaCurrency SIA_DEFAULT_MINIMUM_FUNDS = 4000;
const std::uint32_t SIA_DEFAULT_CONTRACT_LENGTH = SIA_BLOCKS_PER_MONTH * 3;
@@ -131,7 +133,7 @@ public:
public:
Property(T, Code, public, private)
Property(SString, Reason, public, private)
Property(SString, Reason, public, private)
public:
operator bool() { return GetCode() == T::Success; }
@@ -189,41 +191,16 @@ inline static SString SiaCurrencyToGB(const SiaCurrency& value)
return value.ToWString(conv);
}
class IHost
inline static Hastings SiaCurrencyToHastings(const SiaCurrency& currency)
{
public:
IHost() {}
virtual ~IHost() {}
ttmath::Parser<SiaCurrency> parser;
parser.Parse(currency.ToString() + " * (10 ^ 24)");
public:
virtual Hastings GetStoragePrice() const = 0;
virtual Hastings GetDownloadPrice() const = 0;
virtual Hastings GetUploadPrice() const = 0;
};
template<typename T, typename R>
inline static R CalculateAveragePrice(const std::vector<T>& v, std::function<R(const T& t)> PriceGetter)
{
R result = v.size() ? std::accumulate(std::next(v.begin()), v.end(), PriceGetter(v[0]), [&](const R& a, const T& b) {
return a + PriceGetter(b);
}).Div(v.size()) : 0;
return result;
}
inline static Hastings CalculateAverageHostPrice(const std::vector<IHost>& hosts)
{
return CalculateAveragePrice<IHost, Hastings>(hosts, [](const IHost& host)->Hastings { return host.GetStoragePrice(); });
}
inline static Hastings CalculateAverageDownloadPrice(const std::vector<IHost>& hosts)
{
return CalculateAveragePrice<IHost, Hastings>(hosts, [](const IHost& host)->Hastings { return host.GetDownloadPrice(); });
}
inline static Hastings CalculateAverageUploadPrice(const std::vector<IHost>& hosts)
{
return CalculateAveragePrice<IHost, Hastings>(hosts, [](const IHost& host)->Hastings { return host.GetUploadPrice(); });
ttmath::Conv conv;
conv.scient_from = 256;
conv.base = 10;
conv.round = 0;
return parser.stack[0].value.ToString(conv);
}
BOOL SIADRIVE_EXPORTABLE RetryAction(std::function<BOOL()> func, std::uint16_t retryCount, const DWORD& retryDelay);