Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
create_nested_tx.py
Go to the documentation of this file.
1 # Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 #
3 # SPDX-License-Identifier: LGPL-3.0+
4 
5 from zeth_zecale.defaults import \
6  ZETH_NESTED_TRANSACTION_FILE_DEFAULT, ZETH_APP_NAME
7 from zecale.core.nested_transaction import NestedTransaction
8 from zeth.core.mixer_client import \
9  MixParameters, mix_parameters_to_dispatch_parameters
10 from zeth.core.prover_client import ProverConfiguration
11 from zeth.core.zksnark import get_zksnark_provider
12 from zeth.cli.constants import PROVER_CONFIGURATION_FILE_DEFAULT
13 from click import command, argument, option
14 import json
15 
16 
17 @command()
18 @argument("zeth_tx_file")
19 @option(
20  "--prover-config-file",
21  default=PROVER_CONFIGURATION_FILE_DEFAULT,
22  help=f"Prover config file (default={PROVER_CONFIGURATION_FILE_DEFAULT})")
23 @option(
24  "--output-file",
25  "-o",
26  default=ZETH_NESTED_TRANSACTION_FILE_DEFAULT,
27  help=f"Output nested tx to file ({ZETH_NESTED_TRANSACTION_FILE_DEFAULT})")
29  zeth_tx_file: str,
30  prover_config_file: str,
31  output_file: str) -> None:
32  """
33  Create a Zecale nested transaction from a zeth MixParameters object
34  """
35 
36  # Load prover config (which is assumed to already exist)
37  with open(prover_config_file, "r") as prover_config_f:
38  prover_config = \
39  ProverConfiguration.from_json_dict(json.load(prover_config_f))
40  zksnark = zksnark = get_zksnark_provider(prover_config.zksnark_name)
41 
42  # Read the MixParameters
43  with open(zeth_tx_file, "r") as zeth_tx_f:
44  zeth_mix_params = \
45  MixParameters.from_json_dict(zksnark, json.load(zeth_tx_f))
46 
47  # Convert to a nested transaction, and write to output file
48  nested_tx = _create_zeth_nested_tx(zeth_mix_params, 0)
49  with open(output_file, "w") as output_f:
50  json.dump(nested_tx.to_json_dict(), output_f)
51 
52 
53 def _create_zeth_nested_tx(
54  mix_params: MixParameters,
55  fee_in_wei: int) -> NestedTransaction:
56  # Encode the (nested) mix parameters to be passed through zecale, and
57  # create a NestedTransaction object for this Zeth transaction.
58  parameters = mix_parameters_to_dispatch_parameters(mix_params)
59  return NestedTransaction(
60  app_name=ZETH_APP_NAME,
61  ext_proof=mix_params.extended_proof,
62  parameters=parameters,
63  fee_in_wei=fee_in_wei)
zeth_zecale.defaults
Definition: defaults.py:1
zecale.core.nested_transaction
Definition: nested_transaction.py:1
zecale.core.nested_transaction.NestedTransaction
Definition: nested_transaction.py:10
zeth_zecale.create_nested_tx.create_nested_tx
None create_nested_tx(str zeth_tx_file, str prover_config_file, str output_file)
Definition: create_nested_tx.py:28