Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
deploy.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 zecale.core.utils import get_zecale_dir
6 from zecale.cli.defaults import APPLICATION_INSTANCE_FILE_DEFAULT, \
7  INSTANCE_FILE_DEFAULT
8 from zeth.core.contracts import InstanceDescription
9 from zeth.core.utils import hex_to_uint256_list
10 from zeth.cli.utils import open_web3_from_network, load_eth_address, \
11  load_eth_private_key
12 from click import command, argument, option, pass_context, Context
13 from os.path import join
14 import json
15 
16 
17 ZECALE_DIR = get_zecale_dir()
18 CONTRACTS_DIR = join(ZECALE_DIR, "contracts")
19 DUMMY_APP_CONTRACT_FILE = join(CONTRACTS_DIR, "DummyApplication.sol")
20 DUMMY_APP_CONTRACT_DEPLOY_GAS = 500000
21 
22 
23 @command()
24 @argument("verification-key-hash")
25 @option(
26  "--dispatcher-instance-file",
27  default=INSTANCE_FILE_DEFAULT,
28  help="Dispatcher instance file")
29 @option(
30  "--instance-file",
31  default=APPLICATION_INSTANCE_FILE_DEFAULT,
32  help="File to write dummy app instance information to")
33 @pass_context
34 def deploy(
35  ctx: Context,
36  verification_key_hash: str,
37  dispatcher_instance_file: str,
38  instance_file: str) -> None:
39  """
40  Deploy the contract for a dummy application.
41  """
42 
43  eth_network = ctx.obj["eth_network"]
44 
45  # Load the dispatcher instance
46  with open(dispatcher_instance_file, "r") as dispatcher_instance_f:
47  dispatcher_desc = InstanceDescription.from_json_dict(
48  json.load(dispatcher_instance_f))
49 
50  # Verification key hash as an array of evm words.
51  verification_key_hash_evm = list(hex_to_uint256_list(verification_key_hash))
52  print(f"verification_key_hash_evm = {verification_key_hash_evm}")
53 
54  web3 = open_web3_from_network(eth_network)
55  eth_address = load_eth_address(ctx.obj["eth_addr"])
56  eth_private_key_data = load_eth_private_key(ctx.obj["eth_private_key"])
57  instance_desc = InstanceDescription.deploy(
58  web3,
59  DUMMY_APP_CONTRACT_FILE,
60  "DummyApplication",
61  eth_address,
62  eth_private_key_data,
63  DUMMY_APP_CONTRACT_DEPLOY_GAS,
64  {"allow_paths": CONTRACTS_DIR},
65  [dispatcher_desc.address, verification_key_hash_evm])
66 
67  with open(instance_file, "w") as instance_file_f:
68  json.dump(instance_desc.to_json_dict(), instance_file_f)
69 
70  print(f"Instance file written to '{instance_file}'")
zecale.cli.defaults
Definition: defaults.py:1
zecale.core.utils.get_zecale_dir
str get_zecale_dir()
Definition: utils.py:9
zecale.core.utils
Definition: utils.py:1
zecale.dummy_app.deploy.deploy
None deploy(Context ctx, str verification_key_hash, str dispatcher_instance_file, str instance_file)
Definition: deploy.py:34