1
0

Renter display

This commit is contained in:
Scott E. Graves
2017-02-18 12:46:33 -06:00
parent 3949ba30e1
commit 531472fdb8
7 changed files with 163 additions and 8 deletions

View File

@@ -2,7 +2,49 @@
#include "SiaApi.h"
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) :
CSiaBase(siaCurl),
CAutoThread(siaCurl)
@@ -20,7 +62,36 @@ void CSiaApi::_CSiaRenter::AutoThreadCallback(const CSiaCurl& siaCurl)
json 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);
}
}