Skip to content

Commit

Permalink
Remove use of structured bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Nov 24, 2021
1 parent 69e27a1 commit 49b8094
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/masternodes/rpc_vault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,10 +1186,10 @@ UniValue estimatecollateral(const JSONRPCRequest& request) {
LOCK(cs_main);

CAmount totalLoanValue{0};
for (const auto& [tokenId, tokenAmount] : loanAmounts.balances) {
auto loanToken = pcustomcsview->GetLoanTokenByID(tokenId);
for (const auto& balance : loanAmounts.balances) {
auto loanToken = pcustomcsview->GetLoanTokenByID(balance.first);
if (!loanToken) {
throw JSONRPCError(RPC_DATABASE_ERROR, strprintf("(%d) is not a loan token!", tokenId.v));
throw JSONRPCError(RPC_DATABASE_ERROR, strprintf("(%d) is not a loan token!", balance.first.v));
}

auto priceFeed = pcustomcsview->GetFixedIntervalPrice(loanToken->fixedIntervalPriceId);
Expand All @@ -1201,23 +1201,23 @@ UniValue estimatecollateral(const JSONRPCRequest& request) {
if (!priceFeed.val->isLive(pcustomcsview->GetPriceDeviation())) {
throw JSONRPCError(RPC_MISC_ERROR, strprintf("No live fixed price for %s", loanToken->symbol));
}
totalLoanValue += MultiplyAmounts(tokenAmount, price);
totalLoanValue += MultiplyAmounts(balance.second, price);
}

uint32_t height = ::ChainActive().Height();
CBalances collateralBalances;
CAmount totalSplit{0};
for (const auto& [tokenId, splitValue] : collateralSplits) {
CAmount split = AmountFromValue(splitValue);
for (const auto& collateralSplit : collateralSplits) {
CAmount split = AmountFromValue(collateralSplit.second);

auto token = pcustomcsview->GetToken(tokenId);
auto token = pcustomcsview->GetToken(collateralSplit.first);
if (!token) {
throw JSONRPCError(RPC_DATABASE_ERROR, strprintf("Token %s does not exist!", tokenId));
throw JSONRPCError(RPC_DATABASE_ERROR, strprintf("Token %s does not exist!", collateralSplit.first));
}

auto collateralToken = pcustomcsview->HasLoanCollateralToken({token->first, height});
if (!collateralToken || !collateralToken->factor) {
throw JSONRPCError(RPC_DATABASE_ERROR, strprintf("(%s) is not a valid collateral!", tokenId));
throw JSONRPCError(RPC_DATABASE_ERROR, strprintf("(%s) is not a valid collateral!", collateralSplit.first));
}

auto priceFeed = pcustomcsview->GetFixedIntervalPrice(collateralToken->fixedIntervalPriceId);
Expand All @@ -1227,7 +1227,7 @@ UniValue estimatecollateral(const JSONRPCRequest& request) {

auto price = priceFeed.val->priceRecord[0];
if (!priceFeed.val->isLive(pcustomcsview->GetPriceDeviation())) {
throw JSONRPCError(RPC_MISC_ERROR, strprintf("No live fixed price for %s", tokenId));
throw JSONRPCError(RPC_MISC_ERROR, strprintf("No live fixed price for %s", collateralSplit.first));
}

auto requiredValue = MultiplyAmounts(totalLoanValue, split);
Expand Down

0 comments on commit 49b8094

Please sign in to comment.