Fabric-sdk-java 实例化报错

  1. 在学习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);
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值