Skip to content

Commit

Permalink
client: move funding command into zeth_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
dtebbs committed Sep 28, 2020
1 parent d129aa5 commit abd9b93
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/usr/bin/env python3

# Copyright (c) 2015-2020 Clearmatics Technologies Ltd
#
# SPDX-License-Identifier: LGPL-3.0+

from zeth.cli.constants import ETH_ADDRESS_DEFAULT, \
ETH_NETWORK_FILE_DEFAULT, ETH_NETWORK_DEFAULT
from zeth.cli.constants import ETH_ADDRESS_DEFAULT
from zeth.cli.utils import \
get_eth_network, load_eth_address, EtherValue, open_web3_from_network
from click import command, option
from click import command, option, pass_context, Context
from typing import Optional


FUND_AMOUNT_DEFAULT = 1000000


Expand All @@ -19,19 +17,14 @@
"--eth-addr",
help=f"Address or address filename (default: {ETH_ADDRESS_DEFAULT})")
@option("--source-addr", help="Address or address filename (optional)")
@option(
"--eth-network",
default=None,
help="Ethereum RPC endpoint, network or config file "
f"(default: '{ETH_NETWORK_FILE_DEFAULT}' if it exists, otherwise "
f"'{ETH_NETWORK_DEFAULT}')")
@option(
"--amount",
type=int,
default=FUND_AMOUNT_DEFAULT,
help=f"Amount to fund (default: {FUND_AMOUNT_DEFAULT})")
def fund_eth_address(
eth_network: Optional[str],
@pass_context
def eth_fund(
ctx: Context,
eth_addr: Optional[str],
source_addr: Optional[str],
amount: int) -> None:
Expand All @@ -40,14 +33,14 @@ def fund_eth_address(
the RPC host is used.
"""
eth_addr = load_eth_address(eth_addr)
network = get_eth_network(eth_network)
web3 = open_web3_from_network(network)
eth_network = get_eth_network(ctx.obj["eth_network"])
web3 = open_web3_from_network(eth_network)

if not source_addr:
# Use the first hosted address.
source_addr = web3.eth.accounts[0] # pylint: disable=no-member

if network.name == "autonity-helloworld":
if eth_network.name == "autonity-helloworld":
# The Autonity helloworld network supplies hosted accounts, secured
# with the password 'test'. Attempt to unlock it.
# pylint: disable=import-outside-toplevel, no-member
Expand All @@ -64,7 +57,3 @@ def fund_eth_address(
"to": eth_addr,
"value": EtherValue(amount).wei
})


if __name__ == "__main__":
fund_eth_address() # pylint: disable=no-value-for-parameter
6 changes: 3 additions & 3 deletions client/zeth/helper/eth_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from zeth.cli.utils import \
get_eth_network, load_eth_address, EtherValue, open_web3_from_network, \
load_eth_private_key
from click import command, option, pass_context, argument, ClickException
from typing import Optional, Any
from click import command, option, pass_context, argument, ClickException, Context
from typing import Optional

FUND_AMOUNT_DEFAULT = 1000000

Expand All @@ -29,7 +29,7 @@
@argument("dest-addr")
@pass_context
def eth_send(
ctx: Any,
ctx: Context,
dest_addr: str,
eth_private_key: Optional[str],
eth_addr: Optional[str],
Expand Down
2 changes: 2 additions & 0 deletions client/zeth/helper/zeth_helper
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from zeth.helper.eth_gen_network_config import eth_gen_network_config
from zeth.helper.eth_gen_address import eth_gen_address
from zeth.helper.eth_get_balance import eth_get_balance
from zeth.helper.eth_fund import eth_fund
from zeth.helper.eth_send import eth_send
from zeth.helper.token_approve import token_approve
from zeth.cli.constants import ETH_NETWORK_FILE_DEFAULT, ETH_NETWORK_DEFAULT
Expand Down Expand Up @@ -47,6 +48,7 @@ def zeth_helper(ctx: Context, eth_network: str) -> None:
zeth_helper.add_command(eth_gen_network_config)
zeth_helper.add_command(eth_gen_address)
zeth_helper.add_command(eth_get_balance)
zeth_helper.add_command(eth_fund)
zeth_helper.add_command(eth_send)
zeth_helper.add_command(token_approve)
zeth_helper.add_command(help)
Expand Down
3 changes: 1 addition & 2 deletions scripts/test_zeth_cli_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ function setup_user_local_key() {
! [ -e eth-network ] && \
(zeth_helper eth-gen-network-config $2)
! [ -e eth-address ] && \
(zeth_helper eth-gen-address && \
python -m test_commands.fund_eth_address)
(zeth_helper eth-gen-address && zeth_helper eth-fund)
! [ -e zeth-address.priv ] && \
(zeth gen-address)
popd
Expand Down

0 comments on commit abd9b93

Please sign in to comment.