[#issue-395] implement query_approved and check_commit_readiness function
implement query_approved and check_commit_readiness function of chaincode.
Close
@@ -243,6 +243,77 @@ class ChainCodeViewSet(viewsets.ViewSet):
ok("success"), status=status.HTTP_200_OK
)
+ @swagger_auto_schema(
+ method="get",
+ responses=with_common_response(
+ {status.HTTP_201_CREATED: ChainCodeIDSerializer}
+ ),
+ )
+ @action(detail=False, methods=['get'])
+ def query_approved(self, request):
+ try:
+ org = request.user.organization
+ peer_node = Node.objects.get(type="peer", organization=org.id)
+ envs = init_env_vars(peer_node, org)
+
+ channel_name = request.data.get("channel_name")
+ cc_name = request.data.get("cc_name")
+
+ peer_channel_cli = PeerChainCode("v2.2.0", **envs)
+ code, content = peer_channel_cli.lifecycle_query_approved(channel_name, cc_name)
+ if code != 0:
+ return Response(err("query_approved failed."), status=status.HTTP_400_BAD_REQUEST)
+
+ except Exception as e:
+ return Response(
+ err(e.args), status=status.HTTP_400_BAD_REQUEST
+ )
+ return Response(
+ ok(content), status=status.HTTP_200_OK
+ )
+
+ @swagger_auto_schema(
+ method="post",
+ responses=with_common_response(
+ {status.HTTP_201_CREATED: ChainCodeIDSerializer}
+ ),
+ )
+ @action(detail=False, methods=['post'])
+ def check_commit_readiness(self, request):
+ serializer = ChainCodeApproveForMyOrgBody(data=request.data)
+ if serializer.is_valid(raise_exception=True):
+ try:
+ channel_name = serializer.validated_data.get("channel_name")
+ chaincode_name = serializer.validated_data.get("chaincode_name")
+ chaincode_version = serializer.validated_data.get("chaincode_version")
+ policy = serializer.validated_data.get("policy")
+ # Perhaps the orderer's port is best stored in the database
+ orderer_url = serializer.validated_data.get("orderer_url")
+ sequence = serializer.validated_data.get("sequence")
+ org = request.user.organization
+ orderer_node = Node.objects.get(type="orderer", organization=org.id)
+
+ orderer_tls_dir = "{}/{}/crypto-config/ordererOrganizations/{}/orderers/{}/msp/tlscacerts" \
+ .format(CELLO_HOME, org.name, org.name.split(".", 1)[1], orderer_node.name + "." +
+ org.name.split(".", 1)[1])
+
+ peer_node = Node.objects.get(type="peer", organization=org.id)
+ envs = init_env_vars(peer_node, org)
+
+ peer_channel_cli = PeerChainCode("v2.2.0", **envs)
+ code, content = peer_channel_cli.lifecycle_check_commit_readiness(orderer_url, orderer_tls_dir, channel_name, chaincode_name, chaincode_version,
+ policy, sequence)
+ if code != 0:
+ return Response(err("check_commit_readiness failed."), status=status.HTTP_400_BAD_REQUEST)
+
+ except Exception as e:
+ return Response(
+ err(e.args), status=status.HTTP_400_BAD_REQUEST
+ )
+ return Response(
+ ok(content), status=status.HTTP_200_OK
+ )
+
def init_env_vars(node, org):
"""
