Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
get.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.cli.defaults import APPLICATION_INSTANCE_FILE_DEFAULT
6 from zeth.core.contracts import InstanceDescription
7 from zeth.cli.utils import open_web3_from_network
8 import json
9 from click import command, argument, option, pass_context, Context, ClickException
10 from typing import Optional
11 
12 
13 @command()
14 @argument("scalar", type=int)
15 @option(
16  "--instance-file",
17  default=APPLICATION_INSTANCE_FILE_DEFAULT,
18  help="File to write instance information to")
19 @option(
20  "--check", type=int, help="Check the result against the given value")
21 @pass_context
22 def get(
23  ctx: Context,
24  scalar: int,
25  instance_file: str,
26  check: Optional[int]) -> None:
27  """
28  Query the deployed contract to find the value stored for a given scalar.
29  (These values are the parameters submitted along side the proof for the
30  given scalar.)
31  """
32 
33  eth_network = ctx.obj["eth_network"]
34 
35  # Load the contract instance
36  with open(instance_file, "r") as instance_f:
37  instance_desc = InstanceDescription.from_json_dict(json.load(instance_f))
38 
39  # Instantiate
40  web3 = open_web3_from_network(eth_network)
41  app_contract = instance_desc.instantiate(web3)
42  result: int = app_contract.functions.get(scalar).call()
43  print(f"{scalar}: {result}")
44 
45  if (check is not None) and (result != check):
46  raise ClickException("state check failed")
zecale.cli.defaults
Definition: defaults.py:1
zecale.dummy_app.get.get
None get(Context ctx, int scalar, str instance_file, Optional[int] check)
Definition: get.py:22