コード例 #1
0
ファイル: timer.py プロジェクト: nibau/zkay
def time_measure(key, should_print=False):
    start = time.time()
    yield
    end = time.time()
    elapsed = end - start

    if should_print:
        zk_print(f"Took {elapsed} s")
    my_logging.data(key, elapsed)
コード例 #2
0
ファイル: test_logger.py プロジェクト: nibau/zkay
    def test_data(self):
        log_file = default_log_file + '_data_test'
        my_logging.prepare_logger(log_file)
        my_logging.data('key', 2)
        my_logging.info('ABCD')
        my_logging.shutdown()

        # check
        content = read_file(log_file + '_data.log')
        d = json.loads(content)
        self.assertEqual(d['key'], 'key')
        self.assertEqual(d['value'], 2)
        self.assertTrue('ABCD' not in content)
コード例 #3
0
    def _transact(self, contract_handle, sender: Union[bytes, str], function: str, *actual_params, wei_amount: Optional[int] = None) -> Any:
        try:
            fct = contract_handle.constructor if function == 'constructor' else contract_handle.functions[function]
            gas_amount = self._gas_heuristic(sender, fct(*actual_params))
            tx = {'from': sender, 'gas': gas_amount}
            if wei_amount:
                tx['value'] = wei_amount
            tx_hash = fct(*actual_params).transact(tx)
            tx_receipt = self.w3.eth.waitForTransactionReceipt(tx_hash)
        except Exception as e:
            raise BlockChainError(e.args)

        if tx_receipt['status'] == 0:
            raise TransactionFailedException("Transaction failed")
        gas = tx_receipt['gasUsed']
        zk_print(f"Consumed gas: {gas}")
        my_logging.data('gas', gas)
        return tx_receipt
コード例 #4
0
ファイル: zkay_frontend.py プロジェクト: eth-sri/zkay
def compile_zkay_file(input_file_path: str, output_dir: str, import_keys: bool = False, **kwargs):
    """
    Parse, type-check and compile the given zkay contract file.

    :param input_file_path: path to the zkay contract file
    :param output_dir: path to a directory where the compilation output should be generated
    :param import_keys: | if false, zk-snark of all modified circuits will be generated during compilation
                        | if true, zk-snark keys for all circuits are expected to be already present in the output directory, and the compilation will use the provided keys to generate the verification contracts
                        | This option is mostly used internally when connecting to a zkay contract provided by a 3rd-party
    :raise ZkayCompilerError: if any compilation stage fails
    :raise RuntimeError: if import_keys is True and zkay file, manifest file or any of the key files is missing
    """
    code = read_file(input_file_path)

    # log specific features of compiled program
    my_logging.data('originalLoc', lines_of_code(code))
    m = re.search(r'\/\/ Description: (.*)', code)
    if m:
        my_logging.data('description', m.group(1))
    m = re.search(r'\/\/ Domain: (.*)', code)
    if m:
        my_logging.data('domain', m.group(1))
    _, filename = os.path.split(input_file_path)

    # compile
    with time_measure('compileFull'):
        cg, _ = compile_zkay(code, output_dir, import_keys, **kwargs)