Ejemplo n.º 1
0
    def submit_initialize_transaction(self, ledger_config, **extra_params):
        """submit the initialize transaction to the ledger
        """

        if self.status is False:
            raise Exception(
                'attempt to submit failed initialization transactions')

        global transaction_dependencies

        # an initialize operation has no previous state
        assert not self.old_state_hash

        initialize_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_code_hash = crypto.byte_array_to_base64(self.code_hash)

        txnid = initialize_submitter.submit_ccl_initialize_from_data(
            self.originator_keys.signing_key,
            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, self.encrypted_state,
            b64_code_hash, **extra_params)

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

        return txnid
Ejemplo n.º 2
0
def __submit_initialize_transaction__(response, ledger_config, **extra_params):
    """submit the initialize transaction to the ledger
    """

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

    # an initialize operation has no previous state
    assert not response.old_state_hash

    initialize_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_code_hash = crypto.byte_array_to_base64(response.code_hash)

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

    txnid = initialize_submitter.submit_ccl_initialize_from_data(
        response.originator_keys.signing_key,
        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, raw_state, b64_code_hash, **extra_params)

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

    return txnid