Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
eth_gen_network_config.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 # Copyright (c) 2015-2022 Clearmatics Technologies Ltd
4 #
5 # SPDX-License-Identifier: LGPL-3.0+
6 
7 from zeth.cli.constants import ETH_NETWORK_FILE_DEFAULT, ETH_NETWORK_DEFAULT
8 from zeth.cli.utils import NetworkConfig, get_eth_network
9 from click import command, option, argument
10 from typing import Optional
11 
12 
13 @command()
14 @argument("eth-network", default=ETH_NETWORK_DEFAULT)
15 @option("--eth-rpc-endpoint", help="(Optional) Override endpoint URL.")
16 @option(
17  "--eth-rpc-certificate",
18  help="(Optional) Path to TLS certificate for endpoint")
19 @option(
20  "--eth-rpc-insecure",
21  is_flag=True,
22  help="(Optional) Skip TLS certificate checks")
23 @option(
24  "--output-file",
25  default=ETH_NETWORK_FILE_DEFAULT,
26  help=f"Output filename (default: {ETH_NETWORK_FILE_DEFAULT})")
28  eth_network: str,
29  eth_rpc_endpoint: Optional[str],
30  eth_rpc_certificate: Optional[str],
31  eth_rpc_insecure: bool,
32  output_file: str) -> None:
33  """
34  Generate a network config file. ETH_NETWORK is a network name or
35  pre-existing network config file.
36 
37  Examples:
38 
39  \b
40  # Write default config for "ganache" to the default file
41  $ zeth-helper eth-gen-network-config ganache
42 
43  \b
44  # Write "geth" config with a custom endpoint to default file
45  $ zeth-helper eth-gen-network-config geth \\
46  --eth-rpc-endpoint http://localhost:8080
47 
48  \b
49  # Write a custom https endpoint to file, specifying the certificate
50  $ zeth-helper eth-gen-network-config \\
51  my-network \\
52  --eth-rpc-endpoint https://rpc.my-network.io:8545 \\
53  --eth-rpc-certificate rpc.my-network.io.crt
54 
55  \b
56  # Write default network and endpoint to file "default-network"
57  $ zeth-helper eth-gen-network-config --output-file default-network
58  """
59 
60  if eth_rpc_endpoint is not None:
61  network = NetworkConfig(
62  name=eth_network,
63  endpoint=eth_rpc_endpoint,
64  certificate=eth_rpc_certificate,
65  insecure=eth_rpc_insecure)
66  else:
67  network = get_eth_network(eth_network)
68 
69  network_json = network.to_json()
70  print(f"network: {network_json}")
71 
72  with open(output_file, "w") as eth_network_f:
73  eth_network_f.write(network_json)
74  print(f"written to \"{output_file}\"")
zeth.cli.utils.get_eth_network
NetworkConfig get_eth_network(Optional[str] eth_network)
Definition: utils.py:84
zeth.cli.utils
Definition: utils.py:1
zeth.cli.constants
Definition: constants.py:1
zeth.helper.eth_gen_network_config.eth_gen_network_config
None eth_gen_network_config(str eth_network, Optional[str] eth_rpc_endpoint, Optional[str] eth_rpc_certificate, bool eth_rpc_insecure, str output_file)
Definition: eth_gen_network_config.py:27
zeth.cli.utils.NetworkConfig
Definition: utils.py:27