Ejemplo n.º 1
0
    def process_batch(self, pp: PairingParameters,
                      batch: AggregatedTransaction,
                      application_contract_address: str, eth_addr: str,
                      eth_private_key: Optional[bytes]) -> bytes:
        """
        Send a batch to the contracts process_batch entry point. Returns the
        transaction ID.
        """

        # Encode the parameters of the entry point and create a local call
        # object. The proof and inputs are encoded into contract parameters,
        # and the nested_parameters are passed as raw bytes arrays.
        proof_evm = self.zksnark.proof_to_contract_parameters(
            batch.ext_proof.proof, pp)
        inputs_evm = hex_list_to_uint256_list(batch.ext_proof.inputs)

        contract_call = self.instance.functions.process_batch(
            proof_evm, inputs_evm, batch.nested_parameters,
            application_contract_address)

        # Broadcast the call
        return send_contract_call(
            self.web3,
            contract_call,
            eth_addr,
            eth_private_key,
            None,  # TODO: value (fee?)
            None)
Ejemplo n.º 2
0
def token_approve(
        ctx: Context,
        value: str,
        eth_addr: str,
        eth_private_key: str,
        wait: bool,
        instance_file: str) -> None:
    """
    Approve the mixer to spend some amount of ERC20/223 tokens
    """
    approve_value = EtherValue(value)
    eth_addr = load_eth_address(eth_addr)
    eth_private_key_data = load_eth_private_key(eth_private_key)
    web3 = open_web3_from_network(get_eth_network(ctx.obj["eth_network"]))
    mixer_desc = load_mixer_description(instance_file)
    if not mixer_desc.token:
        raise ClickException("no token for mixer {mixer_desc.mixer.address}")

    token_instance = mixer_desc.token.instantiate(web3)
    approve_call = token_instance.functions.approve(
        mixer_desc.mixer.address,
        approve_value.wei)
    tx_hash = send_contract_call(
        web3, approve_call, eth_addr, eth_private_key_data)

    if wait:
        web3.eth.waitForTransactionReceipt(tx_hash)  # pylint: disable=no-member
    else:
        print(tx_hash.hex())
Ejemplo n.º 3
0
def mint_token(web3: Any, token_instance: Any, spender_address: str,
               deployer_address: str, deployer_private_key: Optional[bytes],
               token_amount: EtherValue) -> bytes:
    mint_call = token_instance.functions.mint(spender_address,
                                              token_amount.wei)
    return send_contract_call(web3=web3,
                              call=mint_call,
                              sender_eth_addr=deployer_address,
                              sender_eth_private_key=deployer_private_key)
Ejemplo n.º 4
0
 def mix(self,
         mix_params: MixParameters,
         sender_eth_address: str,
         sender_eth_private_key: Optional[bytes],
         tx_value: EtherValue,
         call_gas: Optional[int] = None) -> str:
     """
     Given a MixParameters object, create and broadcast a transaction
     performing the appropriate mix call.
     """
     mixer_call = self._create_mix_call(mix_params)
     tx_hash = contracts.send_contract_call(self.web3, mixer_call,
                                            sender_eth_address,
                                            sender_eth_private_key,
                                            tx_value, call_gas)
     return tx_hash.hex()
Ejemplo n.º 5
0
    def zklay_deposit(self,
                      deposit_params: DepositParameters,
                      sender_eth_address: str,
                      sender_eth_private_key: Optional[bytes],
                      tx_value: EtherValue,
                      call_gas: int = constants.DEFAULT_MIX_GAS_WEI) -> str:
        zksnark = get_zksnark_provider(self.prover_config.zksnark_name)
        pp = self.prover_config.pairing_parameters
        mix_params_eth = deposit_parameters_to_contract_arguments(
            zksnark, pp, deposit_params)

        deposit_call = self.mixer_instance.functions.deposit(
            *deposit_params_eth)
        tx_hash = contracts.send_contract_call(self.web3, deposit_call,
                                               sender_eth_address,
                                               sender_eth_private_key,
                                               tx_value,
                                               constants.DEFAULT_MIX_GAS_WEI)
        return tx_hash.hex()
Ejemplo n.º 6
0
def deploy_token(web3: Any, deployer_address: str,
                 deployer_private_key: Optional[bytes],
                 deployment_gas: Optional[int]) -> Any:
    """
    Deploy the testing ERC20 token contract
    """
    token_interface = compile_token()
    token = web3.eth.contract(abi=token_interface['abi'],
                              bytecode=token_interface['bin'])
    constructor_call = token.constructor()
    tx_hash = send_contract_call(web3=web3,
                                 call=constructor_call,
                                 sender_eth_addr=deployer_address,
                                 sender_eth_private_key=deployer_private_key,
                                 value=None,
                                 gas=deployment_gas)
    tx_receipt = web3.eth.waitForTransactionReceipt(tx_hash)

    token = web3.eth.contract(
        address=tx_receipt.contractAddress,
        abi=token_interface['abi'],
    )
    return token