From e3b2ceacb7fdbbfe280a2b5566d05cbca9ac90ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNithin?= Date: Wed, 6 Sep 2023 17:09:06 +0530 Subject: [PATCH 1/2] Accept optional collection-config file while fetching approved status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “Nithin --- .../ChaincodeOperationsController.java | 9 +++++++-- .../service/ChaincodeOperationsService.java | 3 +-- .../impl/ChaincodeOperationsServiceImpl.java | 20 +++++++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/hlf/java/rest/client/controller/ChaincodeOperationsController.java b/src/main/java/hlf/java/rest/client/controller/ChaincodeOperationsController.java index b9fdc90e..a18eb0be 100644 --- a/src/main/java/hlf/java/rest/client/controller/ChaincodeOperationsController.java +++ b/src/main/java/hlf/java/rest/client/controller/ChaincodeOperationsController.java @@ -93,7 +93,9 @@ public ResponseEntity> 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) @@ -104,7 +106,10 @@ public ResponseEntity> getApprovedOrganisationListForSmartContract( Set approvedOrganizations = chaincodeOperationsService.getApprovedOrganizations( - networkName, chaincodeOperations, Optional.empty(), Optional.empty()); + networkName, + chaincodeOperations, + Optional.empty(), + Optional.ofNullable(collectionConfigFile)); return new ResponseEntity<>(approvedOrganizations, HttpStatus.OK); } diff --git a/src/main/java/hlf/java/rest/client/service/ChaincodeOperationsService.java b/src/main/java/hlf/java/rest/client/service/ChaincodeOperationsService.java index b0d28cd1..7aa94167 100644 --- a/src/main/java/hlf/java/rest/client/service/ChaincodeOperationsService.java +++ b/src/main/java/hlf/java/rest/client/service/ChaincodeOperationsService.java @@ -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; @@ -48,5 +47,5 @@ Set getApprovedOrganizations( String networkName, ChaincodeOperations chaincodeOperationsModel, Optional chaincodeEndorsementPolicyOptional, - Optional chaincodeCollectionConfigurationOptional); + Optional collectionConfigFileOptional); } diff --git a/src/main/java/hlf/java/rest/client/service/impl/ChaincodeOperationsServiceImpl.java b/src/main/java/hlf/java/rest/client/service/impl/ChaincodeOperationsServiceImpl.java index c5a23f56..9d6a9434 100644 --- a/src/main/java/hlf/java/rest/client/service/impl/ChaincodeOperationsServiceImpl.java +++ b/src/main/java/hlf/java/rest/client/service/impl/ChaincodeOperationsServiceImpl.java @@ -195,7 +195,7 @@ public Set getApprovedOrganizations( String networkName, ChaincodeOperations chaincodeOperationsModel, Optional chaincodeEndorsementPolicyOptional, - Optional chaincodeCollectionConfigurationOptional) { + Optional collectionConfigFileOptional) { Set organizationSet = new HashSet<>(); try { @@ -215,9 +215,21 @@ public Set 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( From 72e00f51b552026f1a795ce4cf881b5bb25a0484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNithin?= Date: Wed, 6 Sep 2023 18:11:51 +0530 Subject: [PATCH 2/2] Use meanigful error-code for Channel creation flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “Nithin --- src/main/java/hlf/java/rest/client/exception/ErrorCode.java | 2 ++ .../hlf/java/rest/client/service/impl/ChannelServiceImpl.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/hlf/java/rest/client/exception/ErrorCode.java b/src/main/java/hlf/java/rest/client/exception/ErrorCode.java index 697f755b..32bb9ea9 100644 --- a/src/main/java/hlf/java/rest/client/exception/ErrorCode.java +++ b/src/main/java/hlf/java/rest/client/exception/ErrorCode.java @@ -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"), diff --git a/src/main/java/hlf/java/rest/client/service/impl/ChannelServiceImpl.java b/src/main/java/hlf/java/rest/client/service/impl/ChannelServiceImpl.java index 52dfa4c9..bc38f8e4 100644 --- a/src/main/java/hlf/java/rest/client/service/impl/ChannelServiceImpl.java +++ b/src/main/java/hlf/java/rest/client/service/impl/ChannelServiceImpl.java @@ -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()); } }