Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
Public Member Functions | Public Attributes | List of all members
zecale.cli.command_context.CommandContext Class Reference

Public Member Functions

def __init__ (self, str aggregator_server=AGGREGATOR_SERVER_ENDPOINT_DEFAULT, str aggregator_config_file=AGGREGATOR_CONFIG_FILE_DEFAULT, str instance_file=INSTANCE_FILE_DEFAULT, Optional[str] eth_network=None, Optional[str] eth_addr=None, Optional[str] eth_private_key=None)
 
Tuple[str, Optional[bytes]] get_eth_key_and_address (self)
 
Any get_web3 (self)
 
AggregatorClient get_aggregator_client (self)
 
AggregatorConfiguration get_aggregator_configuration (self)
 
IZKSnarkProvider get_nested_snark (self)
 
IZKSnarkProvider get_wrapper_snark (self)
 
Any get_dispatcher_contract (self)
 

Public Attributes

 aggregator_server
 
 aggregator_config_file
 
 instance_file
 
 eth_network
 
 eth_addr
 
 eth_private_key
 

Detailed Description

Carries command-independent parameters from top-level command to
sub-commands. Performs some basic operations common to commands, based on
the current context and configuration.

Definition at line 22 of file command_context.py.

Constructor & Destructor Documentation

◆ __init__()

def zecale.cli.command_context.CommandContext.__init__ (   self,
str   aggregator_server = AGGREGATOR_SERVER_ENDPOINT_DEFAULT,
str   aggregator_config_file = AGGREGATOR_CONFIG_FILE_DEFAULT,
str   instance_file = INSTANCE_FILE_DEFAULT,
Optional[str]   eth_network = None,
Optional[str]   eth_addr = None,
Optional[str]   eth_private_key = None 
)

Definition at line 29 of file command_context.py.

29  def __init__(
30  self,
31  aggregator_server: str = AGGREGATOR_SERVER_ENDPOINT_DEFAULT,
32  aggregator_config_file: str = AGGREGATOR_CONFIG_FILE_DEFAULT,
33  instance_file: str = INSTANCE_FILE_DEFAULT,
34  eth_network: Optional[str] = None,
35  eth_addr: Optional[str] = None,
36  eth_private_key: Optional[str] = None):
37  # TODO: Separate nested and wrapper snarks
38  self.aggregator_server = aggregator_server
39  self.aggregator_config_file = aggregator_config_file
40  self.instance_file = instance_file
41  self.eth_network = eth_network
42  self.eth_addr = eth_addr
43  self.eth_private_key = eth_private_key
44  self._web3: Optional[Any] = None
45  self._aggregator_client: Optional[AggregatorClient] = None
46  self._aggregator_config: Optional[AggregatorConfiguration] = None
47  self._dispatcher_contract: Optional[DispatcherContract] = None
48 

Member Function Documentation

◆ get_aggregator_client()

AggregatorClient zecale.cli.command_context.CommandContext.get_aggregator_client (   self)
Return an aggregator client for the appropriate endpoint. Created and
cached when this function is first called.

Definition at line 62 of file command_context.py.

62  def get_aggregator_client(self) -> AggregatorClient:
63  """
64  Return an aggregator client for the appropriate endpoint. Created and
65  cached when this function is first called.
66  """
67  if not self._aggregator_client:
68  self._aggregator_client = AggregatorClient(self.aggregator_server)
69  return self._aggregator_client
70 
Here is the caller graph for this function:

◆ get_aggregator_configuration()

AggregatorConfiguration zecale.cli.command_context.CommandContext.get_aggregator_configuration (   self)
Load the AggregatorConfiguration from a file, or request it from the
aggregator server.

Definition at line 71 of file command_context.py.

71  def get_aggregator_configuration(self) -> AggregatorConfiguration:
72  """
73  Load the AggregatorConfiguration from a file, or request it from the
74  aggregator server.
75  """
76  if self._aggregator_config is not None:
77  return self._aggregator_config
78 
79  if exists(self.aggregator_config_file):
80  with open(self.aggregator_config_file, "r") as aggregator_config_f:
81  try:
82  self._aggregator_config = \
83  AggregatorConfiguration.from_json_dict(
84  json.load(aggregator_config_f))
85  return self._aggregator_config
86  except Exception as ex:
87  print(f"removing `{self.aggregator_config_file}`: {ex}.")
88  unlink(self.aggregator_config_file)
89 
90  aggregator_client = self.get_aggregator_client()
91  self._aggregator_config = aggregator_client.get_configuration()
92 
93  with open(self.aggregator_config_file, "w") as aggregator_config_f:
94  json.dump(self._aggregator_config.to_json_dict(), aggregator_config_f)
95 
96  return self._aggregator_config
97 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_dispatcher_contract()

Any zecale.cli.command_context.CommandContext.get_dispatcher_contract (   self)
Load (and cache) the dispatcher contract instance.

Definition at line 104 of file command_context.py.

104  def get_dispatcher_contract(self) -> Any:
105  """
106  Load (and cache) the dispatcher contract instance.
107  """
108  if not self._dispatcher_contract:
109  with open(self.instance_file, "r") as instance_f:
110  instance_dict = json.load(instance_f)
111  instance = InstanceDescription.from_json_dict(instance_dict)
112  self._dispatcher_contract = DispatcherContract(
113  self.get_web3(), instance, self.get_wrapper_snark())
114  return self._dispatcher_contract
Here is the call graph for this function:

◆ get_eth_key_and_address()

Tuple[str, Optional[bytes]] zecale.cli.command_context.CommandContext.get_eth_key_and_address (   self)

Definition at line 49 of file command_context.py.

49  def get_eth_key_and_address(self) -> Tuple[str, Optional[bytes]]:
50  return (
51  load_eth_address(self.eth_addr),
52  load_eth_private_key(self.eth_private_key))
53 

◆ get_nested_snark()

IZKSnarkProvider zecale.cli.command_context.CommandContext.get_nested_snark (   self)

Definition at line 98 of file command_context.py.

98  def get_nested_snark(self) -> IZKSnarkProvider:
99  return self.get_aggregator_configuration().nested_snark
100 
Here is the call graph for this function:

◆ get_web3()

Any zecale.cli.command_context.CommandContext.get_web3 (   self)
Create and cache web3 connection.

Definition at line 54 of file command_context.py.

54  def get_web3(self) -> Any:
55  """
56  Create and cache web3 connection.
57  """
58  if not self._web3:
59  self._web3 = open_web3_from_network(get_eth_network(self.eth_network))
60  return self._web3
61 
Here is the caller graph for this function:

◆ get_wrapper_snark()

IZKSnarkProvider zecale.cli.command_context.CommandContext.get_wrapper_snark (   self)

Definition at line 101 of file command_context.py.

101  def get_wrapper_snark(self) -> IZKSnarkProvider:
102  return self.get_aggregator_configuration().wrapper_snark
103 
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ aggregator_config_file

zecale.cli.command_context.CommandContext.aggregator_config_file

Definition at line 32 of file command_context.py.

◆ aggregator_server

zecale.cli.command_context.CommandContext.aggregator_server

Definition at line 31 of file command_context.py.

◆ eth_addr

zecale.cli.command_context.CommandContext.eth_addr

Definition at line 35 of file command_context.py.

◆ eth_network

zecale.cli.command_context.CommandContext.eth_network

Definition at line 34 of file command_context.py.

◆ eth_private_key

zecale.cli.command_context.CommandContext.eth_private_key

Definition at line 36 of file command_context.py.

◆ instance_file

zecale.cli.command_context.CommandContext.instance_file

Definition at line 33 of file command_context.py.


The documentation for this class was generated from the following file: