Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
zeth.core.contracts.InstanceDescription Class Reference

Public Member Functions

def __init__ (self, str address, Dict[str, Any] abi)
 
Dict[str, Any] to_json_dict (self)
 
Any instantiate (self, Any web3)
 

Static Public Member Functions

InstanceDescription from_json_dict (Dict[str, Any] desc_json)
 
InstanceDescription deploy (Any web3, str source_file, str contract_name, str deployer_eth_address, Optional[bytes] deployer_eth_private_key, Optional[int] deployment_gas, Dict[str, Any] compiler_flags=None, Iterable[Any] args=None)
 
InstanceDescription deploy_from_compiled (Any web3, str deployer_eth_address, Optional[bytes] deployer_eth_private_key, Optional[int] deployment_gas, Any compiled, *Any args)
 
Any compile (str source_file, str contract_name, Dict[str, Any] compiler_flags=None)
 

Public Attributes

 address
 
 abi
 

Detailed Description

Minimal data required to instantiate the in-memory interface to a contract.

Definition at line 21 of file contracts.py.

Constructor & Destructor Documentation

◆ __init__()

def zeth.core.contracts.InstanceDescription.__init__ (   self,
str  address,
Dict[str, Any]  abi 
)

Definition at line 25 of file contracts.py.

25  def __init__(self, address: str, abi: Dict[str, Any]):
26  self.address = address
27  self.abi = abi
28 

Member Function Documentation

◆ compile()

Any zeth.core.contracts.InstanceDescription.compile ( str  source_file,
str  contract_name,
Dict[str, Any]   compiler_flags = None 
)
static

Definition at line 96 of file contracts.py.

96  def compile(
97  source_file: str,
98  contract_name: str,
99  compiler_flags: Dict[str, Any] = None) \
100  -> Any:
101  compiled_all = compile_files([source_file], **(compiler_flags or {}))
102  assert compiled_all
103  compiled = compiled_all[f"{source_file}:{contract_name}"]
104  assert compiled
105  return compiled
106 
Here is the call graph for this function:

◆ deploy()

InstanceDescription zeth.core.contracts.InstanceDescription.deploy ( Any  web3,
str  source_file,
str  contract_name,
str  deployer_eth_address,
Optional[bytes]  deployer_eth_private_key,
Optional[int]  deployment_gas,
Dict[str, Any]   compiler_flags = None,
Iterable[Any]   args = None 
)
static
Compile and deploy a contract, returning the live instance and an instance
description (which the caller should save in order to access the
instance in the future).

Definition at line 40 of file contracts.py.

40  def deploy(
41  web3: Any,
42  source_file: str,
43  contract_name: str,
44  deployer_eth_address: str,
45  deployer_eth_private_key: Optional[bytes],
46  deployment_gas: Optional[int],
47  compiler_flags: Dict[str, Any] = None,
48  args: Iterable[Any] = None) -> InstanceDescription:
49  """
50  Compile and deploy a contract, returning the live instance and an instance
51  description (which the caller should save in order to access the
52  instance in the future).
53  """
54  compiled = InstanceDescription.compile(
55  source_file, contract_name, compiler_flags)
56  assert compiled
57  instance_desc = InstanceDescription.deploy_from_compiled(
58  web3,
59  deployer_eth_address,
60  deployer_eth_private_key,
61  deployment_gas,
62  compiled,
63  *(args or []))
64  print(
65  f"deploy: contract: {contract_name} "
66  f"to address: {instance_desc.address}")
67  return instance_desc
68 

◆ deploy_from_compiled()

InstanceDescription zeth.core.contracts.InstanceDescription.deploy_from_compiled ( Any  web3,
str  deployer_eth_address,
Optional[bytes]  deployer_eth_private_key,
Optional[int]  deployment_gas,
Any  compiled,
*Any  args 
)
static

Definition at line 70 of file contracts.py.

70  def deploy_from_compiled(
71  web3: Any,
72  deployer_eth_address: str,
73  deployer_eth_private_key: Optional[bytes],
74  deployment_gas: Optional[int],
75  compiled: Any,
76  *args: Any) -> InstanceDescription:
77  contract = web3.eth.contract(
78  abi=compiled['abi'], bytecode=compiled['bin'])
79  construct_call = contract.constructor(*args)
80  tx_hash = send_contract_call(
81  web3,
82  construct_call,
83  deployer_eth_address,
84  deployer_eth_private_key,
85  None,
86  deployment_gas)
87 
88  tx_receipt = web3.eth.waitForTransactionReceipt(tx_hash, 10000)
89  contract_address = tx_receipt['contractAddress']
90  print(
91  f"deploy: tx_hash={tx_hash[0:8].hex()}, " +
92  f" gasUsed={tx_receipt.gasUsed}, status={tx_receipt.status}")
93  return InstanceDescription(contract_address, compiled['abi'])
94 
Here is the call graph for this function:

◆ from_json_dict()

InstanceDescription zeth.core.contracts.InstanceDescription.from_json_dict ( Dict[str, Any]  desc_json)
static

Definition at line 36 of file contracts.py.

36  def from_json_dict(desc_json: Dict[str, Any]) -> InstanceDescription:
37  return InstanceDescription(desc_json["address"], desc_json["abi"])
38 

◆ instantiate()

Any zeth.core.contracts.InstanceDescription.instantiate (   self,
Any  web3 
)
Return the instantiated contract

Definition at line 107 of file contracts.py.

107  def instantiate(self, web3: Any) -> Any:
108  """
109  Return the instantiated contract
110  """
111  return web3.eth.contract(address=self.address, abi=self.abi)
112 
113 

◆ to_json_dict()

Dict[str, Any] zeth.core.contracts.InstanceDescription.to_json_dict (   self)

Definition at line 29 of file contracts.py.

29  def to_json_dict(self) -> Dict[str, Any]:
30  return {
31  "address": self.address,
32  "abi": self.abi
33  }
34 
Here is the caller graph for this function:

Member Data Documentation

◆ abi

zeth.core.contracts.InstanceDescription.abi

Definition at line 27 of file contracts.py.

◆ address

zeth.core.contracts.InstanceDescription.address

Definition at line 26 of file contracts.py.


The documentation for this class was generated from the following file:
zeth.cli.zeth_deploy.deploy
None deploy(Context ctx, Optional[str] eth_addr, Optional[str] eth_private_key, str instance_out, Optional[str] token_address, Optional[str] permitted_dispatcher, Optional[str] vk_hash, Optional[int] deploy_gas)
Definition: zeth_deploy.py:29
zeth.core.contracts.compile_files
Any compile_files(List[str] files, **Any kwargs)
Definition: contracts.py:122
zeth.core.contracts.send_contract_call
bytes send_contract_call(Any web3, Any call, str sender_eth_addr, Optional[bytes] sender_eth_private_key=None, Optional[EtherValue] value=None, Optional[int] gas=None)
Definition: contracts.py:131