コード例 #1
0
def decode_chaincode_action_payload(payload_bytes):
    """Decodes chaincode action payload from ChaincodeAction

    :param payload_bytes: Bytes buffer of the payload
    :type payload_bytes: str
    :return: deserialized payload information and action.
    """
    payload = {}
    proto_chaincode_action_payload = transaction_pb2.ChaincodeActionPayload()
    proto_chaincode_action_payload.ParseFromString(payload_bytes)
    payload['chaincode_proposal_payload'] = \
        decode_chaincode_proposal_payload(
            proto_chaincode_action_payload.chaincode_proposal_payload)
    payload['action'] = \
        decode_chaincode_endorsed_action(proto_chaincode_action_payload.action)
    return payload
コード例 #2
0
ファイル: utils.py プロジェクト: xueguoliang/fabric-sdk-py
def create_tx_payload(endorsements, tran_req):

    cc_action_payload = transaction_pb2.ChaincodeActionPayload()
    response, _ = tran_req.responses[0]
    cc_action_payload.action.proposal_response_payload = \
        response.payload
    cc_action_payload.action.endorsements.extend(endorsements)
    cc_action_payload.chaincode_proposal_payload = tran_req.proposal.payload

    tran = transaction_pb2.Transaction()
    cc_tran_action = tran.actions.add()
    cc_tran_action.header = tran_req.header.signature_header
    cc_tran_action.payload = cc_action_payload.SerializeToString()
    tran_payload = common_pb2.Payload()
    tran_payload.header.channel_header = tran_req.header.channel_header
    tran_payload.header.signature_header = tran_req.header.signature_header
    tran_payload.data = tran.SerializeToString()

    tran_payload_bytes = tran_payload.SerializeToString()
    return tran_payload_bytes
コード例 #3
0
def send_transaction(orderers, tran_req, signing_identity, scheduler=None):
    """Send a transaction to the chain's orderer service (one or more
    orderer endpoints) for consensus and committing to the ledger.

    This call is asynchronous and the successful transaction commit is
    notified via a BLOCK or CHAINCODE event. This method must provide a
    mechanism for applications to attach event listeners to handle
    'transaction submitted', 'transaction complete' and 'error' events.

    Args:
        scheduler: scheduler
        signing_identity: signing identity
        orderers: orderers
        tran_req (TransactionRequest): The transaction object

    Returns:
        result (EventEmitter): an handle to allow the application to
        attach event handlers on 'submitted', 'complete', and 'error'.

    """
    if not tran_req:
        return rx.Observable.just(ValueError(
            "Missing input request object on the transaction request"
        ))

    if not tran_req.responses or len(tran_req.responses) < 1:
        return rx.Observable.just(ValueError(
            "Missing 'proposalResponses' parameter in transaction request"
        ))

    if not tran_req.proposal:
        return rx.Observable.just(ValueError(
            "Missing 'proposalResponses' parameter in transaction request"
        ))

    if len(orderers) < 1:
        return rx.Observable.just(ValueError(
            "Missing orderer objects on this chain"
        ))

    endorsements = map(lambda res: res[0].endorsement, tran_req.responses)

    cc_action_payload = transaction_pb2.ChaincodeActionPayload()
    response, _ = tran_req.responses[0]
    cc_action_payload.action.proposal_response_payload = \
        response.payload
    cc_action_payload.action.endorsements.extend(endorsements)
    cc_action_payload.chaincode_proposal_payload = tran_req.proposal.payload

    tran = transaction_pb2.Transaction()
    cc_tran_action = tran.actions.add()
    cc_tran_action.header = tran_req.header.signature_header
    cc_tran_action.payload = cc_action_payload.SerializeToString()
    tran_payload = common_pb2.Payload()
    tran_payload.header.channel_header = tran_req.header.channel_header
    tran_payload.header.signature_header = tran_req.header.signature_header
    tran_payload.data = tran.SerializeToString()

    envelope = sign_tran_payload(signing_identity, tran_payload)

    if sys.version_info < (3, 0):
        orderer = random.choice(orderers.values())
    else:
        orderer = random.choice(list(orderers.values()))
    return orderer.broadcast(envelope, scheduler)