Skip to content

Commit

Permalink
fix: revert wrong refactor of GetLoanTokensForFutures
Browse files Browse the repository at this point in the history
  • Loading branch information
kuegi committed Sep 6, 2024
1 parent ee07796 commit a998d5d
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a998d5d

Please sign in to comment.