4

我正在研究 golang 版本的 fabcar 智能合约,同时寻求实现一个 Java-SDK API,它可以注册管理员、注册用户并基于https://github.com/hyperledger/fabric-samples/执行查询更新值操作树/主/fabcar/java

我已经成功建立了一个 3 org-9 peers 区块链网络,在 peers 上安装、实例化和调用链码。

但是,当我正在实施相关 API 时,我只能成功查询区块链数据库,同时获得“无法满足链码 mycc 的背书政策”

请在下面找到相对错误的屏幕截图

在此处输入图像描述

背书政策是“OR ('Org1MSP.member','Org2MSP.member', 'Org3MSP.member')”。

注册用户是否应该以某种方式获得 Org1/Org2/Org3.member 属性?任何线索将不胜感激!

4

1 回答 1

0

就像@Ikar Pohorský 说的那样,对我来说,在我使用正确的方法名称后这个问题得到了解决。此外,如果您的 HLF n/w 已重新创建,请确保删除“钱包”文件夹以重新生成用户。

@Test
public void testMyMethodToBeInvoked() throws Exception {
    deleteDirectory(".\\wallet");
    EnrollAdmin.main(null);
    RegisterUser.main(null);
    // Load a file system based wallet for managing identities.
    final Path walletPath = Paths.get("wallet");
    final Wallet wallet = Wallet.createFileSystemWallet(walletPath);

    // load a CCP
    final Path networkConfigPath = Paths
            .get("C:\\sw\\hlf146-2\\fabric-samples\\first-network\\connection-org1.yaml");

    final Gateway.Builder builder = Gateway.createBuilder();
    builder.identity(wallet, "user1").networkConfig(networkConfigPath).discovery(true);

    // create a gateway connection
    try (Gateway gateway = builder.connect()) {
        final Network network = gateway.getNetwork("mychannel");
        final Contract contract = network.getContract("mycc");

        String myJSONString="{\"a\":\"b\"}";

        byte[] result;
        // Following did NOT work. Control goes directly to 'invoke' when 'submitTransaction' is done directly. 'invoke' need not be mentioned here.
        // result = contract.submitTransaction("invoke", myJSONString);

        // Following DID work. In chaincode (my chain code was Java) I had a method named 'myMethodToBeInvoked'. The chain code was written similar to https://github.com/hyperledger/fabric-samples/blob/release-1.4/chaincode/chaincode_example02/java/src/main/java/org/hyperledger/fabric/example/SimpleChaincode.java
        result = contract.submitTransaction("myMethodToBeInvoked", my);
        System.out.println(new String(result));
    }
}

编辑:另外,请记住,如果您的链码抛出 errorResponse,即使这样我们也会遇到这个背书失败的问题。因此,请检查您的链码是否正常工作。

于 2020-06-19T14:01:02.327 回答