Skip to content

Commit

Permalink
console
Browse files Browse the repository at this point in the history
  • Loading branch information
youwenbusi committed Jul 29, 2020
1 parent 0a95beb commit e294939
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion commands/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

FISCO_RPC_ENDPOINT_DEFAULT = "http://119.23.46.126:8545"
PROVER_SERVER_ENDPOINT_DEFAULT = "119.23.46.126:50051"
PROVER_SERVER_ENDPOINT_DEFAULT = "139.9.222.236:50051"

FISCO_ADDRESS_FILE = "fisco_account.keystore"
ADDRESS_FILE_DEFAULT = "zeth-address.json"
Expand Down
6 changes: 3 additions & 3 deletions commands/event_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ def make_wallet() -> List[Wallet]:
wallet_list = []
for username in os.listdir(USER_DIR):
wallet_dir = "{}/{}/{}".format(USER_DIR, username, WALLET_DIR_DEFAULT)
if os.path.exists(wallet_dir) is False:
raise ClickException(f"invalid wallet_dir: {wallet_dir}")
zeth_address = load_zeth_address(username)
wallet_list.append(Wallet(None, username, wallet_dir, zeth_address.addr_sk))
return wallet_list
Expand All @@ -83,7 +81,9 @@ def on_event(self, eventdata):
print("new_merkle_root in log: ", new_merkle_root)
for wallet in make_wallet():
received_notes = wallet.receive_notes(mix_result.output_events)
print(f"{wallet.username} received notes: {received_notes}")
spent_commits = wallet.mark_nullifiers_used(mix_result.nullifiers)
for commit in spent_commits:
print(f"{wallet.username} spent commits: {commit}")
wallet.update_and_save_state()
update_merkle_root = wallet.merkle_tree.get_root()
print(f"The update_merkle_root in wallet of {wallet.username} is {update_merkle_root}")
Expand Down
4 changes: 2 additions & 2 deletions commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: LGPL-3.0+

from __future__ import annotations
from commands.constants import WALLET_USERNAME, FISCO_ADDRESS_FILE, USER_DIR, ADDRESS_FILE_DEFAULT, WALLET_DIR_DEFAULT
from commands.constants import FISCO_ADDRESS_FILE, USER_DIR, ADDRESS_FILE_DEFAULT, WALLET_DIR_DEFAULT
from zeth.zeth_address import ZethAddressPub, ZethAddressPriv, ZethAddress
from zeth.contracts import \
get_mix_results
Expand Down Expand Up @@ -172,7 +172,7 @@ def open_wallet(
Load a wallet using a secret key.
"""
wallet_dir = "{}/{}/{}".format(USER_DIR, username, WALLET_DIR_DEFAULT)
return Wallet(mixer_instance, WALLET_USERNAME, wallet_dir, js_secret)
return Wallet(mixer_instance, username, wallet_dir, js_secret)


def do_sync(
Expand Down
2 changes: 1 addition & 1 deletion commands/zeth_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def deposit(
outputs,
tx_value)

print("receipt output :", outputresult)
print("receipt status: ", receipt['status'])
#do_sync(wallet, receipt)
if __name__ == '__main__':
deposit()
28 changes: 13 additions & 15 deletions commands/zeth_ls_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@
from click import Context, command, option, pass_context
import sys
sys.path.append('../')
from contract.Groth16Mixer import Groth16Mixer
#from contract.Groth16Mixer import Groth16Mixer

@command()
@option("--mixer-addr", help="The Groth16Mixer contract address you want to use")
@option("--balance", is_flag=True, help="Show total balance")
@option("--spent", is_flag=True, help="Show spent notes")
@pass_context
def ls_notes(ctx: Context, mixer_addr: str, balance: bool, spent: bool) -> None:
#@option("--mixer-addr", help="The Groth16Mixer contract address you want to use")
@option("--username", help="The account you want to use")
#@option("--balance", is_flag=True, help="Show total balance")
#@option("--spent", is_flag=True, help="Show spent notes")
def ls_notes(username: str) -> None:
"""
List the set of notes owned by this wallet
"""
client_ctx = ctx.obj
#client_ctx = ctx.obj
#web3 = open_web3_from_ctx(client_ctx)
#mixer_desc = load_mixer_description_from_ctx(client_ctx)
#mixer_instance = mixer_desc.mixer.instantiate(web3)
mixer_instance = Groth16Mixer(mixer_addr)
js_secret = load_zeth_address_secret(client_ctx)
wallet = open_wallet(mixer_instance, js_secret, client_ctx)
#mixer_instance = Groth16Mixer(mixer_addr)
js_secret = load_zeth_address_secret(username)
wallet = open_wallet(None, js_secret, username)

total = EtherValue(0)
for addr, short_commit, value in wallet.note_summaries():
print(f"{short_commit}: value={value.ether()}, addr={addr}")
total = total + value

if balance:
print(f"TOTAL BALANCE: {total.ether()}")

if not spent:
return
print(f"TOTAL BALANCE: {total.ether()}")

print("SPENT NOTES:")
for addr, short_commit, value in wallet.spent_note_summaries():
print(f"{short_commit}: value={value.ether()}, addr={addr}")
if __name__ == '__main__':
ls_notes()
1 change: 1 addition & 0 deletions test_commands/Mixer.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{'inputs': [{'internalType': 'uint256', 'name': 'mk_depth', 'type': 'uint256'}, {'internalType': 'address', 'name': 'token', 'type': 'address'}, {'internalType': 'uint256[2]', 'name': 'Alpha', 'type': 'uint256[2]'}, {'internalType': 'uint256[2]', 'name': 'Beta1', 'type': 'uint256[2]'}, {'internalType': 'uint256[2]', 'name': 'Beta2', 'type': 'uint256[2]'}, {'internalType': 'uint256[2]', 'name': 'Delta1', 'type': 'uint256[2]'}, {'internalType': 'uint256[2]', 'name': 'Delta2', 'type': 'uint256[2]'}, {'internalType': 'uint256[]', 'name': 'ABC_coords', 'type': 'uint256[]'}], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'constructor'}, {'anonymous': False, 'inputs': [{'indexed': False, 'internalType': 'string', 'name': 'message', 'type': 'string'}], 'name': 'LogDebug', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': False, 'internalType': 'bytes32', 'name': 'message', 'type': 'bytes32'}], 'name': 'LogDebug', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': False, 'internalType': 'bytes32', 'name': 'root', 'type': 'bytes32'}, {'indexed': False, 'internalType': 'bytes32[2]', 'name': 'nullifiers', 'type': 'bytes32[2]'}, {'indexed': False, 'internalType': 'bytes32[2]', 'name': 'commitments', 'type': 'bytes32[2]'}, {'indexed': False, 'internalType': 'bytes[2]', 'name': 'ciphertexts', 'type': 'bytes[2]'}], 'name': 'LogMix', 'type': 'event'}, {'constant': True, 'inputs': [{'internalType': 'uint256[9]', 'name': 'primary_inputs', 'type': 'uint256[9]'}], 'name': 'assemble_hsig', 'outputs': [{'internalType': 'bytes32', 'name': 'hsig', 'type': 'bytes32'}], 'payable': False, 'stateMutability': 'pure', 'type': 'function'}, {'constant': True, 'inputs': [{'internalType': 'uint256', 'name': 'index', 'type': 'uint256'}, {'internalType': 'uint256[9]', 'name': 'primary_inputs', 'type': 'uint256[9]'}], 'name': 'assemble_nullifier', 'outputs': [{'internalType': 'bytes32', 'name': 'nf', 'type': 'bytes32'}], 'payable': False, 'stateMutability': 'pure', 'type': 'function'}, {'constant': True, 'inputs': [{'internalType': 'uint256[9]', 'name': 'primary_inputs', 'type': 'uint256[9]'}], 'name': 'assemble_public_values', 'outputs': [{'internalType': 'uint256', 'name': 'vpub_in', 'type': 'uint256'}, {'internalType': 'uint256', 'name': 'vpub_out', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'pure', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'get_constants', 'outputs': [{'internalType': 'uint256', 'name': 'js_in', 'type': 'uint256'}, {'internalType': 'uint256', 'name': 'js_out', 'type': 'uint256'}, {'internalType': 'uint256', 'name': 'num_inputs', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'pure', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'bytes32', 'name': 'commitment', 'type': 'bytes32'}], 'name': 'insert', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'uint256[2]', 'name': 'a', 'type': 'uint256[2]'}, {'internalType': 'uint256[4]', 'name': 'b', 'type': 'uint256[4]'}, {'internalType': 'uint256[2]', 'name': 'c', 'type': 'uint256[2]'}, {'internalType': 'uint256[4]', 'name': 'vk', 'type': 'uint256[4]'}, {'internalType': 'uint256', 'name': 'sigma', 'type': 'uint256'}, {'internalType': 'uint256[9]', 'name': 'input', 'type': 'uint256[9]'}, {'internalType': 'bytes[2]', 'name': 'ciphertexts', 'type': 'bytes[2]'}], 'name': 'mix', 'outputs': [], 'payable': True, 'stateMutability': 'payable', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'token', 'outputs': [{'internalType': 'address', 'name': '', 'type': 'address'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': True, 'inputs': [{'internalType': 'address', 'name': 'from', 'type': 'address'}, {'internalType': 'uint256', 'name': 'value', 'type': 'uint256'}, {'internalType': 'bytes', 'name': 'data', 'type': 'bytes'}], 'name': 'tokenFallback', 'outputs': [], 'payable': False, 'stateMutability': 'pure', 'type': 'function'}]
1 change: 1 addition & 0 deletions test_commands/Mixer.bin

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test_commands/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing import Dict, List, Tuple, Optional, Any

# Web3 HTTP provider
TEST_PROVER_SERVER_ENDPOINT: str = "119.23.46.126:50051"
TEST_PROVER_SERVER_ENDPOINT: str = "139.9.222.236:50051"
#TEST_WEB3_PROVIDER_ENDPOINT: str = "http://localhost:8545"
TEST_NOTE_DIR: str = "_test_notes"

Expand Down
7 changes: 5 additions & 2 deletions test_commands/test_erc_token_mixing.py

Large diffs are not rendered by default.

0 comments on commit e294939

Please sign in to comment.