def __init__(self, processed_transaction): bootstrap_util.EnvelopeExractor.__init__( self, processed_transaction.transactionEnvelope) self.processed_transaction = processed_transaction self.tx = transaction_pb2.Transaction() self.tx.ParseFromString(self.payload.data) self.chaincode_action_payload = transaction_pb2.ChaincodeActionPayload( ) self.chaincode_action_payload.ParseFromString( self.tx.actions[0].payload) # self.signature_header = common_dot_common_pb2.SignatureHeader() # self.signature_header.ParseFromString(self.tx.actions[0].header) self.chaincode_proposal_payload = proposal_pb2.ChaincodeProposalPayload( ) self.chaincode_proposal_payload.ParseFromString( self.chaincode_action_payload.chaincode_proposal_payload) self.chaincode_invocation_spec = chaincode_pb2.ChaincodeInvocationSpec( ) self.chaincode_invocation_spec.ParseFromString( self.chaincode_proposal_payload.input)
def createSignedTx(user, signed_proposal, proposal_responses): assert len(proposal_responses) > 0, "Expected at least 1 ProposalResponse" #Unpack signed proposal proposal = proposal_pb2.Proposal() proposal.ParseFromString(signed_proposal.proposal_bytes) header = common_dot_common_pb2.Header() header.ParseFromString(proposal.header) ccProposalPayload = proposal_pb2.ChaincodeProposalPayload() ccProposalPayload.ParseFromString(proposal.payload) # Be sure to clear the TransientMap ccProposalPayload.TransientMap.clear() endorsements = [p.endorsement for p in proposal_responses] ccEndorsedAction = transaction_pb2.ChaincodeEndorsedAction( proposal_response_payload=proposal_responses[0].payload, endorsements=endorsements) ccActionPayload = transaction_pb2.ChaincodeActionPayload( chaincode_proposal_payload=ccProposalPayload.SerializeToString(), action=ccEndorsedAction) transaction = transaction_pb2.Transaction() action = transaction.actions.add() action.header = header.signature_header action.payload = ccActionPayload.SerializeToString() payload = common_dot_common_pb2.Payload( header=header, data=transaction.SerializeToString()) payloadBytes = payload.SerializeToString() signature = user.sign(payloadBytes) envelope = common_dot_common_pb2.Envelope(payload=payloadBytes, signature=signature) return envelope