From 531472fdb8791d5bb7f13480a4674f000c3c7ddc Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 18 Feb 2017 12:46:33 -0600 Subject: [PATCH] Renter display --- SiaDrive.Api/SiaApi.h | 5 +++ SiaDrive.Api/SiaRenter.cpp | 71 +++++++++++++++++++++++++++++++++++++ SiaDrive/SiaDrive.htm | 19 ++++++---- SiaDrive/SiaDrive.rc | Bin 11706 -> 11706 bytes SiaDrive/SiaDriveDlg.cpp | 50 +++++++++++++++++++++++++- SiaDrive/SiaDriveDlg.h | 6 +++- SiaDrive/res/code.js | 20 +++++++++++ 7 files changed, 163 insertions(+), 8 deletions(-) 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 f9f47327103577b6276e984e1c3e1201b60e3126..4fbdee246cf528869a864847758aacdd2ae9b2ab 100644 GIT binary patch delta 31 ncmdlLy(@Zymk6W9GetFunds(); + 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):