5 from __future__
import annotations
8 from zeth.core.utils
import hex_list_to_uint256_list
9 from zeth.core.pairing
import PairingParameters
10 from zeth.core.contracts
import InstanceDescription, send_contract_call, \
11 get_event_logs_from_tx_receipt
12 from zeth.core.zksnark
import IZKSnarkProvider, IVerificationKey
13 from os.path
import join
14 from typing
import Tuple, Optional, Any
18 CONTRACTS_DIR = join(ZECALE_DIR,
"contracts")
19 DISPATCHER_SOURCE_FILE = join(CONTRACTS_DIR,
"ZecaleDispatcher.sol")
20 DISPATCHER_DEPLOY_GAS = 5000000
25 Wrapper around operations on the zecale dispatcher contract.
31 instance_desc: InstanceDescription,
32 zksnark: IZKSnarkProvider):
34 self.
instance = instance_desc.instantiate(web3)
40 zksnark: IZKSnarkProvider,
41 pp: PairingParameters,
44 eth_private_key: Optional[bytes]
45 ) -> Tuple[DispatcherContract, InstanceDescription]:
47 Deploy the contract, returning an instance of this wrapper, and a
48 description (which can be saved to a file to later instantiate).
50 vk_evm = zksnark.verification_key_to_contract_parameters(vk, pp)
51 instance_desc = InstanceDescription.deploy(
53 DISPATCHER_SOURCE_FILE,
57 DISPATCHER_DEPLOY_GAS,
58 {
"allow_paths": CONTRACTS_DIR},
64 pp: PairingParameters,
65 batch: AggregatedTransaction,
66 application_contract_address: str,
68 eth_private_key: Optional[bytes]) -> bytes:
70 Send a batch to the contracts process_batch entry point. Returns the
77 proof_evm = self.
zksnark.proof_to_contract_parameters(
78 batch.ext_proof.proof, pp)
79 inputs_evm = hex_list_to_uint256_list(batch.ext_proof.inputs)
81 contract_call = self.
instance.functions.process_batch(
84 batch.nested_parameters,
85 application_contract_address)
88 return send_contract_call(
98 Print out debug log information from a dispatcher invocation
100 logs = get_event_logs_from_tx_receipt(self.
instance,
"log", tx_receipt)
101 for event_data
in logs:
102 print(f
"{event_data.args['a']}: {event_data.args['v']}")