use of org.hyperledger.fabric.sdk.exception.ProposalException in project fabric-sdk-java by hyperledger.
the class Channel method queryTransactionByID.
/**
* Query for a Fabric Transaction given its transactionID
*
* @param txID the ID of the transaction
* @param peers the peers to try to send the request.
* @param userContext the user context
* @return a {@link TransactionInfo}
* @throws ProposalException
* @throws InvalidArgumentException
*/
public TransactionInfo queryTransactionByID(Collection<Peer> peers, String txID, User userContext) throws ProposalException, InvalidArgumentException {
checkChannelState();
checkPeers(peers);
User.userContextCheck(userContext);
if (txID == null) {
throw new InvalidArgumentException("TxID parameter is null.");
}
TransactionInfo transactionInfo;
try {
logger.debug("queryTransactionByID with txID " + txID + "\n from peer " + " on channel " + name);
QuerySCCRequest querySCCRequest = new QuerySCCRequest(userContext);
querySCCRequest.setFcn(QuerySCCRequest.GETTRANSACTIONBYID);
querySCCRequest.setArgs(name, txID);
ProposalResponse proposalResponse = sendProposalSerially(querySCCRequest, peers);
return new TransactionInfo(txID, ProcessedTransaction.parseFrom(proposalResponse.getProposalResponse().getResponse().getPayload()));
} catch (Exception e) {
logger.error(e);
throw new ProposalException(e);
}
}
use of org.hyperledger.fabric.sdk.exception.ProposalException in project fabric-sdk-java by hyperledger.
the class Channel method queryBlockByHash.
/**
* Query a peer in this channel for a Block by the block hash.
*
* @param peers the Peers to query.
* @param blockHash the hash of the Block in the chain.
* @param userContext the user context
* @return the {@link BlockInfo} with the given block Hash
* @throws InvalidArgumentException if the channel is shutdown or any of the arguments are not valid.
* @throws ProposalException if an error occurred processing the query.
*/
public BlockInfo queryBlockByHash(Collection<Peer> peers, byte[] blockHash, User userContext) throws InvalidArgumentException, ProposalException {
checkChannelState();
checkPeers(peers);
userContextCheck(userContext);
if (blockHash == null) {
throw new InvalidArgumentException("blockHash parameter is null.");
}
try {
logger.trace("queryBlockByHash with hash : " + Hex.encodeHexString(blockHash) + " on channel " + name);
QuerySCCRequest querySCCRequest = new QuerySCCRequest(userContext);
querySCCRequest.setFcn(QuerySCCRequest.GETBLOCKBYHASH);
querySCCRequest.setArgs(name);
querySCCRequest.setArgBytes(new byte[][] { blockHash });
ProposalResponse proposalResponse = sendProposalSerially(querySCCRequest, peers);
return new BlockInfo(Block.parseFrom(proposalResponse.getProposalResponse().getResponse().getPayload()));
} catch (InvalidProtocolBufferException e) {
ProposalException proposalException = new ProposalException(e);
logger.error(proposalException);
throw proposalException;
}
}
use of org.hyperledger.fabric.sdk.exception.ProposalException in project fabric-sdk-java by hyperledger.
the class Channel method sendInstallProposal.
/**
* Send install chaincode request proposal to the channel.
*
* @param installProposalRequest
* @param peers
* @return
* @throws ProposalException
* @throws InvalidArgumentException
*/
Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest installProposalRequest, Collection<Peer> peers) throws ProposalException, InvalidArgumentException {
checkChannelState();
checkPeers(peers);
if (null == installProposalRequest) {
throw new InvalidArgumentException("InstallProposalRequest is null");
}
try {
TransactionContext transactionContext = getTransactionContext(installProposalRequest.getUserContext());
// Install will have no signing cause it's not really targeted to a channel.
transactionContext.verify(false);
transactionContext.setProposalWaitTime(installProposalRequest.getProposalWaitTime());
InstallProposalBuilder installProposalbuilder = InstallProposalBuilder.newBuilder();
installProposalbuilder.context(transactionContext);
installProposalbuilder.setChaincodeLanguage(installProposalRequest.getChaincodeLanguage());
installProposalbuilder.chaincodeName(installProposalRequest.getChaincodeName());
installProposalbuilder.chaincodePath(installProposalRequest.getChaincodePath());
installProposalbuilder.chaincodeVersion(installProposalRequest.getChaincodeVersion());
installProposalbuilder.setChaincodeSource(installProposalRequest.getChaincodeSourceLocation());
installProposalbuilder.setChaincodeInputStream(installProposalRequest.getChaincodeInputStream());
installProposalbuilder.setChaincodeMetaInfLocation(installProposalRequest.getChaincodeMetaInfLocation());
FabricProposal.Proposal deploymentProposal = installProposalbuilder.build();
SignedProposal signedProposal = getSignedProposal(transactionContext, deploymentProposal);
return sendProposalToPeers(peers, signedProposal, transactionContext);
} catch (Exception e) {
throw new ProposalException(e);
}
}
use of org.hyperledger.fabric.sdk.exception.ProposalException in project fabric-sdk-java by hyperledger.
the class GetConfigBlockBuilder method channelId.
public GetConfigBlockBuilder channelId(String channelId) throws ProposalException {
if (channelId == null) {
ProposalException exp = new ProposalException("Parameter channelId needs to be non-empty string .");
logger.error(exp.getMessage(), exp);
throw exp;
}
argList.add(ByteString.copyFrom(channelId, StandardCharsets.UTF_8));
return this;
}
use of org.hyperledger.fabric.sdk.exception.ProposalException in project fabric-sdk-java by hyperledger.
the class JoinPeerProposalBuilder method genesisBlock.
public JoinPeerProposalBuilder genesisBlock(Block genesisBlock) throws ProposalException {
if (genesisBlock == null) {
ProposalException exp = new ProposalException("No genesis block for Join proposal.");
JoinPeerProposalBuilder.logger.error(exp.getMessage(), exp);
throw exp;
}
List<ByteString> argList = new ArrayList<>();
argList.add(ByteString.copyFrom("JoinChain", StandardCharsets.UTF_8));
argList.add(genesisBlock.toByteString());
args(argList);
return this;
}
Aggregations