Search in sources :

Example 1 with ProposalBuilder

use of org.hyperledger.fabric.sdk.transaction.ProposalBuilder in project fabric-sdk-java by hyperledger.

the class Channel method sendProposal.

private Collection<ProposalResponse> sendProposal(TransactionRequest proposalRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException {
    checkChannelState();
    checkPeers(peers);
    if (null == proposalRequest) {
        throw new InvalidArgumentException("The proposalRequest is null");
    }
    if (Utils.isNullOrEmpty(proposalRequest.getFcn())) {
        throw new InvalidArgumentException("The proposalRequest's fcn is null or empty.");
    }
    if (proposalRequest.getChaincodeID() == null) {
        throw new InvalidArgumentException("The proposalRequest's chaincode ID is null");
    }
    proposalRequest.setSubmitted();
    try {
        TransactionContext transactionContext = getTransactionContext(proposalRequest.getUserContext());
        transactionContext.verify(proposalRequest.doVerify());
        transactionContext.setProposalWaitTime(proposalRequest.getProposalWaitTime());
        // Protobuf message builder
        ProposalBuilder proposalBuilder = ProposalBuilder.newBuilder();
        proposalBuilder.context(transactionContext);
        proposalBuilder.request(proposalRequest);
        SignedProposal invokeProposal = getSignedProposal(transactionContext, proposalBuilder.build());
        return sendProposalToPeers(peers, invokeProposal, transactionContext);
    } catch (ProposalException e) {
        throw e;
    } catch (Exception e) {
        ProposalException exp = new ProposalException(e);
        logger.error(exp.getMessage(), exp);
        throw exp;
    }
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) UpgradeProposalBuilder(org.hyperledger.fabric.sdk.transaction.UpgradeProposalBuilder) ProposalBuilder(org.hyperledger.fabric.sdk.transaction.ProposalBuilder) JoinPeerProposalBuilder(org.hyperledger.fabric.sdk.transaction.JoinPeerProposalBuilder) InstantiateProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstantiateProposalBuilder) 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)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 SignedProposal (org.hyperledger.fabric.protos.peer.FabricProposal.SignedProposal)1 CryptoException (org.hyperledger.fabric.sdk.exception.CryptoException)1 EventHubException (org.hyperledger.fabric.sdk.exception.EventHubException)1 InvalidArgumentException (org.hyperledger.fabric.sdk.exception.InvalidArgumentException)1 ProposalException (org.hyperledger.fabric.sdk.exception.ProposalException)1 TransactionEventException (org.hyperledger.fabric.sdk.exception.TransactionEventException)1 TransactionException (org.hyperledger.fabric.sdk.exception.TransactionException)1 InstallProposalBuilder (org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder)1 InstantiateProposalBuilder (org.hyperledger.fabric.sdk.transaction.InstantiateProposalBuilder)1 JoinPeerProposalBuilder (org.hyperledger.fabric.sdk.transaction.JoinPeerProposalBuilder)1 ProposalBuilder (org.hyperledger.fabric.sdk.transaction.ProposalBuilder)1 TransactionContext (org.hyperledger.fabric.sdk.transaction.TransactionContext)1 UpgradeProposalBuilder (org.hyperledger.fabric.sdk.transaction.UpgradeProposalBuilder)1