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.h
2017-02-04 15:40:12 -06:00

71 lines
1.7 KiB
C++

#pragma once
#include <string>
#include <cstdint>
#include <memory>
#include "json.hpp"
#include <ttmath/ttmath.h>
using json = nlohmann::json;
#define NS_BEGIN(n) namespace n {
#define NS_END1() }
#define NS_END2() NS_END1() }
#define NS_END3() NS_END2() }
#define NS_END4() NS_END3() }
#define NS_END5() NS_END4() }
#define NS_END(c) NS_END##c()
NS_BEGIN(Sia)
NS_BEGIN(Api)
#define String std::wstring
#define Property(type, name, get_access, set_access) \
private:\
type _##name;\
get_access:\
const type& Get##name() const { return _##name;}\
set_access:\
const type& Set##name(const type& value) { _##name = value; return _##name; }
#define JProperty(type, name, get_access, set_access, json_doc) \
get_access:\
type Get##name() const { return json_doc[#name].get<type>();}\
set_access:\
type Set##name(const type& value) { json_doc[#name] = value; return value; }
struct SiaHostConfig
{
String HostName;
std::uint16_t HostPort;
String RequiredVersion;
};
#define API_SUCCESS(t, x) (x == t::Success)
#define DEFAULT_CONFIG_FILE_PATH L".\\Config\\SiaDriveConfig.json"
typedef ttmath::Big<1, 30> SiaCurrency;
/*
BigNumber.config({ EXPONENTIAL_AT: 1e+9 })
BigNumber.config({ DECIMAL_PLACES: 30 })
const hastingsPerSiacoin = new BigNumber('10').toPower(24)
const siacoinsToHastings = (siacoins) => new BigNumber(siacoins).times(hastingsPerSiacoin)
const hastingsToSiacoins = (hastings) => new BigNumber(hastings).dividedBy(hastingsPerSiacoin)
*/
static inline SiaCurrency HastingsStringToSiaCurrency(const String& value)
{
ttmath::Parser<SiaCurrency> parser;
parser.Parse(value + L" / (10^24)");
return parser.stack[0].value;
}
static inline String SiaCurrencyToString(const SiaCurrency& value)
{
return value.ToWString();
}
NS_END(2)