Search in sources :

Example 1 with ChaincodeHeaderExtension

use of org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeHeaderExtension 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 2 with ChaincodeHeaderExtension

use of org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeHeaderExtension in project fabric-sdk-java by hyperledger.

the class ProposalBuilder method createFabricProposal.

private FabricProposal.Proposal createFabricProposal(String channelID, Chaincode.ChaincodeID chaincodeID) {
    if (null == transientMap) {
        transientMap = Collections.emptyMap();
    }
    if (IS_DEBUG_LEVEL) {
        for (Entry<String, byte[]> tme : transientMap.entrySet()) {
            logger.debug(format("transientMap('%s', '%s'))", logString(tme.getKey()), logString(new String(tme.getValue(), UTF_8))));
        }
    }
    ChaincodeHeaderExtension chaincodeHeaderExtension = ChaincodeHeaderExtension.newBuilder().setChaincodeId(chaincodeID).build();
    Common.ChannelHeader chainHeader = createChannelHeader(HeaderType.ENDORSER_TRANSACTION, context.getTxID(), channelID, context.getEpoch(), context.getFabricTimestamp(), chaincodeHeaderExtension, null);
    ChaincodeInvocationSpec chaincodeInvocationSpec = createChaincodeInvocationSpec(chaincodeID, ccType);
    // Convert to bytestring map.
    Map<String, ByteString> bsm = new HashMap<>(transientMap.size());
    for (Entry<String, byte[]> tme : transientMap.entrySet()) {
        bsm.put(tme.getKey(), ByteString.copyFrom(tme.getValue()));
    }
    ChaincodeProposalPayload payload = ChaincodeProposalPayload.newBuilder().setInput(chaincodeInvocationSpec.toByteString()).putAllTransientMap(bsm).build();
    Common.Header header = Common.Header.newBuilder().setSignatureHeader(getSignatureHeaderAsByteString(context)).setChannelHeader(chainHeader.toByteString()).build();
    return FabricProposal.Proposal.newBuilder().setHeader(header.toByteString()).setPayload(payload.toByteString()).build();
}
Also used : ChaincodeInvocationSpec(org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInvocationSpec) HashMap(java.util.HashMap) ProtoUtils.getSignatureHeaderAsByteString(org.hyperledger.fabric.sdk.transaction.ProtoUtils.getSignatureHeaderAsByteString) ByteString(com.google.protobuf.ByteString) ProtoUtils.getSignatureHeaderAsByteString(org.hyperledger.fabric.sdk.transaction.ProtoUtils.getSignatureHeaderAsByteString) ByteString(com.google.protobuf.ByteString) Utils.logString(org.hyperledger.fabric.sdk.helper.Utils.logString) ChaincodeProposalPayload(org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeProposalPayload) ChaincodeHeaderExtension(org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeHeaderExtension) Common(org.hyperledger.fabric.protos.common.Common)

Aggregations

Common (org.hyperledger.fabric.protos.common.Common)2 ChaincodeHeaderExtension (org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeHeaderExtension)2 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 HashMap (java.util.HashMap)1 Header (org.hyperledger.fabric.protos.common.Common.Header)1 ChaincodeInvocationSpec (org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInvocationSpec)1 ChaincodeProposalPayload (org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeProposalPayload)1 CryptoException (org.hyperledger.fabric.sdk.exception.CryptoException)1 InvalidArgumentException (org.hyperledger.fabric.sdk.exception.InvalidArgumentException)1 ProposalException (org.hyperledger.fabric.sdk.exception.ProposalException)1 Utils.logString (org.hyperledger.fabric.sdk.helper.Utils.logString)1 ProtoUtils.getSignatureHeaderAsByteString (org.hyperledger.fabric.sdk.transaction.ProtoUtils.getSignatureHeaderAsByteString)1