Skip to content

Commit

Permalink
Accept optional collection-config file while fetching approved status (
Browse files Browse the repository at this point in the history
…#102)

* Accept optional collection-config file while fetching approved status

Signed-off-by: “Nithin <nithin.pankaj@walmartlabs.com>

* Use meanigful error-code for Channel creation flow

Signed-off-by: “Nithin <nithin.pankaj@walmartlabs.com>

---------

Signed-off-by: “Nithin <nithin.pankaj@walmartlabs.com>
Co-authored-by: “Nithin <nithin.pankaj@walmartlabs.com>
  • Loading branch information
nithin-pankaj and “Nithin authored Sep 6, 2023
1 parent fec0f12 commit 79d6c2b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public ResponseEntity<Set<String>> getApprovedOrganisationListForSmartContract(
@RequestParam("chaincode_name") String chaincodeName,
@RequestParam("chaincode_version") String chaincodeVersion,
@RequestParam("sequence") Long sequence,
@RequestParam(value = "init_required", defaultValue = "false") boolean initRequired) {
@RequestParam(value = "init_required", defaultValue = "false") boolean initRequired,
@RequestPart(value = "collection_config", required = false)
MultipartFile collectionConfigFile) {
ChaincodeOperations chaincodeOperations =
ChaincodeOperations.builder()
.chaincodeName(chaincodeName)
Expand All @@ -104,7 +106,10 @@ public ResponseEntity<Set<String>> getApprovedOrganisationListForSmartContract(

Set<String> approvedOrganizations =
chaincodeOperationsService.getApprovedOrganizations(
networkName, chaincodeOperations, Optional.empty(), Optional.empty());
networkName,
chaincodeOperations,
Optional.empty(),
Optional.ofNullable(collectionConfigFile));

return new ResponseEntity<>(approvedOrganizations, HttpStatus.OK);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hlf/java/rest/client/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum ErrorCode {
CHAINCODE_PACKAGE_ID_VALIDATION_FAILED(
1005, "The chaincode packageId is not same in all the peers or not present."),

CHANNEL_CREATION_FAILED(3000, "Failed to create Channel"),

CHANNEL_JOIN_FAILED(3006, "Failed to join channel"),

CHANNEL_CREATION_MISSING_ORDERER(4000, "Orderer is missing"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import hlf.java.rest.client.model.ChaincodeOperationsType;
import java.util.Optional;
import java.util.Set;
import org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration;
import org.hyperledger.fabric.sdk.LifecycleChaincodeEndorsementPolicy;
import org.springframework.web.multipart.MultipartFile;

Expand Down Expand Up @@ -48,5 +47,5 @@ Set<String> getApprovedOrganizations(
String networkName,
ChaincodeOperations chaincodeOperationsModel,
Optional<LifecycleChaincodeEndorsementPolicy> chaincodeEndorsementPolicyOptional,
Optional<ChaincodeCollectionConfiguration> chaincodeCollectionConfigurationOptional);
Optional<MultipartFile> collectionConfigFileOptional);
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public Set<String> getApprovedOrganizations(
String networkName,
ChaincodeOperations chaincodeOperationsModel,
Optional<LifecycleChaincodeEndorsementPolicy> chaincodeEndorsementPolicyOptional,
Optional<ChaincodeCollectionConfiguration> chaincodeCollectionConfigurationOptional) {
Optional<MultipartFile> collectionConfigFileOptional) {
Set<String> organizationSet = new HashSet<>();
try {

Expand All @@ -215,9 +215,21 @@ public Set<String> getApprovedOrganizations(
lifecycleCheckCommitReadinessRequest.setChaincodeEndorsementPolicy(
chaincodeEndorsementPolicyOptional.get());
}
if (chaincodeCollectionConfigurationOptional.isPresent()) {
lifecycleCheckCommitReadinessRequest.setChaincodeCollectionConfiguration(
chaincodeCollectionConfigurationOptional.get());

if (collectionConfigFileOptional.isPresent()) {

try (InputStream inputStream = collectionConfigFileOptional.get().getInputStream()) {

ChaincodeCollectionConfiguration chaincodeCollectionConfiguration =
ChaincodeCollectionConfiguration.fromJsonStream(inputStream);

lifecycleCheckCommitReadinessRequest.setChaincodeCollectionConfiguration(
chaincodeCollectionConfiguration);
} catch (ChaincodeCollectionConfigurationException | IOException e) {
throw new ServiceException(
ErrorCode.DESERIALIZATION_FAILURE,
"Error occurred while extracting details from the uploaded Collection-Config file");
}
}

lifecycleCheckCommitReadinessRequest.setInitRequired(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ClientResponseModel createChannel(ChannelOperationRequest channelOperatio
} catch (Exception e) {
log.error("Error in creating new channel: ", e);
throw new ChannelOperationException(
ErrorCode.CHANNEL_JOIN_FAILED, "channel creation failed", e.getCause());
ErrorCode.CHANNEL_CREATION_FAILED, "channel creation failed", e.getCause());
}
}

Expand Down

0 comments on commit 79d6c2b

Please sign in to comment.