Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
zecale_submit_batch.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 
6 from zecale.cli.defaults import APPLICATION_INSTANCE_FILE_DEFAULT
7 from zecale.cli.command_context import CommandContext
8 from zecale.cli.utils import load_aggregated_transaction
9 from zeth.core.contracts import InstanceDescription
10 from click import command, argument, option, Context, pass_context, ClickException
11 import json
12 
13 
14 @command()
15 @argument("batch-file")
16 @option(
17  "--application-instance-file", "-i",
18  default=APPLICATION_INSTANCE_FILE_DEFAULT,
19  help="Address or instance file of the application contract")
20 @option("--wait", is_flag=True, help="Wait for the resulting transaction")
21 @pass_context
23  ctx: Context,
24  batch_file: str,
25  application_instance_file: str,
26  wait: bool) -> None:
27  """
28  Submit an aggregated transaction ("batch") to a zecale dispatcher contract
29  instance.
30  """
31 
32  cmd_ctx: CommandContext = ctx.obj
33  aggregator_config = cmd_ctx.get_aggregator_configuration()
34  wrapper_snark = aggregator_config.wrapper_snark
35  pp = aggregator_config.wrapper_pairing_parameters
36 
37  # Load the batch
38  aggregated_tx = load_aggregated_transaction(wrapper_snark, batch_file)
39 
40  # Load the application instance address
41  with open(application_instance_file, "r") as app_instance_f:
42  app_instance = InstanceDescription.from_json_dict(
43  json.load(app_instance_f))
44 
45  # Open the dispatcher client and submit the batch to it
46  eth_addr, eth_private_key = cmd_ctx.get_eth_key_and_address()
47  dispatcher_contract = cmd_ctx.get_dispatcher_contract()
48  tx_id = dispatcher_contract.process_batch(
49  pp, aggregated_tx, app_instance.address, eth_addr, eth_private_key)
50  print(tx_id.hex())
51 
52  if wait:
53  tx_receipt = cmd_ctx.get_web3().eth.waitForTransactionReceipt(
54  tx_id, 10000)
55  gas_used = tx_receipt.gasUsed
56  status = tx_receipt.status
57  print(f"(gasUsed={gas_used}, status={status})")
58  if status != 1:
59  raise ClickException("transaction failed")
60 
61  # This is kept for convenience during contract development. Can be
62  # removed once the contract code is stable.
63  dispatcher_contract.dump_logs(tx_receipt)
zecale.cli.utils
Definition: utils.py:1
zecale.cli.defaults
Definition: defaults.py:1
zecale.cli.utils.load_aggregated_transaction
AggregatedTransaction load_aggregated_transaction(IZKSnarkProvider zksnark, str agg_tx_file)
Definition: utils.py:29
zecale.cli.zecale_submit_batch.submit_batch
None submit_batch(Context ctx, str batch_file, str application_instance_file, bool wait)
Definition: zecale_submit_batch.py:22
zecale.cli.command_context
Definition: command_context.py:1