Search in sources :

Example 36 with InvalidArgumentException

use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.

the class ProposalResponse method getChaincodeActionResponseReadWriteSetInfo.

/**
 * getChaincodeActionResponseReadWriteSetInfo get this proposals read write set.
 *
 * @return The read write set. See {@link TxReadWriteSetInfo}
 * @throws InvalidArgumentException
 */
public TxReadWriteSetInfo getChaincodeActionResponseReadWriteSetInfo() throws InvalidArgumentException {
    if (isInvalid()) {
        throw new InvalidArgumentException("Proposal response is invalid.");
    }
    try {
        final ProposalResponsePayloadDeserializer proposalResponsePayloadDeserializer = getProposalResponsePayloadDeserializer();
        TxReadWriteSet txReadWriteSet = proposalResponsePayloadDeserializer.getExtension().getResults();
        if (txReadWriteSet == null) {
            return null;
        }
        return new TxReadWriteSetInfo(txReadWriteSet);
    } catch (Exception e) {
        throw new InvalidArgumentException(e);
    }
}
Also used : TxReadWriteSet(org.hyperledger.fabric.protos.ledger.rwset.Rwset.TxReadWriteSet) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException) CryptoException(org.hyperledger.fabric.sdk.exception.CryptoException)

Example 37 with InvalidArgumentException

use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.

the class SDKUtils method calculateBlockHash.

/**
 * used asn1 and get hash
 *
 * @param blockNumber
 * @param previousHash
 * @param dataHash
 * @return byte[]
 * @throws IOException
 * @throws InvalidArgumentException
 */
public static byte[] calculateBlockHash(HFClient client, long blockNumber, byte[] previousHash, byte[] dataHash) throws IOException, InvalidArgumentException {
    if (previousHash == null) {
        throw new InvalidArgumentException("previousHash parameter is null.");
    }
    if (dataHash == null) {
        throw new InvalidArgumentException("dataHash parameter is null.");
    }
    if (null == client) {
        throw new InvalidArgumentException("client parameter is null.");
    }
    CryptoSuite cryptoSuite = client.getCryptoSuite();
    if (null == client) {
        throw new InvalidArgumentException("Client crypto suite has not  been set.");
    }
    ByteArrayOutputStream s = new ByteArrayOutputStream();
    DERSequenceGenerator seq = new DERSequenceGenerator(s);
    seq.addObject(new ASN1Integer(blockNumber));
    seq.addObject(new DEROctetString(previousHash));
    seq.addObject(new DEROctetString(dataHash));
    seq.close();
    return cryptoSuite.hash(s.toByteArray());
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) CryptoSuite(org.hyperledger.fabric.sdk.security.CryptoSuite) DERSequenceGenerator(org.bouncycastle.asn1.DERSequenceGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 38 with InvalidArgumentException

use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.

the class SDKUtils method getProposalConsistencySets.

/**
 * Check that the proposals all have consistent read write sets
 *
 * @param proposalResponses
 * @param invalid           proposals that were found to be invalid.
 * @return A Collection of sets where each set has consistent proposals.
 * @throws InvalidArgumentException
 */
public static Collection<Set<ProposalResponse>> getProposalConsistencySets(Collection<ProposalResponse> proposalResponses, Set<ProposalResponse> invalid) throws InvalidArgumentException {
    if (proposalResponses == null) {
        throw new InvalidArgumentException("proposalResponses collection is null");
    }
    if (proposalResponses.isEmpty()) {
        throw new InvalidArgumentException("proposalResponses collection is empty");
    }
    if (null == invalid) {
        throw new InvalidArgumentException("invalid set is null.");
    }
    HashMap<ByteString, Set<ProposalResponse>> ret = new HashMap<>();
    for (ProposalResponse proposalResponse : proposalResponses) {
        if (proposalResponse.isInvalid()) {
            invalid.add(proposalResponse);
        } else {
            // payload bytes is what's being signed over so it must be consistent.
            final ByteString payloadBytes = proposalResponse.getPayloadBytes();
            if (payloadBytes == null) {
                throw new InvalidArgumentException(format("proposalResponse.getPayloadBytes() was null from peer: %s.", proposalResponse.getPeer()));
            } else if (payloadBytes.isEmpty()) {
                throw new InvalidArgumentException(format("proposalResponse.getPayloadBytes() was empty from peer: %s.", proposalResponse.getPeer()));
            }
            Set<ProposalResponse> set = ret.computeIfAbsent(payloadBytes, k -> new HashSet<>());
            set.add(proposalResponse);
        }
    }
    return ret.values();
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString)

Aggregations

InvalidArgumentException (org.hyperledger.fabric.sdk.exception.InvalidArgumentException)38 CryptoException (org.hyperledger.fabric.sdk.exception.CryptoException)26 IOException (java.io.IOException)22 ProposalException (org.hyperledger.fabric.sdk.exception.ProposalException)22 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)21 TransactionEventException (org.hyperledger.fabric.sdk.exception.TransactionEventException)17 StatusRuntimeException (io.grpc.StatusRuntimeException)16 ExecutionException (java.util.concurrent.ExecutionException)16 TimeoutException (java.util.concurrent.TimeoutException)16 EventHubException (org.hyperledger.fabric.sdk.exception.EventHubException)16 TransactionException (org.hyperledger.fabric.sdk.exception.TransactionException)16 ByteString (com.google.protobuf.ByteString)11 TransactionContext (org.hyperledger.fabric.sdk.transaction.TransactionContext)11 FabricProposalResponse (org.hyperledger.fabric.protos.peer.FabricProposalResponse)9 SignedProposal (org.hyperledger.fabric.protos.peer.FabricProposal.SignedProposal)8 ProtoUtils.getSignatureHeaderAsByteString (org.hyperledger.fabric.sdk.transaction.ProtoUtils.getSignatureHeaderAsByteString)7 FabricProposal (org.hyperledger.fabric.protos.peer.FabricProposal)6 CertificateException (java.security.cert.CertificateException)5 BroadcastResponse (org.hyperledger.fabric.protos.orderer.Ab.BroadcastResponse)5 ArrayList (java.util.ArrayList)4