package blockchain.client; import blockchain.configuration.Config; import blockchain.user.UserContext; import org.hyperledger.fabric.sdk.Channel; import org.hyperledger.fabric.sdk.HFClient; import org.hyperledger.fabric.sdk.Peer; import org.hyperledger.fabric.sdk.exception.CryptoException; import org.hyperledger.fabric.sdk.exception.InvalidArgumentException; import org.hyperledger.fabric.sdk.exception.ProposalException; import org.hyperledger.fabric.sdk.security.CryptoSuite; import java.lang.reflect.InvocationTargetException; import java.util.Set; public class FabricClientWrapper { private HFClient client; public HFClient getClient(){ return client; } public FabricClientWrapper(UserContext userContext) throws CryptoException, InvalidArgumentException, IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException { CryptoSuite cryptoSuite = CryptoSuite.Factory.getCryptoSuite(); client = HFClient.createNewInstance(); client.setCryptoSuite(cryptoSuite); client.setUserContext(userContext); } public ChannelClientWrapper createChannelClient(String name) throws InvalidArgumentException { Channel channel = client.newChannel(name); ChannelClientWrapper channelClientWrapper = new ChannelClientWrapper(name, channel, this); return channelClientWrapper; } public Set queryForChannels() throws InvalidArgumentException, IllegalArgumentException, ProposalException { client.newChannel(Config.CHANNEL_NAME); client.newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL); //Peer peer = client.newPeer(Config.ORG_PEER,Config.ORG_PEER_URL); Peer peer = client.newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL); return client.queryChannels(peer); } }