6 load_zeth_address, open_wallet, parse_output, do_sync, load_eth_address, \
7 load_eth_private_key, zeth_note_short_print, create_prover_client
11 from zeth.api.zeth_messages_pb2
import ZethNote
12 from click
import command, option, pass_context, ClickException, Context
13 from typing
import List, Tuple, Optional
18 @option(
"--vin", default=
"0", help=
"Public input value")
19 @option(
"--vout", default=
"0", help=
"Public output value")
20 @option(
"--in",
"input_notes", multiple=
True, help=
"Input note identifier")
25 help=
"<receiver_pub_addr>,<value> where <receiver_pub_addr> can be a "
26 "filename or hex address")
27 @option(
"--eth-addr", help=
"Sender's eth address or address filename")
28 @option(
"--eth-private-key", help=
"Sender's eth private key file")
29 @option(
"--wait", is_flag=
True, help=
"Wait for transaction to be mined")
31 "--for-dispatch-call",
33 help=
"Generate signature for later call to dispatch (implies --dry-run)")
34 @option(
"--dump-parameters", help=
"Write mix parameters to file ('-' for stdout)")
36 "--dump-signing-keypair",
37 help=
"Write signing keypair to file ('-' for stdout). "
38 "USE ONLY FOR DEBUGGING.")
39 @option(
"--dry-run",
"-n", is_flag=
True, help=
"Do not send the mix transaction")
45 input_notes: List[str],
46 output_specs: List[str],
47 eth_addr: Optional[str],
48 eth_private_key: Optional[str],
50 for_dispatch_call: bool,
51 dump_parameters: Optional[str],
52 dump_signing_keypair: Optional[str],
53 dry_run: bool) ->
None:
58 if len(input_notes) > JS_INPUTS:
59 raise ClickException(f
"too many inputs (max {JS_INPUTS})")
60 if len(output_specs) > JS_OUTPUTS:
61 raise ClickException(f
"too many outputs (max {JS_OUTPUTS})")
68 client_ctx, prover_client)
71 zeth_client.mixer_instance, zeth_address.addr_sk, client_ctx)
73 inputs: List[Tuple[int, ZethNote]] = [
74 wallet.find_note(note_id).as_input()
for note_id
in input_notes]
75 outputs: List[Tuple[ZethAddressPub, EtherValue]] = [
80 sum([
int(note.value, 16)
for _, note
in inputs]))
81 output_note_sum = sum([value
for _, value
in outputs],
EtherValue(0))
82 if vin_pub + input_note_sum != vout_pub + output_note_sum:
83 raise ClickException(
"input and output value mismatch")
89 tx_value =
EtherValue(0)
if mixer_desc.token
else vin_pub
93 mix_params, signing_keypair = \
94 zeth_client.create_mix_parameters_and_signing_key(
97 zeth_address.ownership_keypair(),
103 for_dispatch_call=for_dispatch_call)
107 if dump_parameters ==
'-':
108 print(f
"mix_params={mix_params.to_json()}")
110 with open(dump_parameters,
"w")
as mix_params_f:
111 json.dump(mix_params.to_json_dict(), mix_params_f)
114 if dump_signing_keypair:
115 if dump_signing_keypair ==
'-':
116 print(f
"signing_key={signing_keypair.to_json_dict()}")
118 with open(dump_signing_keypair,
"w")
as signing_keypair_f:
119 json.dump(signing_keypair.to_json_dict(), signing_keypair_f)
122 if for_dispatch_call
or dry_run:
126 tx_hash = zeth_client.mix(
127 mix_params=mix_params,
128 sender_eth_address=eth_address,
129 sender_eth_private_key=eth_private_key_data,
134 pp = prover_client.get_configuration().pairing_parameters
135 do_sync(zeth_client.web3, wallet, pp, tx_hash, zeth_note_short_print)