Search in sources :

Example 1 with ChaincodeProposalPayload

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

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