gpt4 book ai didi

gradle - Hyperledger:使用Gradle构建Chaincode

转载 作者:行者123 更新时间:2023-12-03 03:17:44 25 4
gpt4 key购买 nike

使用fabric-java-sdk发送链码初始化请求时遇到问题。

部署(安装)方法:

public Collection<ProposalResponse> deploy(Collection<Peer> peers)
throws InvalidArgumentException, ProposalException {

String chaincodeName = chaincode.name();
String chaincodeVersion = chaincode.version();

HyperLedgerClient hyperLedgerClient = hyperLedgerChannelClient.getHyperLedgerClient();
InstallProposalRequest request = hyperLedgerClient.newInstallProposalRequest();

ChaincodeID.Builder chaincodeIDBuilder =
ChaincodeID.newBuilder()
.setName(chaincodeName)
.setVersion(chaincodeVersion);

ChaincodeID chaincodeID = chaincodeIDBuilder.build();

LOGGER.info(
"Deploying chaincode " + chaincodeName + " using Fabric client " +
hyperLedgerClient.getUserContext().getMspId()
+ " " + hyperLedgerClient.getUserContext().getName()
);

request.setChaincodeID(chaincodeID);
request.setUserContext(hyperLedgerClient.getUserContext());
request.setChaincodeInputStream(chaincode.source());
request.setChaincodeVersion(chaincodeVersion);
request.setChaincodeLanguage(Type.JAVA);

return hyperLedgerClient.sendInstallProposal(request, peers);
}

初始化(实例化)方法:
public Collection<ProposalResponse> instantiate(
String functionName, String[] functionArgs)
throws InvalidArgumentException, ProposalException {

HyperLedgerClient hyperLedgerClient = hyperLedgerChannelClient.getHyperLedgerClient();

String channelName = hyperLedgerChannelClient.getName();
String chaincodeName = chaincode.name();

String userContextName = hyperLedgerClient.getUserContext().getName();
String mspId = hyperLedgerClient.getUserContext().getMspId();

LOGGER.info(
"Instantiate proposal request {} on channel {} with Fabric client {} {}",
chaincodeName, channelName, mspId, userContextName
);

InstantiateProposalRequest instantiateProposalRequest =
hyperLedgerClient.getHfClient().newInstantiationProposalRequest();

instantiateProposalRequest.setProposalWaitTime(180000);
ChaincodeID.Builder chaincodeIDBuilder = ChaincodeID.newBuilder()
.setName(chaincodeName)
.setVersion(chaincode.version());

ChaincodeID ccid = chaincodeIDBuilder.build();
LOGGER.info("Instantiating Chaincode ID {} on channel {}", chaincodeName, channelName);

instantiateProposalRequest.setChaincodeID(ccid);
instantiateProposalRequest.setChaincodeLanguage(Type.JAVA);
instantiateProposalRequest.setFcn(functionName);
instantiateProposalRequest.setArgs(functionArgs);
Map<String, byte[]> tm = new HashMap<>();
tm.put("HyperLedgerFabric", "InstantiateProposalRequest:JavaSDK".getBytes(UTF_8));
tm.put("method", "InstantiateProposalRequest".getBytes(UTF_8));
instantiateProposalRequest.setTransientMap(tm);

Collection<ProposalResponse> responses =
hyperLedgerChannelClient.sendInstantiationProposal(instantiateProposalRequest);

CompletableFuture<TransactionEvent> completableFuture =
hyperLedgerChannelClient.sendTransaction(responses);

LOGGER.info(
"Chaincode {} on channel {} instantiation {}",
chaincodeName, channelName, completableFuture
);

return responses;
}

chaincode.source()指向.tgz文件,该文件具有以下内容
➜ transfer-chaincode git:(master) ✗ gradle clean buildProjectArchive 
Configuration on demand is an incubating feature.

BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed
➜ transfer-chaincode git:(master) ✗ tar -tvf build/distributions/transfer-chaincode-1.0.0-SNAPSHOT.tgz
-rw-r--r-- 0 0 0 1817 Mar 2 21:31 build.gradle
drwxr-xr-x 0 0 0 0 Feb 25 15:00 src/
drwxr-xr-x 0 0 0 0 Mar 2 21:22 src/main/
drwxr-xr-x 0 0 0 0 Mar 2 18:50 src/main/resources/
drwxr-xr-x 0 0 0 0 Mar 2 18:50 src/main/resources/config/
-rw-r--r-- 0 0 0 0 Mar 2 18:50 src/main/resources/config/application.yml
drwxr-xr-x 0 0 0 0 Feb 25 15:02 src/main/java/
drwxr-xr-x 0 0 0 0 Feb 25 15:02 src/main/java/com/
drwxr-xr-x 0 0 0 0 Feb 25 15:02 src/main/java/com/
drwxr-xr-x 0 0 0 0 Feb 25 15:02 src/main/java/com/fundtransfer/
drwxr-xr-x 0 0 0 0 Mar 2 18:49 src/main/java/com/fundtransfer/transfer/
-rw-r--r-- 0 0 0 1142 Mar 2 18:49 src/main/java/com/fundtransfer/transfer/TransferChaincodeApplication.java
drwxr-xr-x 0 0 0 0 Mar 2 21:12 src/main/java/com/fundtransfer/transfer/service/
-rw-r--r-- 0 0 0 1950 Mar 2 21:12 src/main/java/com/fundtransfer/transfer/service/ChaincodeEntrypoint.java
drwxr-xr-x 0 0 0 0 Mar 2 21:23 src/main/gradle/
-rw-r--r-- 0 0 0 39 Mar 2 21:23 src/main/gradle/settings.gradle
-rw-r--r-- 0 0 0 1587 Mar 2 21:28 gradle.properties
-rw-r--r-- 0 0 0 39 Mar 2 21:23 settings.gradle

对等docker-compose配置:
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

services:
peer-base:
image: hyperledger/fabric-peer:$HYPERLEDGER_VERSION
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
# the following setting starts chaincode containers on the same
# bridge network as the peers
# https://docs.docker.com/compose/networking/
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_fundtransfer
# - FABRIC_LOGGING_SPEC=INFO
- FABRIC_LOGGING_SPEC=DEBUG
- CORE_PEER_ENDORSER_ENABLED=true
- CORE_PEER_PROFILE_ENABLED=true
- CORE_PEER_CHANNELSERVICE_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- CORE_PEER_TLS_ENABLED=false
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
working_dir: /opt/hyperledger/peer
command: peer node start

对等日志:
    peer0.gateway.fundtransfer.com                  | 2019-03-02 17:39:27.230 UTC [comm.grpc.server] 1 -> INFO 1ad unary call completed {"grpc.start_time": "2019-03-02T17:39:27.194Z", "grpc.service": "protos.Endorser", "grpc.method": "ProcessProposal", "grpc.peer_address": "172.20.0.1:41564", "grpc.code": "OK", "grpc.call_duration": "35.5921ms"}
peer0.gateway.fundtransfer.com | 2019-03-02 17:39:32.846 UTC [endorser] callChaincode -> INFO 1ae [all-orgs-channel][ada2da1f] Entry chaincode: name:"lscc"
peer0.gateway.fundtransfer.com | 2019-03-02 17:39:58.340 UTC [chaincode.platform.java] GenerateDockerBuild -> ERRO 1af Can't build java chaincode Error returned from build: 1 "Maven build
peer0.gateway.fundtransfer.com | [INFO] Scanning for projects...
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [INFO] BUILD FAILURE
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [INFO] Total time: 1.818 s
peer0.gateway.fundtransfer.com | [INFO] Finished at: 2019-03-02T17:39:57Z
peer0.gateway.fundtransfer.com | [INFO] Final Memory: 6M/46M
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/chaincode/input/src). Please verify you invoked Maven from the correct directory. -> [Help 1]
peer0.gateway.fundtransfer.com | [ERROR]
peer0.gateway.fundtransfer.com | [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
peer0.gateway.fundtransfer.com | [ERROR] Re-run Maven using the -X switch to enable full debug logging.
peer0.gateway.fundtransfer.com | [ERROR]
peer0.gateway.fundtransfer.com | [ERROR] For more information about the errors and possible solutions, please read the following articles:
peer0.gateway.fundtransfer.com | [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
peer0.gateway.fundtransfer.com | "
peer0.gateway.fundtransfer.com | 2019-03-02 17:39:58.340 UTC [chaincode.platform] func1 -> ERRO 1b0 Failed to generate platform-specific docker build: Error returned from build: 1 "Maven build
peer0.gateway.fundtransfer.com | [INFO] Scanning for projects...
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [INFO] BUILD FAILURE
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [INFO] Total time: 1.818 s
peer0.gateway.fundtransfer.com | [INFO] Finished at: 2019-03-02T17:39:57Z
peer0.gateway.fundtransfer.com | [INFO] Final Memory: 6M/46M
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/chaincode/input/src). Please verify you invoked Maven from the correct directory. -> [Help 1]
peer0.gateway.fundtransfer.com | [ERROR]
peer0.gateway.fundtransfer.com | [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
peer0.gateway.fundtransfer.com | [ERROR] Re-run Maven using the -X switch to enable full debug logging.
peer0.gateway.fundtransfer.com | [ERROR]
peer0.gateway.fundtransfer.com | [ERROR] For more information about the errors and possible solutions, please read the following articles:
peer0.gateway.fundtransfer.com | [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
peer0.gateway.fundtransfer.com | "
peer0.gateway.fundtransfer.com | 2019-03-02 17:39:58.340 UTC [dockercontroller] deployImage -> ERRO 1b1 Error building image: Failed to generate platform-specific docker build: Error returned from build: 1 "Maven build
peer0.gateway.fundtransfer.com | [INFO] Scanning for projects...
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [INFO] BUILD FAILURE
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [INFO] Total time: 1.818 s
peer0.gateway.fundtransfer.com | [INFO] Finished at: 2019-03-02T17:39:57Z
peer0.gateway.fundtransfer.com | [INFO] Final Memory: 6M/46M
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/chaincode/input/src). Please verify you invoked Maven from the correct directory. -> [Help 1]
peer0.gateway.fundtransfer.com | [ERROR]
peer0.gateway.fundtransfer.com | [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
peer0.gateway.fundtransfer.com | [ERROR] Re-run Maven using the -X switch to enable full debug logging.
peer0.gateway.fundtransfer.com | [ERROR]
peer0.gateway.fundtransfer.com | [ERROR] For more information about the errors and possible solutions, please read the following articles:
peer0.gateway.fundtransfer.com | [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
peer0.gateway.fundtransfer.com | "
peer0.gateway.fundtransfer.com | 2019-03-02 17:39:58.340 UTC [dockercontroller] deployImage -> ERRO 1b2 Build Output:
peer0.gateway.fundtransfer.com | ********************
peer0.gateway.fundtransfer.com |
peer0.gateway.fundtransfer.com | ********************
peer0.gateway.fundtransfer.com | 2019-03-02 17:39:58.359 UTC [endorser] callChaincode -> INFO 1b3 [all-orgs-channel][ada2da1f] Exit chaincode: name:"lscc" (25548ms)
peer0.gateway.fundtransfer.com | 2019-03-02 17:39:58.359 UTC [endorser] SimulateProposal -> ERRO 1b4 [all-orgs-channel][ada2da1f] failed to invoke chaincode name:"lscc" , error: Failed to generate platform-specific docker build: Error returned from build: 1 "Maven build
peer0.gateway.fundtransfer.com | [INFO] Scanning for projects...
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [INFO] BUILD FAILURE
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [INFO] Total time: 1.818 s
peer0.gateway.fundtransfer.com | [INFO] Finished at: 2019-03-02T17:39:57Z
peer0.gateway.fundtransfer.com | [INFO] Final Memory: 6M/46M
peer0.gateway.fundtransfer.com | [INFO] ------------------------------------------------------------------------
peer0.gateway.fundtransfer.com | [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/chaincode/input/src). Please verify you invoked Maven from the correct directory. -> [Help 1]
peer0.gateway.fundtransfer.com | [ERROR]
peer0.gateway.fundtransfer.com | [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
peer0.gateway.fundtransfer.com | [ERROR] Re-run Maven using the -X switch to enable full debug logging.
peer0.gateway.fundtransfer.com | [ERROR]
peer0.gateway.fundtransfer.com | [ERROR] For more information about the errors and possible solutions, please read the following articles:
peer0.gateway.fundtransfer.com | [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
peer0.gateway.fundtransfer.com | "
peer0.gateway.fundtransfer.com | error starting container
peer0.gateway.fundtransfer.com | error starting container
peer0.gateway.fundtransfer.com | 2019-03-02 17:39:58.359 UTC [comm.grpc.server] 1 -> INFO 1b5 unary call completed {"grpc.start_time": "2019-03-02T17:39:32.845Z", "grpc.service": "protos.Endorser", "grpc.method": "ProcessProposal", "grpc.peer_address": "172.20.0.1:41564", "grpc.code": "OK", "grpc.call_duration": "25.5488994s"}
peer0.gateway.fundtransfer.com | 2019-03-02 17:47:34.631 UTC [endorser] callChaincode -> INFO 1b6 [all-orgs-channel][74212e9f] Entry chaincode: name:"lscc"
peer0.gateway.fundtransfer.com | 2019-03-02 17:47:36.258 UTC [comm.grpc.server] 1 -> INFO 1b7 streaming call completed {"grpc.start_time": "2019-03-02T17:39:18.839Z", "grpc.service": "protos.Deliver", "grpc.method": "Deliver", "grpc.peer_address": "172.20.0.1:41566", "error": "context finished before block retrieved: context canceled", "grpc.code": "Unknown", "grpc.call_duration": "8m18.0064816s"}

问题是我正在使用 gradle。如何切换同伴使用gradle?

最佳答案

问题在于,我正在发送带有以下结构的tgz存档:

src/main/...
build.gradle
settings.gradle

但是我需要将其更改为:
src/src/main/...
src/build.gradle
src/settings.gradle

然后,同龄人将认识到Gradle。

关于gradle - Hyperledger:使用Gradle构建Chaincode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54961314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com