Skip to content

Commit 3dcf2aa

Browse files
authored
Merge branch 'main' into fix/RA-91-extension-error-description
2 parents 21ba9ed + 4358c96 commit 3dcf2aa

30 files changed

+1322
-283
lines changed

api/pom.xml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
<properties>
1515
<spotbugs-annotations.version>4.8.3</spotbugs-annotations.version>
1616
<argLine/>
17+
<test.exclusions>
18+
**/org/openapitools/**,
19+
**/model/**,
20+
**/entity/**,
21+
**/rosetta/config/**,
22+
**/rosetta/common/enumeration/NetworkId.java,
23+
**/rosetta/common/enumeration/OperationTypeStatus.java,
24+
**/rosetta/common/enumeration/RewardType.java,
25+
**/rosetta/common/enumeration/SyncStateType.java,
26+
**/rosetta/common/enumeration/ScriptPurposetype.java,
27+
**/rosetta/api/mempool/service/MempoolServiceImpl.java,
28+
**/rosetta/common/exception/ServerException.java,
29+
**/rosetta/common/exception/Error.java,
30+
**/rosetta/common/exception/Details.java,
31+
**/rosetta/common/exception/ApiException.java
32+
</test.exclusions>
33+
<sonar.coverage.exclusions>${test.exclusions}</sonar.coverage.exclusions>
1734
</properties>
1835

1936
<packaging>jar</packaging>
@@ -328,15 +345,7 @@
328345
<version>${version.jacoco-maven-plugin}</version>
329346
<configuration>
330347
<excludes>
331-
<exclude>**/org/openapitools/**</exclude>
332-
<exclude>**/model/**</exclude>
333-
<exclude>**/entity/**</exclude>
334-
<exclude>**/rosetta/config/**</exclude>
335-
<exclude>**/rosetta/common/enumeration/NetworkId.java</exclude>
336-
<exclude>**/rosetta/common/enumeration/OperationTypeStatus.java</exclude>
337-
<exclude>**/rosetta/common/enumeration/RewardType.java</exclude>
338-
<exclude>**/rosetta/common/enumeration/ScriptPurposetype.java</exclude>
339-
<exclude>**/rosetta/common/enumeration/SyncStateType.java</exclude>
348+
<exclude>${test.exclusions}</exclude>
340349
</excludes>
341350
</configuration>
342351
<executions>

api/src/main/java/org/cardanofoundation/rosetta/api/construction/service/ConstructionApiServiceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.cardanofoundation.rosetta.common.enumeration.AddressType;
4646
import org.cardanofoundation.rosetta.common.enumeration.NetworkEnum;
4747
import org.cardanofoundation.rosetta.common.enumeration.NetworkIdentifierType;
48-
import org.cardanofoundation.rosetta.common.exception.ApiException;
4948
import org.cardanofoundation.rosetta.common.exception.ExceptionFactory;
5049
import org.cardanofoundation.rosetta.common.mapper.CborMapToTransactionExtraData;
5150
import org.cardanofoundation.rosetta.common.mapper.DataMapper;
@@ -237,7 +236,7 @@ public ConstructionCombineResponse constructionCombineService(
237236
CborEncodeUtil.encodeExtraData(signedTransaction, extraData.operations(),
238237
extraData.transactionMetadataHex()));
239238
} catch (CborException e) {
240-
throw new ApiException("Error while encoding signed transaction", e);
239+
throw ExceptionFactory.cantEncodeExtraData();
241240
}
242241
}
243242

api/src/main/java/org/cardanofoundation/rosetta/api/network/controller/NetworkApiDelegate.java

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import io.swagger.v3.oas.annotations.media.Content;
99
import io.swagger.v3.oas.annotations.responses.ApiResponse;
1010
import io.swagger.v3.oas.annotations.tags.Tag;
11-
import org.openapitools.client.model.*;
12-
13-
import org.cardanofoundation.rosetta.common.exception.ServerException;
11+
import org.openapitools.client.model.MetadataRequest;
12+
import org.openapitools.client.model.NetworkListResponse;
13+
import org.openapitools.client.model.NetworkOptionsResponse;
14+
import org.openapitools.client.model.NetworkRequest;
15+
import org.openapitools.client.model.NetworkStatusResponse;
1416

1517
/**
1618
* @author Sotatek-HoangNguyen9
@@ -20,50 +22,50 @@
2022
public interface NetworkApiDelegate {
2123

2224
@Operation(
23-
operationId = "networkList",
24-
summary = "Network endpoints are used when first connecting to a Rosetta endpoint to determine which network and sub-networks are supported.",
25-
responses = {
26-
@ApiResponse(responseCode = "200", description = "", content = @Content(mediaType = "application/json")),
27-
@ApiResponse(responseCode = "400", description = "Invalid `body`")
28-
}
25+
operationId = "networkList",
26+
summary = "Network endpoints are used when first connecting to a Rosetta endpoint to determine which network and sub-networks are supported.",
27+
responses = {
28+
@ApiResponse(responseCode = "200", description = "", content = @Content(mediaType = "application/json")),
29+
@ApiResponse(responseCode = "400", description = "Invalid `body`")
30+
}
2931
)
3032
@PostMapping(
31-
value = "/network/list",
32-
produces = { "application/json;charset=utf-8" },
33-
consumes = { "application/json;charset=utf-8" }
33+
value = "/network/list",
34+
produces = {"application/json;charset=utf-8"},
35+
consumes = {"application/json;charset=utf-8"}
3436
)
3537
ResponseEntity<NetworkListResponse> networkList(MetadataRequest metadataRequest)
3638
throws IOException;
3739

3840
@Operation(
39-
operationId = "networkOptions",
40-
summary = "This endpoint returns the version information and allowed network-specific types for a NetworkIdentifier.",
41-
responses = {
42-
@ApiResponse(responseCode = "200", description = "", content = @Content(mediaType = "application/json")),
43-
@ApiResponse(responseCode = "400", description = "Invalid `body`")
44-
}
41+
operationId = "networkOptions",
42+
summary = "This endpoint returns the version information and allowed network-specific types for a NetworkIdentifier.",
43+
responses = {
44+
@ApiResponse(responseCode = "200", description = "", content = @Content(mediaType = "application/json")),
45+
@ApiResponse(responseCode = "400", description = "Invalid `body`")
46+
}
4547
)
4648
@PostMapping(
47-
value = "/network/options",
48-
produces = { "application/json;charset=utf-8" },
49-
consumes = { "application/json;charset=utf-8" }
49+
value = "/network/options",
50+
produces = {"application/json;charset=utf-8"},
51+
consumes = {"application/json;charset=utf-8"}
5052
)
5153
ResponseEntity<NetworkOptionsResponse> networkOptions(NetworkRequest networkRequest)
5254
throws IOException, InterruptedException;
5355

5456
@Operation(
55-
operationId = "networkStatus",
56-
summary = "This endpoint returns the current status of the network requested.",
57-
responses = {
58-
@ApiResponse(responseCode = "200", description = "", content = @Content(mediaType = "application/json")),
59-
@ApiResponse(responseCode = "400", description = "Invalid `body`")
60-
}
57+
operationId = "networkStatus",
58+
summary = "This endpoint returns the current status of the network requested.",
59+
responses = {
60+
@ApiResponse(responseCode = "200", description = "", content = @Content(mediaType = "application/json")),
61+
@ApiResponse(responseCode = "400", description = "Invalid `body`")
62+
}
6163
)
6264
@PostMapping(
63-
value = "/network/status",
64-
produces = { "application/json;charset=utf-8" },
65-
consumes = { "application/json;charset=utf-8" }
65+
value = "/network/status",
66+
produces = {"application/json;charset=utf-8"},
67+
consumes = {"application/json;charset=utf-8"}
6668
)
6769
ResponseEntity<NetworkStatusResponse> networkStatus(NetworkRequest networkRequest)
68-
throws ServerException, IOException;
70+
throws IOException;
6971
}

api/src/main/java/org/cardanofoundation/rosetta/api/network/controller/NetworkApiDelegateImplementation.java

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,42 @@
77
import org.springframework.http.ResponseEntity;
88
import org.springframework.web.bind.annotation.RequestBody;
99
import org.springframework.web.bind.annotation.RestController;
10-
import org.openapitools.client.model.*;
10+
import org.openapitools.client.model.MetadataRequest;
11+
import org.openapitools.client.model.NetworkListResponse;
12+
import org.openapitools.client.model.NetworkOptionsResponse;
13+
import org.openapitools.client.model.NetworkRequest;
14+
import org.openapitools.client.model.NetworkStatusResponse;
1115

1216
import org.cardanofoundation.rosetta.api.network.service.NetworkService;
1317

1418
@RestController
1519
@RequiredArgsConstructor
1620
public class NetworkApiDelegateImplementation implements NetworkApiDelegate {
1721

18-
private final NetworkService networkService;
19-
20-
@Override
21-
public ResponseEntity<NetworkListResponse> networkList(@RequestBody MetadataRequest metadataRequest)
22-
throws IOException {
23-
final NetworkListResponse networkListResponse = networkService.getNetworkList(metadataRequest);
24-
return ResponseEntity.ok(networkListResponse);
25-
}
26-
27-
@Override
28-
public ResponseEntity<NetworkOptionsResponse> networkOptions(@RequestBody NetworkRequest networkRequest)
29-
throws IOException, InterruptedException {
30-
final NetworkOptionsResponse networkOptionsResponse = networkService.getNetworkOptions(networkRequest);
31-
return ResponseEntity.ok(networkOptionsResponse);
32-
}
33-
34-
@Override
35-
public ResponseEntity<NetworkStatusResponse> networkStatus(@RequestBody NetworkRequest networkRequest)
36-
throws IOException {
37-
final NetworkStatusResponse networkStatusResponse = networkService.getNetworkStatus(networkRequest);
38-
return ResponseEntity.ok(networkStatusResponse);
39-
}
22+
private final NetworkService networkService;
23+
24+
@Override
25+
public ResponseEntity<NetworkListResponse> networkList(
26+
@RequestBody MetadataRequest metadataRequest) throws IOException {
27+
final NetworkListResponse networkListResponse = networkService.getNetworkList(metadataRequest);
28+
return ResponseEntity.ok(networkListResponse);
29+
}
30+
31+
@Override
32+
public ResponseEntity<NetworkOptionsResponse> networkOptions(
33+
@RequestBody NetworkRequest networkRequest) throws IOException, InterruptedException {
34+
networkService.verifyNetworkRequest(networkRequest.getNetworkIdentifier());
35+
final NetworkOptionsResponse networkOptionsResponse = networkService.getNetworkOptions(
36+
networkRequest);
37+
return ResponseEntity.ok(networkOptionsResponse);
38+
}
39+
40+
@Override
41+
public ResponseEntity<NetworkStatusResponse> networkStatus(
42+
@RequestBody NetworkRequest networkRequest) throws IOException {
43+
networkService.verifyNetworkRequest(networkRequest.getNetworkIdentifier());
44+
final NetworkStatusResponse networkStatusResponse = networkService.getNetworkStatus(
45+
networkRequest);
46+
return ResponseEntity.ok(networkStatusResponse);
47+
}
4048
}

api/src/main/java/org/cardanofoundation/rosetta/common/exception/ApiException.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ public class ApiException extends RuntimeException {
99

1010
@Serial
1111
private static final long serialVersionUID = 7966468689369382174L;
12-
private Error error;
12+
private final Error error;
1313

1414
public ApiException(Error error) {
1515
super();
1616
this.error = error;
1717
}
18-
19-
public ApiException(String message, Throwable throwable) {
20-
super(message, throwable);
21-
}
22-
2318
}

api/src/main/java/org/cardanofoundation/rosetta/common/exception/ExceptionFactory.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.cardanofoundation.rosetta.common.exception;
22

3-
43
import static org.cardanofoundation.rosetta.common.util.RosettaConstants.RosettaErrorType;
54

65

@@ -48,10 +47,6 @@ public static ApiException cantCreateSignTransaction() {
4847
return new ApiException(RosettaErrorType.CANT_CREATE_SIGN_TRANSACTION.toRosettaError(false));
4948
}
5049

51-
public static ApiException cantBuildSignedTransaction() {
52-
return new ApiException(RosettaErrorType.CANT_CREATE_SIGN_TRANSACTION.toRosettaError(false));
53-
}
54-
5550
public static ApiException missingChainCodeError() {
5651
return new ApiException(RosettaErrorType.CHAIN_CODE_MISSING.toRosettaError(false));
5752
}
@@ -242,7 +237,7 @@ public static ApiException submitRejected(String detail) {
242237
Details.builder().message(detail).build()));
243238
}
244239

245-
public static ApiException outPutTooLow() {
240+
public static ApiException outputTooLow() {
246241
return unspecifiedError("The outputAmount is too low. Try with more funds.");
247242
}
248243

@@ -256,7 +251,7 @@ public static ApiException invalidNetworkError() {
256251
return new ApiException(RosettaErrorType.INVALID_NETWORK.toRosettaError(false));
257252
}
258253

259-
public static ApiException cantDecodeMempoolTransaction() {
254+
public static ApiException cantDecodeMemPoolTransaction() {
260255
return new ApiException(RosettaErrorType.CANT_DECODE_MEMPOOL_TRANSACTION.toRosettaError(false));
261256
}
262257

api/src/main/java/org/cardanofoundation/rosetta/common/exception/ServerException.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

api/src/main/java/org/cardanofoundation/rosetta/common/model/entity/BaseEntity.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

api/src/main/java/org/cardanofoundation/rosetta/common/services/impl/ProtocolParamServiceImpl.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
import org.springframework.beans.factory.annotation.Value;
1010
import org.springframework.stereotype.Service;
11+
import com.fasterxml.jackson.core.JsonProcessingException;
1112
import com.fasterxml.jackson.databind.ObjectMapper;
1213
import org.json.JSONObject;
1314

1415
import org.cardanofoundation.rosetta.api.block.model.domain.ProtocolParams;
1516
import org.cardanofoundation.rosetta.api.block.model.entity.ProtocolParamsEntity;
1617
import org.cardanofoundation.rosetta.api.block.model.repository.EpochParamRepository;
17-
import org.cardanofoundation.rosetta.common.exception.ApiException;
1818
import org.cardanofoundation.rosetta.common.exception.ExceptionFactory;
1919
import org.cardanofoundation.rosetta.common.mapper.ProtocolParamsToEntity;
2020
import org.cardanofoundation.rosetta.common.services.ProtocolParamService;
@@ -43,20 +43,13 @@ public ProtocolParams getProtocolParameters() {
4343
log.error("Error reading genesis shelley file: {}", genesisShelleyPath);
4444
throw ExceptionFactory.configNotFoundException();
4545
}
46-
4746
}
4847

49-
private ProtocolParams fromJSONObject(JSONObject shelleyJsonObject) {
50-
48+
private ProtocolParams fromJSONObject(JSONObject shelleyJsonObject)
49+
throws JsonProcessingException {
5150
var params = shelleyJsonObject.getJSONObject("protocolParams");
52-
53-
try {
54-
String s = Optional.ofNullable(params).map(JSONObject::toString).orElse("{}");
55-
return objectMapper.readValue(s, ProtocolParams.class);
56-
} catch (Exception e) {
57-
throw new ApiException("Error parsing protocol parameters", e);
58-
}
59-
51+
String s = Optional.ofNullable(params).map(JSONObject::toString).orElse("{}");
52+
return objectMapper.readValue(s, ProtocolParams.class);
6053
}
6154

6255
@Override
@@ -66,5 +59,4 @@ public ProtocolParams findProtocolParametersFromIndexerAndConfig() {
6659
ProtocolParams protocolParametersFromConfigFile = getProtocolParameters();
6760
return mapperProtocolParams.merge(protocolParams, protocolParametersFromConfigFile);
6861
}
69-
7062
}

0 commit comments

Comments
 (0)