1
0

Renter allowance changes

This commit is contained in:
Scott E. Graves
2017-03-28 18:35:39 -05:00
parent ffaf818e5f
commit 8d0b76e378
6 changed files with 107 additions and 11 deletions

View File

@@ -350,8 +350,7 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
{
context->Enter();
auto global = context->GetGlobal();
auto obj = global->GetValue("uiState");
bool wasOnline = obj->GetValue("isOnline")->GetBoolValue();
bool wasOnline = global->GetValue("uiState")->GetValue("isOnline")->GetBoolValue();
bool isOnline = _siaApi->GetWallet()->GetConnected();
if (wasOnline != isOnline)
@@ -421,6 +420,15 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
}
ExecuteSetter(context, uiUpdate, "setAvailableDriveLetters", driveList);
// Renter settings
auto allowance = _siaApi->GetRenter()->GetAllowance();
auto obj = global->CreateObject(nullptr, nullptr);
obj->SetValue("Funds", CefV8Value::CreateString(SiaCurrencyToString(allowance.Funds).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("Hosts", CefV8Value::CreateString(SString::FromUInt64(allowance.Hosts).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("Period", CefV8Value::CreateString(SString::FromUInt64(allowance.Period).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("RenewWindowInBlocks", CefV8Value::CreateString(SString::FromUInt64(allowance.RenewWindowInBlocks).str()), V8_PROPERTY_ATTRIBUTE_NONE);
ExecuteSetter(context, renterActions, "setAllowance", obj);
// Display block height
ExecuteSetter(context, uiActions, "setBlockHeight", SString::FromUInt64(_siaApi->GetConsensus()->GetHeight()));
}

View File

@@ -45,13 +45,26 @@ using namespace Sia::Api;
"unspent": "1234" // hastings
}
}*/
/*
typedef struct
{
std::uint8_t DurationInMonths;
SiaCurrency Funds;
std::uint64_t Hosts;
std::uint64_t RenewWindowInBlocks;
} _SiaRenterAllowance;*/
CSiaApi::_CSiaRenter::_CSiaRenter(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) :
CSiaBase(siaCurl, siaDriveConfig),
_Funds(0),
_Hosts(0),
_Unspent(0),
_TotalUsedBytes(0),
_TotalUploadProgress(100)
_TotalUploadProgress(100),
_Period(0),
_RenewWindow(0),
_currentAllowance({ 0,0,0,0 })
{
}
@@ -66,11 +79,15 @@ void CSiaApi::_CSiaRenter::Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* sia
{
SiaCurrency funds = HastingsStringToSiaCurrency(result["settings"]["allowance"]["funds"].get<std::string>());
SiaCurrency unspent = HastingsStringToSiaCurrency(result["financialmetrics"]["unspent"].get<std::string>());
std::uint64_t hosts = result["settings"]["allowance"]["hosts"].get<std::uint64_t>();
std::uint64_t hosts = result["settings"]["allowance"]["hosts"].get<std::uint64_t>();
std::uint64_t period = result["settings"]["allowance"]["period"].get<std::uint64_t>();
std::uint64_t renewWindow = result["settings"]["allowance"]["renewwindow"].get<std::uint64_t>();
SetFunds(funds);
SetHosts(hosts);
SetUnspent(unspent);
SetRenewWindow(renewWindow);
SetPeriod(period);
_currentAllowance = { funds, hosts, period, renewWindow };
CSiaFileTreePtr fileTree(new CSiaFileTree(siaCurl, siaDriveConfig));
if (ApiSuccess(siaCurl.Get(L"/renter/files", result)))
{
@@ -115,6 +132,9 @@ void CSiaApi::_CSiaRenter::Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* sia
SetUnspent(0);
SetTotalUsedBytes(0);
SetTotalUploadProgress(100);
SetPeriod(0);
SetRenewWindow(0);
_currentAllowance = { 0,0,0,0 };
}
}
@@ -150,4 +170,28 @@ SiaApiError CSiaApi::_CSiaRenter::GetFileTree(CSiaFileTreePtr& siaFileTree) cons
}
return SiaApiError::Success;
}
SiaRenterAllowance CSiaApi::_CSiaRenter::GetAllowance() const
{
return _currentAllowance;
}
SiaApiError CSiaApi::_CSiaRenter::SetAllowance(const SiaRenterAllowance& renterAllowance)
{
SiaApiError ret = SiaApiError::RequestError;
json result;
if (ApiSuccess(GetSiaCurl().Post(L"/renter",
{
{ "funds", SiaCurrencyToHastingsString(renterAllowance.Funds) },
{ "hosts", SString::FromUInt64(renterAllowance.Hosts) },
{ "period", SString::FromUInt64(renterAllowance.Period) },
{ "renewwindow", SString::FromUInt64 (renterAllowance.RenewWindowInBlocks) }
}, result)))
{
ret = SiaApiError::Success;
}
return ret;
}