Fabric-sdk-jAVA issue #fabric-sdk-java


jeff.jo95z@...
 

hello,

when I was trying a query transaction via fabric sdk, I was getting this error:

mychannel already exist

This is coming because it is unable to read the details of the existing channel in the network

This is the code for querying:
 
  Path walletPath = Paths.get("wallet");
  Wallet wallet = Wallets.newFileSystemWallet(walletPath);
  // load a CCP
  Path networkConfigPath = Paths.get("..", "artifacts", "channel", "crypto-config", "peerOrganizations",
    "UBS.bank.com", "connection-org1.json");
 
  Gateway.Builder builder = Gateway.createBuilder();
  builder.identity(wallet, appUser).networkConfig(networkConfigPath).discovery(true);
 
  // System.out.println("vcID:"+vcID);
 
  byte[] result;
 
  try (Gateway gateway = builder.connect()) {
 
   // get the network and contract
   Network network = gateway.getNetwork("bank-channel");
   Contract contract = network.getContract("assetTest");
 
   result = contract.evaluateTransaction("ReadAssetPrivate", readID);
   System.out.println("query result:" + new String(result));
 
  }

when this line is executed:

  Gateway gateway = builder.connect()

when I debugged the gateway object does not contain the channel details
ie,channel hashmap is empty. Ideally it should contain the channel id which we have passed.
channel and chaincodes are all present.

this is the gateway implementation of fabric sdk:

NetworkImpl network = networks.get(networkName);
        if (network == null) {
            Channel channel = client.getChannel(networkName);
            if (channel == null && networkConfig != null) {
                try {
                    channel = client.loadChannelFromConfig(networkName, networkConfig);
                } catch (InvalidArgumentException | NetworkConfigurationException ex) {
                    LOG.info("Unable to load channel configuration from connection profile: " + ex.getLocalizedMessage());
                }
            }
            if (channel == null) {
                try {
                    // since this channel is not in the CCP, we'll assume it exists,
                    // and the org's peer(s) has joined it with all roles
                    channel = client.newChannel(networkName);
                    for (Peer peer : getPeersForOrg()) {
                        PeerOptions peerOptions = PeerOptions.createPeerOptions()
                                .setPeerRoles(EnumSet.allOf(PeerRole.class));
                        channel.addPeer(peer, peerOptions);
                    }
                } catch (InvalidArgumentException e) {
                    // we've already checked the channel status
                    throw new GatewayRuntimeException(e);
                }
            }
Channel value is getting null and it is trying to make a channel with the name we provided
It is not able to get the details of the channel in the network

What can be the reasons for not getting the details of the channel of the network

Join fabric@lists.hyperledger.org to automatically receive all group messages.