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);
}
}
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());
}
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();
}
Aggregations