Fabric-sdk-java 实例化报错
2021/12/22 11:21:42
本文主要是介绍Fabric-sdk-java 实例化报错,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
- 在学习Fabric -sdk -java 时,使用 ChaincodeInstantiated() 方法报错
public void ChaincodeInstantiated() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, org.bouncycastle.crypto.CryptoException, InvalidArgumentException, CryptoException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException, TransactionException, ProposalException { UserContext userContext = new UserContext(); userContext.setAffiliation("Org1"); userContext.setMspId("Org1MSP"); userContext.setAccount("李伟"); userContext.setName("admin"); Enrollment enrollment = UserUtils.getEnrollment(keyFolderPath,keyFileName,certFoldePath,certFileName); userContext.setEnrollment(enrollment); FabricClient fabricClient = new FabricClient(userContext); Peer peer = fabricClient.getPeer("peer0.org1.nwpu.com","grpcs://peer0.org1.nwpu.com:7051",tlsPeerFilePath); Orderer order = fabricClient.getOrderer("orderer.nwpu.com","grpcs://orderer.nwpu.com:7050",tlsOrderFilePath); String initArgs[] = {"a","100","b","100"}; fabricClient.initChaincode("agiot-channel", TransactionRequest.Type.GO_LANG,"testcc","2.0",order,peer,"init",initArgs); }
报错看区块链节点的输出日志如图下所示:
Failed to generate platform-specific docker build: Error returned from build: 1 "can’t load package: package mainresourceschaincode: cannot find package “mainresourceschaincode” in any of:
peer0.org1.nwpu.com | /opt/go/src/mainresourceschaincode (from $GOROOT)
peer0.org1.nwpu.com | /chaincode/input/src/mainresourceschaincode (from $GOPATH)
peer0.org1.nwpu.com | /opt/gopath/src/mainresourceschaincode
选择重新安装, 将链码的路径由.
fabricClient.installChaincode(TransactionRequest.Type.GO_LANG,"testcc","2.0","E:\\Java\\fabric\\","main\\resources\\chaincode",peers);
路径改为
fabricClient.installChaincode(TransactionRequest.Type.GO_LANG,"testcc","2.0","E:/Java/fabric/","main/resources/chaincode",peers); 链码为test.go 在项目中的路径为结构如:
安装链码:
@Test public void installChaincodeToOrg1() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, org.bouncycastle.crypto.CryptoException, InvalidArgumentException, CryptoException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException, ProposalException { UserContext userContext = new UserContext(); userContext.setAffiliation("Org1"); userContext.setMspId("Org1MSP"); userContext.setAccount("李伟"); userContext.setName("admin"); Enrollment enrollment = UserUtils.getEnrollment(keyFolderPath,keyFileName,certFoldePath,certFileName); userContext.setEnrollment(enrollment); FabricClient fabricClient = new FabricClient(userContext); Peer peer0 = fabricClient.getPeer("peer0.org1.nwpu.com","grpcs://peer0.org1.nwpu.com:7051",tlsPeerFilePath); Peer peer1 = fabricClient.getPeer("peer1.org1.nwpu.com","grpcs://peer1.org1.nwpu.com:8051",tlsPeerFilePath); List<Peer> peers = new ArrayList<Peer>(); peers.add(peer0); peers.add(peer1); fabricClient.installChaincode(TransactionRequest.Type.GO_LANG,"testcc","2.0","E:/Java/fabric/","main/resources/chaincode",peers); } @Test public void installChaincodeToOrg2() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, org.bouncycastle.crypto.CryptoException, InvalidArgumentException, CryptoException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException, ProposalException { List list = new ArrayList(); UserContext userContext = new UserContext(); userContext.setAffiliation("Org2"); userContext.setMspId("Org2MSP"); userContext.setAccount("赵而"); userContext.setName("admin"); Enrollment enrollment = UserUtils.getEnrollment(keyFolderPath2,keyFileName2,certFoldePath2,certFileName2); userContext.setEnrollment(enrollment); FabricClient fabricClient = new FabricClient(userContext); Peer peer0 = fabricClient.getPeer("peer0.org2.nwpu.com","grpcs://peer0.org2.nwpu.com:9051",tlsPeerFilePath2); Peer peer1 = fabricClient.getPeer("peer1.org2.nwpu.com","grpcs://peer1.org2.nwpu.com:10051",tlsPeerFilePath2); List<Peer> peers = new ArrayList<Peer>(); peers.add(peer0); peers.add(peer1); //链码的路径一定要用 / 的方式来写,不能使用 \\ ,否则在实例化链码的时候会 Failed to generate platform-specific docker build: Error returned from build: 1 "can't load package: package mainresourceschaincode: cannot find package "mainresourceschaincode" in any of: /opt/go/src/mainresourceschaincode fabricClient.installChaincode(TransactionRequest.Type.GO_LANG,"testcc","2.0","E:/Java/fabric/","main/resources/chaincode",peers); }
这篇关于Fabric-sdk-java 实例化报错的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-102025 蛇年,J 人直播带货内容审核团队必备的办公软件有哪 6 款?
- 2025-01-10高效运营背后的支柱:文档管理优化指南
- 2025-01-10年末压力山大?试试优化你的文档管理
- 2025-01-10跨部门协作中的进度追踪重要性解析
- 2025-01-10总结 JavaScript 中的变体函数调用方式
- 2025-01-10HR团队如何通过数据驱动提升管理效率?6个策略
- 2025-01-10WBS实战指南:如何一步步构建高效项目管理框架?
- 2025-01-10实现精准执行:团队协作新方法
- 2025-01-10如何使用工具提升活动策划团队的工作效率?几个必备工具推荐
- 2025-01-10WiX 标签使用介绍:打造专业安装程序的利器