Skip to content

Commit

Permalink
Merge pull request #1133 from cardano-foundation/1.1.0
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
nemo83 committed Apr 30, 2024
2 parents f9417f0 + f9310a0 commit 4fa8364
Show file tree
Hide file tree
Showing 66 changed files with 2,995 additions and 73 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<version.sonarcube-maven-plugin>3.9.1.2184</version.sonarcube-maven-plugin>
<version.maven-project-info-reports-plugin>3.3.0</version.maven-project-info-reports-plugin>
<version.maven-site-plugin>4.0.0-M2</version.maven-site-plugin>
<version.spring-boot>3.1.6</version.spring-boot>
<version.spring-boot>3.0.5</version.spring-boot>
<version.bloxbean>0.4.3</version.bloxbean>
<version.lombok>1.18.26</version.lombok>
<version.springdoc-starter>2.1.0</version.springdoc-starter>
Expand All @@ -67,7 +67,7 @@
<version.snakeyaml>2.0</version.snakeyaml>
<version.mapstruct>1.5.3.Final</version.mapstruct>
<version.lombok-mapstruct-binding>0.2.0</version.lombok-mapstruct-binding>
<version.explorer-common>0.1.16-SNAPSHOT-PR173</version.explorer-common>
<version.explorer-common>0.9.0-PR196</version.explorer-common>
<sonar.coverage.jacoco.xmlReportPaths>../cardano-explorer-api/target/site/jacoco-aggregate/jacoco.xml
</sonar.coverage.jacoco.xmlReportPaths>
<sonar.coverage.exclusions>**/entity/*, **/validation/*</sonar.coverage.exclusions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.cardanofoundation.explorer.api.common.enumeration;

import java.util.HashMap;
import java.util.Map;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;

@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@RequiredArgsConstructor
@Getter
public enum GovActionStatus {
ANY("ANY"),
OPEN_BALLOT("OPEN_BALLOT"),
RATIFIED("RATIFIED"),
ENACTED("ENACTED"),
EXPIRED("EXPIRED");

String value;

private static final Map<String, GovActionStatus> govActionStatusMap = new HashMap<>();

static {
for (GovActionStatus type : GovActionStatus.values()) {
govActionStatusMap.put(type.value, type);
}
}

public static GovActionStatus fromValue(String value) {
return govActionStatusMap.get(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.cardanofoundation.explorer.api.common.enumeration;

import java.util.HashMap;
import java.util.Map;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;

@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@RequiredArgsConstructor
@Getter
public enum GovActionType {
PARAMETER_CHANGE_ACTION("PARAMETER_CHANGE_ACTION"),
HARD_FORK_INITIATION_ACTION("HARD_FORK_INITIATION_ACTION"),
TREASURY_WITHDRAWALS_ACTION("TREASURY_WITHDRAWALS_ACTION"),
NO_CONFIDENCE("NO_CONFIDENCE"),
UPDATE_COMMITTEE("UPDATE_COMMITTEE"),
NEW_CONSTITUTION("NEW_CONSTITUTION"),
INFO_ACTION("INFO_ACTION"),
ALL("ALL");
String value;

private static final Map<String, GovActionType> govActionTypeMap = new HashMap<>();

static {
for (GovActionType type : GovActionType.values()) {
govActionTypeMap.put(type.value, type);
}
}

public static GovActionType fromValue(String value) {
return govActionTypeMap.get(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public enum TxPurposeType {
MINT,
CERT,
REWARD,
VOTE,
PROPOSE,
ANY, // all types above
NO_TX_PURPOSE // no tx purpose
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.cardanofoundation.explorer.api.common.enumeration;

import java.util.HashMap;
import java.util.Map;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;

@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@RequiredArgsConstructor
@Getter
public enum VoteType {
NO("NO"),
YES("YES"),
ABSTAIN("ABSTAIN"),
ANY("ANY"),
NONE("NONE");

String value;

private static final Map<String, VoteType> voteTypeMap = new HashMap<>();

static {
for (VoteType type : VoteType.values()) {
voteTypeMap.put(type.value, type);
}
}

public static VoteType fromValue(String value) {
return voteTypeMap.get(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.cardanofoundation.explorer.api.controller;

import jakarta.validation.Valid;

import lombok.RequiredArgsConstructor;

import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;

import org.cardanofoundation.explorer.api.common.enumeration.GovActionType;
import org.cardanofoundation.explorer.api.config.LogMessage;
import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse;
import org.cardanofoundation.explorer.api.model.response.drep.DRepCertificateHistoryResponse;
import org.cardanofoundation.explorer.api.model.response.drep.DRepDelegatorsResponse;
import org.cardanofoundation.explorer.api.model.response.drep.DRepDetailsResponse;
import org.cardanofoundation.explorer.api.model.response.drep.VotingProcedureChartResponse;
import org.cardanofoundation.explorer.api.service.DRepService;
import org.cardanofoundation.explorer.common.validation.pagination.Pagination;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationDefault;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationValid;

@RestController
@RequestMapping("/api/v1/dreps")
@RequiredArgsConstructor
@Validated
@Tag(name = "dRep", description = "The delegated representatives APIs")
public class DRepController {

private final DRepService dRepService;

@GetMapping("/{drepHashOrDrepId}/certificates-history")
@LogMessage
@Operation(
summary = "Get list of DRep certificate history",
tags = {"dRep"})
public ResponseEntity<BaseFilterResponse<DRepCertificateHistoryResponse>>
getTxDRepCertificatesHistory(
@PathVariable @Parameter(description = "The DRep id or DRep hash")
String drepHashOrDrepId,
@ParameterObject
@PaginationValid
@PaginationDefault(
size = 20,
sort = {"createdAt"},
direction = Sort.Direction.DESC)
Pagination pagination) {
return ResponseEntity.ok(
dRepService.getTxDRepCertificateHistory(drepHashOrDrepId, pagination.toPageable()));
}

@GetMapping("/{dRepHashOrId}/vote-procedure-chart")
@LogMessage
@Operation(
summary = "Get chart of DRep vote on Governance Action",
tags = {"dRep"})
public ResponseEntity<VotingProcedureChartResponse> getChartOfDRepVotesOnGovernanceAction(
@PathVariable @Parameter(description = "The DRep hash or id") String dRepHashOrId,
@RequestParam(value = "govActionType")
@Parameter(description = "The type of Governance Action")
GovActionType govActionType) {
return ResponseEntity.ok(dRepService.getVoteProcedureChart(dRepHashOrId, govActionType));
}

@GetMapping("/{dRepHashOrDRepId}/drep-details")
@LogMessage
@Operation(
summary = "Get details of Delegated Representative (DRep)",
tags = {"dRep"})
public ResponseEntity<DRepDetailsResponse> getDRepDetails(
@Valid @PathVariable @Parameter(description = "The DRep id or DRep hash")
String dRepHashOrDRepId) {
return ResponseEntity.ok(dRepService.getDRepDetails(dRepHashOrDRepId));
}

@GetMapping("/{dRepHashOrDRepId}/get-delegation")
@LogMessage
@Operation(
summary = "Get stake that delegated to Delegated Representative (DRep)",
tags = {"dRep"})
public ResponseEntity<BaseFilterResponse<DRepDelegatorsResponse>> getDRepDelegation(
@Valid @PathVariable @Parameter(description = "dRepHashOrDRepId") String dRepHashOrDRepId,
@ParameterObject @PaginationValid @Valid Pagination pagination) {
return ResponseEntity.ok(
dRepService.getDRepDelegators(dRepHashOrDRepId, pagination.toPageable()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.cardanofoundation.explorer.api.controller;

import jakarta.validation.Valid;

import lombok.RequiredArgsConstructor;

import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;

import org.cardanofoundation.explorer.api.config.LogMessage;
import org.cardanofoundation.explorer.api.model.request.governanceAction.GovernanceActionFilter;
import org.cardanofoundation.explorer.api.model.request.governanceAction.GovernanceActionRequest;
import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse;
import org.cardanofoundation.explorer.api.model.response.governanceAction.GovernanceActionDetailsResponse;
import org.cardanofoundation.explorer.api.model.response.governanceAction.GovernanceActionResponse;
import org.cardanofoundation.explorer.api.model.response.governanceAction.VotingChartResponse;
import org.cardanofoundation.explorer.api.service.GovernanceActionService;
import org.cardanofoundation.explorer.common.validation.pagination.Pagination;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationDefault;
import org.cardanofoundation.explorer.common.validation.pagination.PaginationValid;

@RestController
@RequestMapping("/api/v1/gov-actions")
@RequiredArgsConstructor
@Validated
@Tag(name = "gov-actions", description = "The governance action APIs")
public class GovernanceActionController {

private final GovernanceActionService governanceActionService;

@GetMapping("{dRepHashOrPoolHash}")
@LogMessage
@Operation(
summary = "Get governance action that vote by DRep or pool",
tags = {"gov-actions"})
public ResponseEntity<BaseFilterResponse<GovernanceActionResponse>> getGovActionByFilter(
@PathVariable @Parameter(description = "The DRep hash or pool hash or pool view")
String dRepHashOrPoolHash,
@ParameterObject GovernanceActionFilter governanceActionFilter,
@ParameterObject
@PaginationValid
@PaginationDefault(
size = 20,
sort = {"blockTime"},
direction = Sort.Direction.DESC)
@Valid
Pagination pagination) {
return ResponseEntity.ok(
governanceActionService.getGovernanceActions(
dRepHashOrPoolHash, governanceActionFilter, pagination.toPageable()));
}

@GetMapping("{dRepHashOrPoolHash}/voting-procedure-detail")
@LogMessage
@Operation(
summary = "Get governance action that vote by DRep or pool",
tags = {"gov-actions"})
public ResponseEntity<GovernanceActionDetailsResponse> getGovActionByTxHashAndVoterHash(
@PathVariable @Parameter(description = "The DRep hash or pool hash")
String dRepHashOrPoolHash,
@ParameterObject GovernanceActionRequest governanceActionRequest) {
return ResponseEntity.ok(
governanceActionService.getGovernanceActionDetails(
dRepHashOrPoolHash, governanceActionRequest));
}

@GetMapping("voting-chart")
@LogMessage
@Operation(
summary = "Get voting chart of governance action",
tags = {"gov-actions"})
public ResponseEntity<VotingChartResponse> getVotingChartByGovAction(
@RequestParam @Parameter(description = "The tx hash of governance action") String txHash,
@RequestParam @Parameter(description = "The index of governance action") Integer index) {
return ResponseEntity.ok(
governanceActionService.getVotingChartByGovActionTxHashAndIndex(txHash, index));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public enum BusinessCode implements ErrorCode {
REPORT_LIMIT_REACHED("400-REPORT_LIMIT_REACHED", "Report limit reached"),
OUT_OF_QUERY_LIMIT("400-OUT_OF_QUERY_LIMIT", "Out of query limit"),
EXTERNAL_API_IS_NOT_AVAILABLE(
"500-EXTERNAL_API_IS_NOT_AVAILABLE", "External API is not available");
"500-EXTERNAL_API_IS_NOT_AVAILABLE", "External API is not available"),

GOVERNANCE_ACTION_NOT_FOUND("404-GOVERNANCE_ACTION_NOT_FOUND", "Governance action not found"),
DREP_NOT_FOUND("404-DREP_NOT_FOUND", "DRep not found");

private final String code;
private final String desc;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.cardanofoundation.explorer.api.mapper;

import java.util.Date;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import org.cardanofoundation.explorer.api.model.response.drep.DRepCertificateHistoryResponse;
import org.cardanofoundation.explorer.api.model.response.drep.projection.DRepCertificateProjection;

@Mapper(componentModel = "spring")
public interface DRepCertificateMapper {

@Mapping(source = "blockTime", target = "createdAt")
DRepCertificateHistoryResponse fromDRepCertProjection(
DRepCertificateProjection dRepCertificateProjection);

default Date fromLong(Long value) {
return value == null ? null : new Date(value * 1000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.cardanofoundation.explorer.api.mapper;

import java.util.Date;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import org.cardanofoundation.explorer.api.model.response.drep.DRepDelegatorsResponse;
import org.cardanofoundation.explorer.api.model.response.drep.DRepDetailsResponse;
import org.cardanofoundation.explorer.api.projection.DRepDelegatorProjection;
import org.cardanofoundation.explorer.common.entity.explorer.DRepInfo;

@Mapper(componentModel = "spring")
public interface DRepMapper {
@Mapping(target = "createdAt", expression = "java(fromLong(dRepInfo.getCreatedAt()))")
DRepDetailsResponse fromDrepInfo(DRepInfo dRepInfo);

@Mapping(
target = "createdAt",
expression = "java(fromLong(dRepDelegatorProjection.getBlockTime()))")
DRepDelegatorsResponse fromDRepDelegatorProjection(
DRepDelegatorProjection dRepDelegatorProjection);

default Date fromLong(Long value) {
return value == null ? null : new Date(value * 1000);
}
}

0 comments on commit 4fa8364

Please sign in to comment.