Renter display
This commit is contained in:
@@ -137,6 +137,11 @@ public:
|
|||||||
public:
|
public:
|
||||||
virtual ~_CSiaRenter();
|
virtual ~_CSiaRenter();
|
||||||
|
|
||||||
|
Property(SiaCurrency, Funds, public, private)
|
||||||
|
Property(std::uint64_t, Hosts, public, private)
|
||||||
|
Property(SiaCurrency, Unspent, public, private)
|
||||||
|
Property(std::uint64_t, TotalUsedBytes, public, private)
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void AutoThreadCallback(const CSiaCurl& siaCurl) override;
|
virtual void AutoThreadCallback(const CSiaCurl& siaCurl) override;
|
||||||
|
|
||||||
|
@@ -2,7 +2,49 @@
|
|||||||
#include "SiaApi.h"
|
#include "SiaApi.h"
|
||||||
|
|
||||||
using namespace Sia::Api;
|
using namespace Sia::Api;
|
||||||
|
/*{
|
||||||
|
// Settings that control the behavior of the renter.
|
||||||
|
"settings": {
|
||||||
|
// Allowance dictates how much the renter is allowed to spend in a given
|
||||||
|
// period. Note that funds are spent on both storage and bandwidth.
|
||||||
|
"allowance": {
|
||||||
|
// Amount of money allocated for contracts. Funds are spent on both
|
||||||
|
// storage and bandwidth.
|
||||||
|
"funds": "1234", // hastings
|
||||||
|
|
||||||
|
// Number of hosts that contracts will be formed with.
|
||||||
|
"hosts":24,
|
||||||
|
|
||||||
|
// Duration of contracts formed, in number of blocks.
|
||||||
|
"period": 6048, // blocks
|
||||||
|
|
||||||
|
// If the current blockheight + the renew window >= the height the
|
||||||
|
// contract is scheduled to end, the contract is renewed automatically.
|
||||||
|
// Is always nonzero.
|
||||||
|
"renewwindow": 3024 // blocks
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Metrics about how much the Renter has spent on storage, uploads, and
|
||||||
|
// downloads.
|
||||||
|
"financialmetrics": {
|
||||||
|
// How much money, in hastings, the Renter has spent on file contracts,
|
||||||
|
// including fees.
|
||||||
|
"contractspending": "1234", // hastings
|
||||||
|
|
||||||
|
// Amount of money spent on downloads.
|
||||||
|
"downloadspending": "5678", // hastings
|
||||||
|
|
||||||
|
// Amount of money spend on storage.
|
||||||
|
"storagespending": "1234", // hastings
|
||||||
|
|
||||||
|
// Amount of money spent on uploads.
|
||||||
|
"uploadspending": "5678", // hastings
|
||||||
|
|
||||||
|
// Amount of money in the allowance that has not been spent.
|
||||||
|
"unspent": "1234" // hastings
|
||||||
|
}
|
||||||
|
}*/
|
||||||
CSiaApi::_CSiaRenter::_CSiaRenter(const CSiaCurl& siaCurl) :
|
CSiaApi::_CSiaRenter::_CSiaRenter(const CSiaCurl& siaCurl) :
|
||||||
CSiaBase(siaCurl),
|
CSiaBase(siaCurl),
|
||||||
CAutoThread(siaCurl)
|
CAutoThread(siaCurl)
|
||||||
@@ -20,7 +62,36 @@ void CSiaApi::_CSiaRenter::AutoThreadCallback(const CSiaCurl& siaCurl)
|
|||||||
json result;
|
json result;
|
||||||
if (ApiSuccess(siaCurl.Get(L"/renter", result)))
|
if (ApiSuccess(siaCurl.Get(L"/renter", result)))
|
||||||
{
|
{
|
||||||
|
SiaCurrency funds = HastingsStringToSiaCurrency(CA2W(result["settings"]["allowance"]["funds"].get<std::string>().c_str()).m_psz);
|
||||||
|
SiaCurrency unspent = HastingsStringToSiaCurrency(CA2W(result["financialmetrics"]["unspent"].get<std::string>().c_str()).m_psz);
|
||||||
|
std::uint64_t hosts = result["settings"]["allowance"]["hosts"].get<std::uint64_t>();
|
||||||
|
SetFunds(funds);
|
||||||
|
SetHosts(hosts);
|
||||||
|
SetUnspent(unspent);
|
||||||
|
|
||||||
|
CSiaFileTreePtr fileTree(new CSiaFileTree(siaCurl));
|
||||||
|
if (ApiSuccess(siaCurl.Get(L"/renter/files", result)))
|
||||||
|
{
|
||||||
|
fileTree->BuildTree(result);
|
||||||
|
|
||||||
|
auto fileList = fileTree->GetFileList();
|
||||||
|
std::uint64_t total = std::accumulate(std::next(fileList.begin()), fileList.end(), fileList[0]->GetFileSize(), [](const std::uint64_t& sz, const CSiaFilePtr& file)
|
||||||
|
{
|
||||||
|
return sz + file->GetFileSize();
|
||||||
|
});
|
||||||
|
SetTotalUsedBytes(total);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetTotalUsedBytes(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetFunds(0);
|
||||||
|
SetHosts(0);
|
||||||
|
SetUnspent(0);
|
||||||
|
SetTotalUsedBytes(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -157,30 +157,37 @@
|
|||||||
<h3>Renter Settings <a href="javascript:void(0)" id="ID_Renter_Edit">edit</a></h3>
|
<h3>Renter Settings <a href="javascript:void(0)" id="ID_Renter_Edit">edit</a></h3>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: right">Funding:</td>
|
<td style="text-align: right">Total Funding:</td>
|
||||||
<td id="ID_Renter_AllocatedFunds"></td>
|
<td id="ID_Renter_AllocatedFunds"></td>
|
||||||
<td colspan="50%"></td>
|
<td colspan="40%"></td>
|
||||||
<td style="text-align: right">Hosts:</td>
|
<td style="text-align: right">Used Funding:</td>
|
||||||
|
<td id="ID_Renter_UsedFunds"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="text-align: right">Available Funding:</td>
|
||||||
|
<td id="ID_Renter_AvailableFunds"></td>
|
||||||
|
<td colspan="40%"></td>
|
||||||
|
<td style="text-align: right">Host Count:</td>
|
||||||
<td id="ID_Renter_HostCount"></td>
|
<td id="ID_Renter_HostCount"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: right">Total Space:</td>
|
<td style="text-align: right">Total Space:</td>
|
||||||
<td id="ID_Renter_EstimatedSpace"></td>
|
<td id="ID_Renter_EstimatedSpace"></td>
|
||||||
<td colspan="50%"></td>
|
<td colspan="40%"></td>
|
||||||
<td style="text-align: right">Price (per GB):</td>
|
<td style="text-align: right">Price (per GB):</td>
|
||||||
<td id="ID_Renter_EstimatedCost"></td>
|
<td id="ID_Renter_EstimatedCost"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: right">Available Space:</td>
|
<td style="text-align: right">Available Space:</td>
|
||||||
<td id="ID_Renter_AvailablSpace"></td>
|
<td id="ID_Renter_AvailablSpace"></td>
|
||||||
<td colspan="50%"></td>
|
<td colspan="40%"></td>
|
||||||
<td style="text-align: right">Download (per GB):</td>
|
<td style="text-align: right">Download (per GB):</td>
|
||||||
<td id="ID_Renter_EstimatedDownlodCost"></td>
|
<td id="ID_Renter_EstimatedDownlodCost"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: right">Used Space:</td>
|
<td style="text-align: right">Used Space:</td>
|
||||||
<td id="ID_Renter_UsedSpace"></td>
|
<td id="ID_Renter_UsedSpace"></td>
|
||||||
<td colspan="50%"></td>
|
<td colspan="40%"></td>
|
||||||
<td style="text-align: right">Upload (per GB):</td>
|
<td style="text-align: right">Upload (per GB):</td>
|
||||||
<td id="ID_Renter_EstimatedUploadCost"></td>
|
<td id="ID_Renter_EstimatedUploadCost"></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Binary file not shown.
@@ -432,6 +432,32 @@ String CSiaDriveDlg::GetWalletUnlockPassword()
|
|||||||
return result.bstrVal ? result.bstrVal : L"";
|
return result.bstrVal ? result.bstrVal : L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSiaDriveDlg::SetRenterAllocatedFunds(const SiaCurrency& currency)
|
||||||
|
{
|
||||||
|
CallClientScript(L"setRenterAllocatedFunds", SiaCurrencyToString(currency), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSiaDriveDlg::SetRenterHosts(const std::uint64_t& hosts)
|
||||||
|
{
|
||||||
|
CallClientScript(L"setRenterHosts", std::to_wstring(hosts), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSiaDriveDlg::SetRenterAvailableFunds(const SiaCurrency& currency)
|
||||||
|
{
|
||||||
|
CallClientScript(L"setRenterAvailableFunds", SiaCurrencyToString(currency), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSiaDriveDlg::SetRenterUsedFunds(const SiaCurrency& currency)
|
||||||
|
{
|
||||||
|
CallClientScript(L"setRenterUsedFunds", SiaCurrencyToString(currency), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSiaDriveDlg::SetRenterTotalUsed(const std::uint64_t& bytes)
|
||||||
|
{
|
||||||
|
double total = bytes ? bytes / (1024.0 * 1024.0 * 1024.0) : 0.0;
|
||||||
|
CallClientScript(L"setRenterTotalUsedGb", std::to_wstring(total), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
||||||
{
|
{
|
||||||
KillTimer(IDT_UPDATE);
|
KillTimer(IDT_UPDATE);
|
||||||
@@ -439,10 +465,18 @@ void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
|||||||
|
|
||||||
SetServerVersion(L"x.x.x.");
|
SetServerVersion(L"x.x.x.");
|
||||||
SetClientVersion(L"1.0.0");
|
SetClientVersion(L"1.0.0");
|
||||||
|
|
||||||
SetWalletConfirmedBalance(L"");
|
SetWalletConfirmedBalance(L"");
|
||||||
SetWalletUnconfirmedBalance(L"");
|
SetWalletUnconfirmedBalance(L"");
|
||||||
SetWalletTotalBalance(L"");
|
SetWalletTotalBalance(L"");
|
||||||
SetWalletReceiveAddress(L"");
|
SetWalletReceiveAddress(L"");
|
||||||
|
|
||||||
|
SetRenterAllocatedFunds(0);
|
||||||
|
SetRenterAvailableFunds(0);
|
||||||
|
SetRenterUsedFunds(0);
|
||||||
|
SetRenterHosts(0);
|
||||||
|
SetRenterTotalUsed(0);
|
||||||
|
|
||||||
SetConsensusHeight(0);
|
SetConsensusHeight(0);
|
||||||
|
|
||||||
SetTimer(IDT_UPDATE, 2000, nullptr);
|
SetTimer(IDT_UPDATE, 2000, nullptr);
|
||||||
@@ -523,7 +557,6 @@ bool CSiaDriveDlg::UpdateSiaInfo()
|
|||||||
SetWalletConfirmedBalance(SiaCurrencyToString(confirmed));
|
SetWalletConfirmedBalance(SiaCurrencyToString(confirmed));
|
||||||
SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed));
|
SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed));
|
||||||
SetWalletTotalBalance(SiaCurrencyToString(total));
|
SetWalletTotalBalance(SiaCurrencyToString(total));
|
||||||
|
|
||||||
if (GetWalletReceiveAddress().empty())
|
if (GetWalletReceiveAddress().empty())
|
||||||
{
|
{
|
||||||
String address;
|
String address;
|
||||||
@@ -531,6 +564,14 @@ bool CSiaDriveDlg::UpdateSiaInfo()
|
|||||||
SetWalletReceiveAddress(address);
|
SetWalletReceiveAddress(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SiaCurrency allocatedFunds = _siaApi.GetRenter()->GetFunds();
|
||||||
|
SiaCurrency unspentFunds = _siaApi.GetRenter()->GetUnspent();
|
||||||
|
SetRenterAllocatedFunds(allocatedFunds);
|
||||||
|
SetRenterAvailableFunds(unspentFunds);
|
||||||
|
SetRenterUsedFunds(allocatedFunds - unspentFunds);
|
||||||
|
SetRenterHosts(_siaApi.GetRenter()->GetHosts());
|
||||||
|
SetRenterTotalUsed(_siaApi.GetRenter()->GetTotalUsedBytes());
|
||||||
|
|
||||||
SetConsensusHeight(_siaApi.GetConsensus()->GetHeight());
|
SetConsensusHeight(_siaApi.GetConsensus()->GetHeight());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -543,6 +584,13 @@ bool CSiaDriveDlg::UpdateSiaInfo()
|
|||||||
SetWalletUnconfirmedBalance(L"");
|
SetWalletUnconfirmedBalance(L"");
|
||||||
SetWalletTotalBalance(L"");
|
SetWalletTotalBalance(L"");
|
||||||
SetWalletReceiveAddress(L"");
|
SetWalletReceiveAddress(L"");
|
||||||
|
|
||||||
|
SetRenterAllocatedFunds(0);
|
||||||
|
SetRenterAvailableFunds(0);
|
||||||
|
SetRenterUsedFunds(0);
|
||||||
|
SetRenterHosts(0);
|
||||||
|
SetRenterTotalUsed(0);
|
||||||
|
|
||||||
SetConsensusHeight(0);
|
SetConsensusHeight(0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -78,7 +78,11 @@ private:
|
|||||||
String GetWalletUnlockPassword();
|
String GetWalletUnlockPassword();
|
||||||
void SetWalletUnlockPassword(const String& address);
|
void SetWalletUnlockPassword(const String& address);
|
||||||
void SetConsensusHeight(const std::uint64_t& height);
|
void SetConsensusHeight(const std::uint64_t& height);
|
||||||
|
void SetRenterAllocatedFunds(const SiaCurrency& currency);
|
||||||
|
void SetRenterAvailableFunds(const SiaCurrency& currency);
|
||||||
|
void SetRenterUsedFunds(const SiaCurrency& currency);
|
||||||
|
void SetRenterHosts(const std::uint64_t& hosts);
|
||||||
|
void SetRenterTotalUsed(const std::uint64_t& bytes);
|
||||||
void QueueUiAction(std::function<void()> action);
|
void QueueUiAction(std::function<void()> action);
|
||||||
void ProcessUiActionQueue();
|
void ProcessUiActionQueue();
|
||||||
|
|
||||||
|
@@ -60,6 +60,26 @@ function setConsensusHeight(height) {
|
|||||||
setInnerText("ID_BlockHeight", height);
|
setInnerText("ID_BlockHeight", height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setRenterAllocatedFunds(funds) {
|
||||||
|
setInnerText("ID_Renter_AllocatedFunds", funds);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setRenterHosts(hosts) {
|
||||||
|
setInnerText("ID_Renter_HostCount", hosts);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setRenterAvailableFunds(funds) {
|
||||||
|
setInnerText("ID_Renter_AvailableFunds", funds);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setRenterUsedFunds(funds) {
|
||||||
|
setInnerText("ID_Renter_UsedFunds", funds);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setRenterTotalUsedGb(gb) {
|
||||||
|
setInnerText("ID_Renter_UsedSpace", gb);
|
||||||
|
}
|
||||||
|
|
||||||
function setAvailableDrives(driveList) {
|
function setAvailableDrives(driveList) {
|
||||||
driveList = Array.isArray(driveList) ? driveList : JSON.parse(driveList);
|
driveList = Array.isArray(driveList) ? driveList : JSON.parse(driveList);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user