Skip to content

Commit

Permalink
fix: cannot search DRep
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-ThinhVu committed May 3, 2024
1 parent 7292a3d commit 1befbe2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class SearchResponse {
private PoolSearchResponse pool;
private boolean validPoolName;
private ScriptSearchResponse script;
private String dRep;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.cardanofoundation.explorer.api.model.response.search.ScriptSearchResponse;
import org.cardanofoundation.explorer.api.model.response.search.SearchResponse;
import org.cardanofoundation.explorer.api.model.response.search.TokenSearchResponse;
import org.cardanofoundation.explorer.api.repository.explorer.DrepInfoRepository;
import org.cardanofoundation.explorer.api.repository.ledgersync.BlockRepository;
import org.cardanofoundation.explorer.api.repository.ledgersync.EpochRepository;
import org.cardanofoundation.explorer.api.repository.ledgersync.MultiAssetRepository;
Expand All @@ -28,6 +29,7 @@
import org.cardanofoundation.explorer.api.service.SearchService;
import org.cardanofoundation.explorer.api.util.AddressUtils;
import org.cardanofoundation.explorer.common.entity.enumeration.ScriptType;
import org.cardanofoundation.explorer.common.entity.explorer.DRepInfo;
import org.cardanofoundation.explorer.common.entity.ledgersync.Block;
import org.cardanofoundation.explorer.common.entity.ledgersync.MultiAsset;
import org.cardanofoundation.explorer.common.entity.ledgersync.Script;
Expand All @@ -43,6 +45,7 @@ public class SearchServiceImpl implements SearchService {
private final PoolHashRepository poolHashRepository;
private final StakeAddressRepository stakeAddressRepository;
private final ScriptRepository scriptRepository;
private final DrepInfoRepository drepInfoRepository;

@Value("${application.network}")
private String network;
Expand All @@ -59,9 +62,15 @@ public SearchResponse search(String query) {
searchAddress(rawQuery, searchResponse);
searchPool(query, searchResponse);
searchScriptHash(query, searchResponse);
searchDRep(query, searchResponse);
return searchResponse;
}

private void searchDRep(String query, SearchResponse searchResponse) {
Optional<DRepInfo> dRepInfo = drepInfoRepository.findByDRepHashOrDRepId(query);
dRepInfo.ifPresent(repInfo -> searchResponse.setDRep(repInfo.getDrepId()));
}

private void searchEpoch(String query, SearchResponse searchResponse) {
try {
Integer epochNo = Integer.parseInt(query);
Expand Down

0 comments on commit 1befbe2

Please sign in to comment.