diff --git a/SiaDrive.Api/SiaApi.h b/SiaDrive.Api/SiaApi.h index e628d4d..cbe3d4b 100644 --- a/SiaDrive.Api/SiaApi.h +++ b/SiaDrive.Api/SiaApi.h @@ -137,6 +137,11 @@ public: public: 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: virtual void AutoThreadCallback(const CSiaCurl& siaCurl) override; diff --git a/SiaDrive.Api/SiaRenter.cpp b/SiaDrive.Api/SiaRenter.cpp index ceeb4b7..bd1d85c 100644 --- a/SiaDrive.Api/SiaRenter.cpp +++ b/SiaDrive.Api/SiaRenter.cpp @@ -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().c_str()).m_psz); + SiaCurrency unspent = HastingsStringToSiaCurrency(CA2W(result["financialmetrics"]["unspent"].get().c_str()).m_psz); + std::uint64_t hosts = result["settings"]["allowance"]["hosts"].get(); + 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); } } diff --git a/SiaDrive/SiaDrive.htm b/SiaDrive/SiaDrive.htm index a729177..ffd2cc7 100644 --- a/SiaDrive/SiaDrive.htm +++ b/SiaDrive/SiaDrive.htm @@ -157,30 +157,37 @@

Renter Settings edit

- + - - + + + + + + + + + - + - + - + diff --git a/SiaDrive/SiaDrive.rc b/SiaDrive/SiaDrive.rc index f9f4732..4fbdee2 100644 Binary files a/SiaDrive/SiaDrive.rc and b/SiaDrive/SiaDrive.rc differ diff --git a/SiaDrive/SiaDriveDlg.cpp b/SiaDrive/SiaDriveDlg.cpp index b2597ff..fad8d46 100644 --- a/SiaDrive/SiaDriveDlg.cpp +++ b/SiaDrive/SiaDriveDlg.cpp @@ -432,6 +432,32 @@ String CSiaDriveDlg::GetWalletUnlockPassword() 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) { KillTimer(IDT_UPDATE); @@ -439,10 +465,18 @@ void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR) SetServerVersion(L"x.x.x."); SetClientVersion(L"1.0.0"); + SetWalletConfirmedBalance(L""); SetWalletUnconfirmedBalance(L""); SetWalletTotalBalance(L""); SetWalletReceiveAddress(L""); + + SetRenterAllocatedFunds(0); + SetRenterAvailableFunds(0); + SetRenterUsedFunds(0); + SetRenterHosts(0); + SetRenterTotalUsed(0); + SetConsensusHeight(0); SetTimer(IDT_UPDATE, 2000, nullptr); @@ -523,7 +557,6 @@ bool CSiaDriveDlg::UpdateSiaInfo() SetWalletConfirmedBalance(SiaCurrencyToString(confirmed)); SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed)); SetWalletTotalBalance(SiaCurrencyToString(total)); - if (GetWalletReceiveAddress().empty()) { String address; @@ -531,6 +564,14 @@ bool CSiaDriveDlg::UpdateSiaInfo() 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()); return true; } @@ -543,6 +584,13 @@ bool CSiaDriveDlg::UpdateSiaInfo() SetWalletUnconfirmedBalance(L""); SetWalletTotalBalance(L""); SetWalletReceiveAddress(L""); + + SetRenterAllocatedFunds(0); + SetRenterAvailableFunds(0); + SetRenterUsedFunds(0); + SetRenterHosts(0); + SetRenterTotalUsed(0); + SetConsensusHeight(0); return false; } diff --git a/SiaDrive/SiaDriveDlg.h b/SiaDrive/SiaDriveDlg.h index 1467866..495e5d3 100644 --- a/SiaDrive/SiaDriveDlg.h +++ b/SiaDrive/SiaDriveDlg.h @@ -78,7 +78,11 @@ private: String GetWalletUnlockPassword(); void SetWalletUnlockPassword(const String& address); 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 action); void ProcessUiActionQueue(); diff --git a/SiaDrive/res/code.js b/SiaDrive/res/code.js index 5905431..06fe600 100644 --- a/SiaDrive/res/code.js +++ b/SiaDrive/res/code.js @@ -60,6 +60,26 @@ function setConsensusHeight(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) { driveList = Array.isArray(driveList) ? driveList : JSON.parse(driveList);
Funding:Total Funding: Hosts:Used Funding:
Available Funding:Host Count:
Total Space: Price (per GB):
Available Space: Download (per GB):
Used Space: Upload (per GB):