Skip to content

Commit

Permalink
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/masternodes/rpc_loan.cpp
Original file line number Diff line number Diff line change
@@ -1245,10 +1245,14 @@ UniValue getloaninfo(const JSONRPCRequest& request) {
auto height = ::ChainActive().Height() + 1;
bool useNextPrice = false, requireLivePrice = true;
auto lastBlockTime = ::ChainActive().Tip()->GetBlockTime();
uint64_t totalCollateralValue = 0, totalLoanValue = 0, totalVaults = 0;
pcustomcsview->ForEachVaultCollateral([&](const CVaultId& vaultId, const CBalances& collaterals) {
uint64_t totalCollateralValue = 0, totalLoanValue = 0, totalVaults = 0, totalAuctions = 0;

pcustomcsview->ForEachVault([&](const CVaultId& vaultId, const CVaultData& data) {
LogPrint(BCLog::LOAN,"getloaninfo()->Vault(%s):\n", vaultId.GetHex());
auto rate = pcustomcsview->GetLoanCollaterals(vaultId, collaterals, height, lastBlockTime, useNextPrice, requireLivePrice);
auto collaterals = pcustomcsview->GetVaultCollaterals(vaultId);
if (!collaterals)
collaterals = CBalances{};
auto rate = pcustomcsview->GetLoanCollaterals(vaultId, *collaterals, height, lastBlockTime, useNextPrice, requireLivePrice);
if (rate)
{
totalCollateralValue += rate.val->totalCollaterals;
@@ -1258,6 +1262,11 @@ UniValue getloaninfo(const JSONRPCRequest& request) {
return true;
});

pcustomcsview->ForEachVaultAuction([&](const CVaultId& vaultId, const CAuctionData& data) {
totalAuctions++;
return true;
}, height);

UniValue totalsObj{UniValue::VOBJ};
auto totalLoanSchemes = static_cast<int>(listloanschemes(request).size());
auto totalCollateralTokens = static_cast<int>(listcollateraltokens(request).size());
@@ -1269,7 +1278,6 @@ UniValue getloaninfo(const JSONRPCRequest& request) {
totalsObj.pushKV("loanTokens", totalLoanTokens);
totalsObj.pushKV("loanValue", ValueFromUint(totalLoanValue));
totalsObj.pushKV("openVaults", totalVaults);
auto totalAuctions = static_cast<int>(listauctions(request).size());
totalsObj.pushKV("openAuctions", totalAuctions);

UniValue defaultsObj{UniValue::VOBJ};

0 comments on commit 8dfa88a

Please sign in to comment.