Search in sources :

Example 16 with ProposalException

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);
    }
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException) FabricProposalResponse(org.hyperledger.fabric.protos.peer.FabricProposalResponse) EventHubException(org.hyperledger.fabric.sdk.exception.EventHubException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) TransactionException(org.hyperledger.fabric.sdk.exception.TransactionException) TransactionEventException(org.hyperledger.fabric.sdk.exception.TransactionEventException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) StatusRuntimeException(io.grpc.StatusRuntimeException) CryptoException(org.hyperledger.fabric.sdk.exception.CryptoException) TimeoutException(java.util.concurrent.TimeoutException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException)

Example 17 with ProposalException

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;
    }
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException) FabricProposalResponse(org.hyperledger.fabric.protos.peer.FabricProposalResponse)

Example 18 with 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);
    }
}
Also used : FabricProposal(org.hyperledger.fabric.protos.peer.FabricProposal) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) SignedProposal(org.hyperledger.fabric.protos.peer.FabricProposal.SignedProposal) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException) EventHubException(org.hyperledger.fabric.sdk.exception.EventHubException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) TransactionException(org.hyperledger.fabric.sdk.exception.TransactionException) TransactionEventException(org.hyperledger.fabric.sdk.exception.TransactionEventException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) StatusRuntimeException(io.grpc.StatusRuntimeException) CryptoException(org.hyperledger.fabric.sdk.exception.CryptoException) TimeoutException(java.util.concurrent.TimeoutException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException)

Example 19 with ProposalException

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;
}
Also used : ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException)

Example 20 with ProposalException

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;
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException)

Aggregations

ProposalException (org.hyperledger.fabric.sdk.exception.ProposalException)20 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)16 InvalidArgumentException (org.hyperledger.fabric.sdk.exception.InvalidArgumentException)16 TransactionEventException (org.hyperledger.fabric.sdk.exception.TransactionEventException)14 StatusRuntimeException (io.grpc.StatusRuntimeException)13 IOException (java.io.IOException)13 ExecutionException (java.util.concurrent.ExecutionException)13 TimeoutException (java.util.concurrent.TimeoutException)13 CryptoException (org.hyperledger.fabric.sdk.exception.CryptoException)13 EventHubException (org.hyperledger.fabric.sdk.exception.EventHubException)13 TransactionException (org.hyperledger.fabric.sdk.exception.TransactionException)13 FabricProposalResponse (org.hyperledger.fabric.protos.peer.FabricProposalResponse)12 SignedProposal (org.hyperledger.fabric.protos.peer.FabricProposal.SignedProposal)9 TransactionContext (org.hyperledger.fabric.sdk.transaction.TransactionContext)9 FabricProposal (org.hyperledger.fabric.protos.peer.FabricProposal)7 ByteString (com.google.protobuf.ByteString)3 BroadcastResponse (org.hyperledger.fabric.protos.orderer.Ab.BroadcastResponse)3 DeliverResponse (org.hyperledger.fabric.protos.orderer.Ab.DeliverResponse)3 Response (org.hyperledger.fabric.protos.peer.FabricProposalResponse.Response)3 ChaincodeQueryResponse (org.hyperledger.fabric.protos.peer.Query.ChaincodeQueryResponse)3