use of org.hyperledger.fabric.protos.peer.FabricProposalResponse.Response in project fabric-sdk-java by hyperledger.
the class Channel method queryInstantiatedChaincodes.
/**
* Query peer for chaincode that has been instantiated
*
* @param peer The peer to query.
* @param userContext the user context.
* @return A list of ChaincodeInfo @see {@link ChaincodeInfo}
* @throws InvalidArgumentException
* @throws ProposalException
*/
public List<ChaincodeInfo> queryInstantiatedChaincodes(Peer peer, User userContext) throws InvalidArgumentException, ProposalException {
checkChannelState();
checkPeer(peer);
User.userContextCheck(userContext);
try {
TransactionContext context = getTransactionContext(userContext);
FabricProposal.Proposal q = QueryInstantiatedChaincodesBuilder.newBuilder().context(context).build();
SignedProposal qProposal = getSignedProposal(context, q);
Collection<ProposalResponse> proposalResponses = sendProposalToPeers(Collections.singletonList(peer), qProposal, context);
if (null == proposalResponses) {
throw new ProposalException(format("Peer %s channel query return with null for responses", peer.getName()));
}
if (proposalResponses.size() != 1) {
throw new ProposalException(format("Peer %s channel query expected one response but got back %d responses ", peer.getName(), proposalResponses.size()));
}
ProposalResponse proposalResponse = proposalResponses.iterator().next();
FabricProposalResponse.ProposalResponse fabricResponse = proposalResponse.getProposalResponse();
if (null == fabricResponse) {
throw new ProposalException(format("Peer %s channel query return with empty fabric response", peer.getName()));
}
final Response fabricResponseResponse = fabricResponse.getResponse();
if (null == fabricResponseResponse) {
// not likely but check it.
throw new ProposalException(format("Peer %s channel query return with empty fabricResponseResponse", peer.getName()));
}
if (200 != fabricResponseResponse.getStatus()) {
throw new ProposalException(format("Peer %s channel query expected 200, actual returned was: %d. " + fabricResponseResponse.getMessage(), peer.getName(), fabricResponseResponse.getStatus()));
}
ChaincodeQueryResponse chaincodeQueryResponse = ChaincodeQueryResponse.parseFrom(fabricResponseResponse.getPayload());
return chaincodeQueryResponse.getChaincodesList();
} catch (ProposalException e) {
throw e;
} catch (Exception e) {
throw new ProposalException(format("Query for peer %s channels failed. " + e.getMessage(), name), e);
}
}
use of org.hyperledger.fabric.protos.peer.FabricProposalResponse.Response in project fabric-sdk-java by hyperledger.
the class Channel method queryInstalledChaincodes.
List<ChaincodeInfo> queryInstalledChaincodes(Peer peer) throws InvalidArgumentException, ProposalException {
checkPeer(peer);
if (!isSystemChannel()) {
throw new InvalidArgumentException("queryInstalledChaincodes should only be invoked on system channel.");
}
try {
TransactionContext context = getTransactionContext();
FabricProposal.Proposal q = QueryInstalledChaincodesBuilder.newBuilder().context(context).build();
SignedProposal qProposal = getSignedProposal(context, q);
Collection<ProposalResponse> proposalResponses = sendProposalToPeers(Collections.singletonList(peer), qProposal, context);
if (null == proposalResponses) {
throw new ProposalException(format("Peer %s channel query return with null for responses", peer.getName()));
}
if (proposalResponses.size() != 1) {
throw new ProposalException(format("Peer %s channel query expected one response but got back %d responses ", peer.getName(), proposalResponses.size()));
}
ProposalResponse proposalResponse = proposalResponses.iterator().next();
FabricProposalResponse.ProposalResponse fabricResponse = proposalResponse.getProposalResponse();
if (null == fabricResponse) {
throw new ProposalException(format("Peer %s channel query return with empty fabric response", peer.getName()));
}
final Response fabricResponseResponse = fabricResponse.getResponse();
if (null == fabricResponseResponse) {
// not likely but check it.
throw new ProposalException(format("Peer %s channel query return with empty fabricResponseResponse", peer.getName()));
}
if (200 != fabricResponseResponse.getStatus()) {
throw new ProposalException(format("Peer %s channel query expected 200, actual returned was: %d. " + fabricResponseResponse.getMessage(), peer.getName(), fabricResponseResponse.getStatus()));
}
ChaincodeQueryResponse chaincodeQueryResponse = ChaincodeQueryResponse.parseFrom(fabricResponseResponse.getPayload());
return chaincodeQueryResponse.getChaincodesList();
} catch (ProposalException e) {
throw e;
} catch (Exception e) {
throw new ProposalException(format("Query for peer %s channels failed. " + e.getMessage(), name), e);
}
}
use of org.hyperledger.fabric.protos.peer.FabricProposalResponse.Response in project fabric-sdk-java by hyperledger.
the class Channel method queryChannels.
// ///////////////////////////////////////////////////////
// transactions order
Set<String> queryChannels(Peer peer) throws InvalidArgumentException, ProposalException {
checkPeer(peer);
if (!isSystemChannel()) {
throw new InvalidArgumentException("queryChannels should only be invoked on system channel.");
}
try {
TransactionContext context = getTransactionContext();
FabricProposal.Proposal q = QueryPeerChannelsBuilder.newBuilder().context(context).build();
SignedProposal qProposal = getSignedProposal(context, q);
Collection<ProposalResponse> proposalResponses = sendProposalToPeers(Collections.singletonList(peer), qProposal, context);
if (null == proposalResponses) {
throw new ProposalException(format("Peer %s channel query return with null for responses", peer.getName()));
}
if (proposalResponses.size() != 1) {
throw new ProposalException(format("Peer %s channel query expected one response but got back %d responses ", peer.getName(), proposalResponses.size()));
}
ProposalResponse proposalResponse = proposalResponses.iterator().next();
if (proposalResponse.getStatus() != ChaincodeResponse.Status.SUCCESS) {
throw new ProposalException(format("Failed exception message is %s, status is %d", proposalResponse.getMessage(), proposalResponse.getStatus().getStatus()));
}
FabricProposalResponse.ProposalResponse fabricResponse = proposalResponse.getProposalResponse();
if (null == fabricResponse) {
throw new ProposalException(format("Peer %s channel query return with empty fabric response", peer.getName()));
}
final Response fabricResponseResponse = fabricResponse.getResponse();
if (null == fabricResponseResponse) {
// not likely but check it.
throw new ProposalException(format("Peer %s channel query return with empty fabricResponseResponse", peer.getName()));
}
if (200 != fabricResponseResponse.getStatus()) {
throw new ProposalException(format("Peer %s channel query expected 200, actual returned was: %d. " + fabricResponseResponse.getMessage(), peer.getName(), fabricResponseResponse.getStatus()));
}
ChannelQueryResponse qr = ChannelQueryResponse.parseFrom(fabricResponseResponse.getPayload());
Set<String> ret = new HashSet<>(qr.getChannelsCount());
for (Query.ChannelInfo x : qr.getChannelsList()) {
ret.add(x.getChannelId());
}
return ret;
} catch (ProposalException e) {
throw e;
} catch (Exception e) {
throw new ProposalException(format("Query for peer %s channels failed. " + e.getMessage(), name), e);
}
}
Aggregations