org.hyperledger.fabric.client.ChaincodeEventsRequestImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fabric-gateway Show documentation
Show all versions of fabric-gateway Show documentation
Hyperledger Fabric Gateway client API for Java
The newest version!
/*
* Copyright 2021 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.fabric.client;
import com.google.protobuf.ByteString;
import io.grpc.CallOptions;
import java.util.function.UnaryOperator;
import org.hyperledger.fabric.protos.gateway.ChaincodeEventsResponse;
import org.hyperledger.fabric.protos.gateway.SignedChaincodeEventsRequest;
final class ChaincodeEventsRequestImpl implements ChaincodeEventsRequest {
private final GatewayClient client;
private final SigningIdentity signingIdentity;
private SignedChaincodeEventsRequest signedRequest;
ChaincodeEventsRequestImpl(
final GatewayClient client,
final SigningIdentity signingIdentity,
final SignedChaincodeEventsRequest signedRequest) {
this.client = client;
this.signingIdentity = signingIdentity;
this.signedRequest = signedRequest;
}
@Override
public CloseableIterator getEvents(final UnaryOperator options) {
sign();
CloseableIterator responseIter = client.chaincodeEvents(signedRequest, options);
return new ChaincodeEventIterator(responseIter);
}
@Override
public byte[] getBytes() {
return signedRequest.toByteArray();
}
@Override
public byte[] getDigest() {
byte[] message = signedRequest.getRequest().toByteArray();
return signingIdentity.hash(message);
}
void setSignature(final byte[] signature) {
signedRequest = signedRequest.toBuilder()
.setSignature(ByteString.copyFrom(signature))
.build();
}
private void sign() {
if (isSigned()) {
return;
}
byte[] digest = getDigest();
byte[] signature = signingIdentity.sign(digest);
setSignature(signature);
}
private boolean isSigned() {
return !signedRequest.getSignature().isEmpty();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy