4

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

enter image description here

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!

Ikar Pohorský
  • 4,617
  • 6
  • 39
  • 56
StamGR
  • 41
  • 2
  • Are you sure this is the instantiated policy? Have you upgraded the chaincode? When you upgrade the chaincode you need to define endorsement policy. – Sergio Gragera Oct 12 '19 at 08:01
  • 1
    @SergioGragera yes this is the instantiated policy. No need to upgrade chaincode. I successfully queried and wrote to ledger with Java API, by updating /etc/hosts file to include all peers,db's and CA's as localhosts. – StamGR Oct 12 '19 at 12:47
  • 1
    @StamGR In my case this was caused by a typo in the method name :( – Ikar Pohorský Oct 14 '19 at 13:03
  • @StamGR what does your host file look like? I have the same issue. Help appreciated – rogger2016 Oct 23 '19 at 22:09
  • 1
    @rogger2016 my host file looks something like this: 127.0.0.1 localhost 127.0.0.1 orderer[i]..com 127.0.0.1 peer[i]...com 127.0.0.1 ca...com 127.0.0.1 couchdb[i] where i=1,2.3... (depending on the number of peers/orderers etc.) while and is case dependent. hope it helps – StamGR Oct 27 '19 at 19:26
  • Thanks @StamGR, ill check it put :) – rogger2016 Oct 28 '19 at 20:08
  • the host file changes worked :) Cheers @StamGR – rogger2016 Oct 28 '19 at 20:52
  • @StamGR also make sure your chaincode argument types are the same on both sides (chaincode vs. app) – Ikar Pohorský Oct 29 '19 at 11:00

1 Answers1

0

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.

Siva
  • 598
  • 3
  • 11