Search in sources :

Example 16 with InvalidArgumentException

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

the class CryptoPrimitives method setSecurityLevel.

// validateCertificate
/**
 * Security Level determines the elliptic curve used in key generation
 *
 * @param securityLevel currently 256 or 384
 * @throws InvalidArgumentException
 */
void setSecurityLevel(final int securityLevel) throws InvalidArgumentException {
    logger.trace(format("setSecurityLevel to %d", securityLevel));
    if (securityCurveMapping.isEmpty()) {
        throw new InvalidArgumentException("Security curve mapping has no entries.");
    }
    if (!securityCurveMapping.containsKey(securityLevel)) {
        StringBuilder sb = new StringBuilder();
        String sp = "";
        for (int x : securityCurveMapping.keySet()) {
            sb.append(sp).append(x);
            sp = ", ";
        }
        throw new InvalidArgumentException(format("Illegal security level: %d. Valid values are: %s", securityLevel, sb.toString()));
    }
    String lcurveName = securityCurveMapping.get(securityLevel);
    logger.debug(format("Mapped curve strength %d to %s", securityLevel, lcurveName));
    X9ECParameters params = ECNamedCurveTable.getByName(lcurveName);
    // Check if can match curve name to requested strength.
    if (params == null) {
        InvalidArgumentException invalidArgumentException = new InvalidArgumentException(format("Curve %s defined for security strength %d was not found.", curveName, securityLevel));
        logger.error(invalidArgumentException);
        throw invalidArgumentException;
    }
    curveName = lcurveName;
    this.securityLevel = securityLevel;
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) X9ECParameters(org.bouncycastle.asn1.x9.X9ECParameters)

Example 17 with InvalidArgumentException

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

the class InstantiateProposalBuilder method createNetModeTransaction.

private void createNetModeTransaction() throws InvalidArgumentException {
    logger.debug("NetModeTransaction");
    if (chaincodeType == null) {
        throw new InvalidArgumentException("Chaincode type is required");
    }
    List<String> modlist = new LinkedList<>();
    modlist.add("init");
    modlist.addAll(argList);
    switch(chaincodeType) {
        case JAVA:
            ccType(Chaincode.ChaincodeSpec.Type.JAVA);
            break;
        case NODE:
            ccType(Chaincode.ChaincodeSpec.Type.NODE);
            break;
        case GO_LANG:
            ccType(Chaincode.ChaincodeSpec.Type.GOLANG);
            break;
        default:
            throw new InvalidArgumentException("Requested chaincode type is not supported: " + chaincodeType);
    }
    ChaincodeDeploymentSpec depspec = createDeploymentSpec(ccType, chaincodeName, chaincodePath, chaincodeVersion, modlist, null);
    List<ByteString> argList = new ArrayList<>();
    argList.add(ByteString.copyFrom(action, StandardCharsets.UTF_8));
    argList.add(ByteString.copyFrom(context.getChannelID(), StandardCharsets.UTF_8));
    argList.add(depspec.toByteString());
    if (chaincodePolicy != null) {
        argList.add(ByteString.copyFrom(chaincodePolicy));
    }
    args(argList);
}
Also used : ChaincodeDeploymentSpec(org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeDeploymentSpec) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) LinkedList(java.util.LinkedList)

Example 18 with InvalidArgumentException

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

the class ProposalResponse method getChaincodeActionResponsePayload.

/**
 * ChaincodeActionResponsePayload is the result of the executing chaincode.
 *
 * @return the result of the executing chaincode.
 * @throws InvalidArgumentException
 */
public byte[] getChaincodeActionResponsePayload() throws InvalidArgumentException {
    if (isInvalid()) {
        throw new InvalidArgumentException("Proposal response is invalid.");
    }
    try {
        final ProposalResponsePayloadDeserializer proposalResponsePayloadDeserializer = getProposalResponsePayloadDeserializer();
        ByteString ret = proposalResponsePayloadDeserializer.getExtension().getChaincodeAction().getResponse().getPayload();
        if (null == ret) {
            return null;
        }
        return ret.toByteArray();
    } catch (InvalidArgumentException e) {
        throw e;
    } catch (Exception e) {
        throw new InvalidArgumentException(e);
    }
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) ByteString(com.google.protobuf.ByteString) 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 19 with InvalidArgumentException

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

the class ProposalResponse method getChaincodeID.

// public ByteString getPayload() {
// return proposalResponse.getPayload();
// }
/**
 * Chaincode ID that was executed.
 *
 * @return See {@link ChaincodeID}
 * @throws InvalidArgumentException
 */
public ChaincodeID getChaincodeID() throws InvalidArgumentException {
    try {
        if (chaincodeID == null) {
            Header header = Header.parseFrom(proposal.getHeader());
            Common.ChannelHeader channelHeader = Common.ChannelHeader.parseFrom(header.getChannelHeader());
            ChaincodeHeaderExtension chaincodeHeaderExtension = ChaincodeHeaderExtension.parseFrom(channelHeader.getExtension());
            chaincodeID = new ChaincodeID(chaincodeHeaderExtension.getChaincodeId());
        }
        return chaincodeID;
    } catch (Exception e) {
        throw new InvalidArgumentException(e);
    }
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) Header(org.hyperledger.fabric.protos.common.Common.Header) 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) Common(org.hyperledger.fabric.protos.common.Common) ChaincodeHeaderExtension(org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeHeaderExtension)

Example 20 with InvalidArgumentException

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

the class HFClient method deSerializeChannel.

/**
 * Deserialize a channel serialized by {@link Channel#serializeChannel()}
 *
 * @param channelBytes bytes to be deserialized.
 * @return A Channel that has not been initialized.
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws InvalidArgumentException
 */
public Channel deSerializeChannel(byte[] channelBytes) throws IOException, ClassNotFoundException, InvalidArgumentException {
    Channel channel;
    ObjectInputStream in = null;
    try {
        in = new ObjectInputStream(new ByteArrayInputStream(channelBytes));
        channel = (Channel) in.readObject();
        final String name = channel.getName();
        synchronized (channels) {
            if (null != getChannel(name)) {
                channel.shutdown(true);
                throw new InvalidArgumentException(format("Channel %s already exists in the client", name));
            }
            channels.put(name, channel);
            channel.client = this;
        }
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            // Best effort here.
            logger.error(e);
        }
    }
    return channel;
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

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