Search in sources :

Example 1 with InstantiateProposalBuilder

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

the class Channel method sendInstantiationProposal.

/**
 * Send instantiate request to the channel. Chaincode is created and initialized.
 *
 * @param instantiateProposalRequest
 * @param peers
 * @return responses from peers.
 * @throws InvalidArgumentException
 * @throws ProposalException
 */
public Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposalRequest instantiateProposalRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException {
    checkChannelState();
    if (null == instantiateProposalRequest) {
        throw new InvalidArgumentException("InstantiateProposalRequest is null");
    }
    instantiateProposalRequest.setSubmitted();
    checkPeers(peers);
    try {
        TransactionContext transactionContext = getTransactionContext(instantiateProposalRequest.getUserContext());
        transactionContext.setProposalWaitTime(instantiateProposalRequest.getProposalWaitTime());
        InstantiateProposalBuilder instantiateProposalbuilder = InstantiateProposalBuilder.newBuilder();
        instantiateProposalbuilder.context(transactionContext);
        instantiateProposalbuilder.argss(instantiateProposalRequest.getArgs());
        instantiateProposalbuilder.chaincodeName(instantiateProposalRequest.getChaincodeName());
        instantiateProposalbuilder.chaincodeType(instantiateProposalRequest.getChaincodeLanguage());
        instantiateProposalbuilder.chaincodePath(instantiateProposalRequest.getChaincodePath());
        instantiateProposalbuilder.chaincodeVersion(instantiateProposalRequest.getChaincodeVersion());
        instantiateProposalbuilder.chaincodEndorsementPolicy(instantiateProposalRequest.getChaincodeEndorsementPolicy());
        instantiateProposalbuilder.setTransientMap(instantiateProposalRequest.getTransientMap());
        FabricProposal.Proposal instantiateProposal = instantiateProposalbuilder.build();
        SignedProposal signedProposal = getSignedProposal(transactionContext, instantiateProposal);
        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) InstantiateProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstantiateProposalBuilder) 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)

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 FabricProposal (org.hyperledger.fabric.protos.peer.FabricProposal)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 InstantiateProposalBuilder (org.hyperledger.fabric.sdk.transaction.InstantiateProposalBuilder)1 TransactionContext (org.hyperledger.fabric.sdk.transaction.TransactionContext)1