简体   繁体   中英

Hyperledger fabric endorsement policy error using Java SDK

I am working on golang version of fabcar smart contract while seeking to implement a Java-SDK API which enrolls an admin, registers a user and performs query-update value operations based on https://github.com/hyperledger/fabric-samples/tree/master/fabcar/java

I have successfully set up a 3 org-9 peers blockchain network, installed, instantiated and invoked chaincode on peers.

However, as i am working on implementing the relative API, i am only able to successfully query blockchain database, while getting a "Could not meet endorsement policy for chaincode mycc"

Please find below screenshot of relative error

在此处输入图像描述

Endorsement policy is "OR ('Org1MSP.member','Org2MSP.member', 'Org3MSP.member')".

Should registered user somehow get an Org1/Org2/Org3.member attribute? Any leads would be appreciated!

Like @Ikar Pohorský said, for me this got resolved after I used correct method name. Also, ensure that you delete 'wallet' folder in order to regenerate the user if your HLF n/w was recreated.

@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));
    }
}

EDIT: Also, please remember that if your chaincode throws errorResponse, even then we can have this endorsement fail issue. So, check if your chain code is working without any issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM