Esempio n. 1
0
    def submit_update_transaction(self, ledger_config, **extra_params):
        """submit the update transaction to the ledger
        """

        global transaction_dependencies

        # there must be a previous state hash if this is
        # an update
        assert self.old_state_hash

        update_submitter = Submitter(ledger_config['LedgerURL'],
                                     key_str=self.channel_keys.txn_private)

        b64_message_hash = crypto.byte_array_to_base64(self.message_hash)
        b64_new_state_hash = crypto.byte_array_to_base64(self.new_state_hash)
        b64_old_state_hash = crypto.byte_array_to_base64(self.old_state_hash)

        # convert contract dependencies into transaction dependencies
        # to ensure that the sawtooth validator does not attempt to
        # re-order the transactions since it is unaware of the semantics
        # of the contract dependencies
        txn_dependencies = set()
        if extra_params.get('transaction_dependency_list'):
            txn_dependencies.update(
                extra_params['transaction_dependency_list'])

        txnid = transaction_dependencies.FindDependency(
            ledger_config, self.contract_id, b64_old_state_hash)
        if txnid:
            txn_dependencies.add(txnid)

        for dependency in self.dependencies:
            contract_id = dependency['contract_id']
            state_hash = dependency['state_hash']
            txnid = transaction_dependencies.FindDependency(
                ledger_config, contract_id, state_hash)
            if txnid:
                txn_dependencies.add(txnid)

        if txn_dependencies:
            extra_params['transaction_dependency_list'] = list(
                txn_dependencies)

        # now send off the transaction to the ledger
        txnid = update_submitter.submit_ccl_update_from_data(
            self.originator_keys.verifying_key, self.channel_keys.txn_public,
            self.enclave_service.enclave_id, self.signature, self.contract_id,
            b64_message_hash, b64_new_state_hash, b64_old_state_hash,
            self.encrypted_state, self.dependencies, **extra_params)

        if txnid:
            transaction_dependencies.SaveDependency(self.contract_id,
                                                    b64_new_state_hash, txnid)

        return txnid
def __submit_update_transaction__(response, ledger_config, **extra_params):
    """submit the update transaction to the ledger
    """

    if response.status is False:
        raise Exception('attempt to submit failed update transaction')

    # there must be a previous state hash if this is
    # an update
    assert response.old_state_hash

    update_submitter = Submitter(ledger_config['LedgerURL'],
                                 key_str=response.channel_keys.txn_private)

    b64_message_hash = crypto.byte_array_to_base64(response.message_hash)
    b64_new_state_hash = crypto.byte_array_to_base64(response.new_state_hash)
    b64_old_state_hash = crypto.byte_array_to_base64(response.old_state_hash)

    # get transaction dependency list from the input
    txn_dependencies = set()
    if extra_params.get('transaction_dependency_list'):
        txn_dependencies.update(extra_params['transaction_dependency_list'])

    raw_state = response.raw_state
    try:
        raw_state = raw_state.decode()
    except AttributeError:
        pass

    # now send off the transaction to the ledger
    txnid = update_submitter.submit_ccl_update_from_data(
        response.originator_keys.verifying_key,
        response.channel_keys.txn_public, response.enclave_service.enclave_id,
        response.signature, response.contract_id, b64_message_hash,
        b64_new_state_hash, b64_old_state_hash, raw_state,
        response.dependencies, **extra_params)

    if txnid:
        __lock_for_dependencies__.acquire()
        __dependencies__.SaveDependency(response.contract_id,
                                        b64_new_state_hash, txnid)
        __lock_for_dependencies__.release()

    return txnid