74 lines
3.1 KiB
Java
74 lines
3.1 KiB
Java
package blockchain.query;
|
|
|
|
import blockchain.client.ChannelClientWrapper;
|
|
import blockchain.client.FabricClientWrapper;
|
|
import blockchain.configuration.Config;
|
|
import blockchain.user.UserContext;
|
|
import blockchain.utility.Util;
|
|
import org.apache.log4j.BasicConfigurator;
|
|
import org.apache.log4j.Logger;
|
|
import org.hyperledger.fabric.sdk.*;
|
|
import org.junit.Test;
|
|
|
|
import java.io.File;
|
|
import java.util.Collection;
|
|
import java.util.Set;
|
|
|
|
public class QueryTest {
|
|
private static Logger logger = Logger.getLogger(QueryTest.class);
|
|
//DON'T WORK
|
|
@Test
|
|
public void TestAQueryChannels() {
|
|
BasicConfigurator.configure();
|
|
|
|
//UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
|
UserContext user = Util.readUserContext(Config.ORG1,"User-org1");
|
|
|
|
try{
|
|
|
|
//TEST FAILED
|
|
//UserContext admin = new UserContext();
|
|
//File pkFolder = new File(Config.ADMIN_KEY_PATH);
|
|
//File[] pkFile = pkFolder.listFiles();
|
|
//File certFolder = new File(Config.ADMIN_CERT_PATH);
|
|
//File[] certFile = certFolder.listFiles();
|
|
//admin.setName(Config.ADMIN);
|
|
//admin.setMspId(Config.ORG1_MSP);
|
|
//admin.setAffiliation(Config.ORG1);
|
|
//Enrollment enrollAdmin = Util.getEnrollement(Config.ADMIN_KEY_PATH, pkFile[0].getName(), Config.ADMIN_CERT_PATH, certFile[0].getName());
|
|
//admin.setEnrollment(enrollAdmin);
|
|
//END TEST
|
|
|
|
String chaincode = Config.CHAINCODE_NAME;
|
|
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
|
|
Channel channel = channelClientWrapper.getChannel();
|
|
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
|
|
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
|
|
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
|
|
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
channel.addPeer(peer);
|
|
channel.addEventHub(eventHub);
|
|
channel.addOrderer(orderer);
|
|
channel.initialize();
|
|
|
|
String[] args1 = {"a"};
|
|
|
|
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"query",args1);
|
|
for(ProposalResponse pres : responseQuery){
|
|
ChaincodeResponse.Status status = pres.getStatus();
|
|
if(status.getStatus()!=200){
|
|
throw new Exception(pres.getMessage());
|
|
}
|
|
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
logger.info("RESPONSE : "+stringResponse);
|
|
}
|
|
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|