From a998d5d8f974fef3b1def463a289305cc7324cd9 Mon Sep 17 00:00:00 2001 From: kuegi <29012906+kuegi@users.noreply.github.com> Date: Sat, 7 Sep 2024 00:06:56 +0200 Subject: [PATCH] fix: revert wrong refactor of GetLoanTokensForFutures --- src/dfi/validation.cpp | 50 +++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/dfi/validation.cpp b/src/dfi/validation.cpp index 1c3c7501a6..897f26712e 100644 --- a/src/dfi/validation.cpp +++ b/src/dfi/validation.cpp @@ -1132,28 +1132,42 @@ static auto GetLoanTokensForFutures(CCustomCSView &cache, ATTRIBUTES attributes) LoanTokenCollection loanTokens; CDataStructureV0 tokenKey{AttributeTypes::Token, 0, TokenKeys::DFIP2203Enabled}; - attributes.ForEach( - [&](const CDataStructureV0 &attr, const CAttributeValue &) { - if (attr.type != AttributeTypes::Token) { - return false; - } + cache.ForEachLoanToken([&](const DCT_ID &id, const CLoanView::CLoanSetLoanTokenImpl &loanToken) { + tokenKey.typeId = id.v; + const auto enabled = attributes.GetValue(tokenKey, true); + if (!enabled) { + return true; + } - tokenKey.typeId = attr.typeId; - const auto enabled = attributes.GetValue(tokenKey, true); - if (!enabled) { - return true; - } + loanTokens.emplace_back(id, loanToken); - if (attr.key == TokenKeys::LoanMintingEnabled) { - auto tokenId = DCT_ID{attr.typeId}; - if (auto loanToken = cache.GetLoanTokenFromAttributes(tokenId)) { - loanTokens.emplace_back(tokenId, *loanToken); + return true; + }); + + if (loanTokens.empty()) { + attributes.ForEach( + [&](const CDataStructureV0 &attr, const CAttributeValue &) { + if (attr.type != AttributeTypes::Token) { + return false; } - } - return true; - }, - CDataStructureV0{AttributeTypes::Token}); + tokenKey.typeId = attr.typeId; + const auto enabled = attributes.GetValue(tokenKey, true); + if (!enabled) { + return true; + } + + if (attr.key == TokenKeys::LoanMintingEnabled) { + auto tokenId = DCT_ID{attr.typeId}; + if (auto loanToken = cache.GetLoanTokenFromAttributes(tokenId)) { + loanTokens.emplace_back(tokenId, *loanToken); + } + } + + return true; + }, + CDataStructureV0{AttributeTypes::Token}); + } return loanTokens; }