mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 12:28:09 +00:00
style(python/monero): improve type signature on Monero functions
This commit is contained in:
parent
0c1eb0c30d
commit
6feada2eed
1
python/.changelog.d/2219.changed
Normal file
1
python/.changelog.d/2219.changed
Normal file
@ -0,0 +1 @@
|
|||||||
|
`trezorctl monero` network type arguments now accept symbolic names instead of numbers.
|
@ -18,8 +18,8 @@ from typing import TYPE_CHECKING, Dict
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from .. import monero, tools
|
from .. import messages, monero, tools
|
||||||
from . import with_client
|
from . import ChoiceType, with_client
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client import TrezorClient
|
from ..client import TrezorClient
|
||||||
@ -36,29 +36,38 @@ def cli() -> None:
|
|||||||
@click.option("-n", "--address", required=True, help=PATH_HELP)
|
@click.option("-n", "--address", required=True, help=PATH_HELP)
|
||||||
@click.option("-d", "--show-display", is_flag=True)
|
@click.option("-d", "--show-display", is_flag=True)
|
||||||
@click.option(
|
@click.option(
|
||||||
"-t", "--network-type", type=click.Choice(["0", "1", "2", "3"]), default="0"
|
"-t",
|
||||||
|
"--network-type",
|
||||||
|
type=ChoiceType({m.name: m for m in messages.MoneroNetworkType}),
|
||||||
|
default=messages.MoneroNetworkType.MAINNET,
|
||||||
)
|
)
|
||||||
@with_client
|
@with_client
|
||||||
def get_address(
|
def get_address(
|
||||||
client: "TrezorClient", address: str, show_display: bool, network_type: str
|
client: "TrezorClient",
|
||||||
|
address: str,
|
||||||
|
show_display: bool,
|
||||||
|
network_type: messages.MoneroNetworkType,
|
||||||
) -> bytes:
|
) -> bytes:
|
||||||
"""Get Monero address for specified path."""
|
"""Get Monero address for specified path."""
|
||||||
address_n = tools.parse_path(address)
|
address_n = tools.parse_path(address)
|
||||||
return monero.get_address(client, address_n, show_display, int(network_type))
|
return monero.get_address(client, address_n, show_display, network_type)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option("-n", "--address", required=True, help=PATH_HELP)
|
@click.option("-n", "--address", required=True, help=PATH_HELP)
|
||||||
@click.option(
|
@click.option(
|
||||||
"-t", "--network-type", type=click.Choice(["0", "1", "2", "3"]), default="0"
|
"-t",
|
||||||
|
"--network-type",
|
||||||
|
type=ChoiceType({m.name: m for m in messages.MoneroNetworkType}),
|
||||||
|
default=messages.MoneroNetworkType.MAINNET,
|
||||||
)
|
)
|
||||||
@with_client
|
@with_client
|
||||||
def get_watch_key(
|
def get_watch_key(
|
||||||
client: "TrezorClient", address: str, network_type: str
|
client: "TrezorClient", address: str, network_type: messages.MoneroNetworkType
|
||||||
) -> Dict[str, str]:
|
) -> Dict[str, str]:
|
||||||
"""Get Monero watch key for specified path."""
|
"""Get Monero watch key for specified path."""
|
||||||
address_n = tools.parse_path(address)
|
address_n = tools.parse_path(address)
|
||||||
res = monero.get_watch_key(client, address_n, int(network_type))
|
res = monero.get_watch_key(client, address_n, network_type)
|
||||||
# TODO: could be made required in MoneroWatchKey
|
# TODO: could be made required in MoneroWatchKey
|
||||||
assert res.address is not None
|
assert res.address is not None
|
||||||
assert res.watch_key is not None
|
assert res.watch_key is not None
|
||||||
|
@ -36,7 +36,7 @@ def get_address(
|
|||||||
client: "TrezorClient",
|
client: "TrezorClient",
|
||||||
n: "Address",
|
n: "Address",
|
||||||
show_display: bool = False,
|
show_display: bool = False,
|
||||||
network_type: int = 0,
|
network_type: messages.MoneroNetworkType = messages.MoneroNetworkType.MAINNET,
|
||||||
) -> "MessageType":
|
) -> "MessageType":
|
||||||
return client.call(
|
return client.call(
|
||||||
messages.MoneroGetAddress(
|
messages.MoneroGetAddress(
|
||||||
@ -47,7 +47,9 @@ def get_address(
|
|||||||
|
|
||||||
@expect(messages.MoneroWatchKey)
|
@expect(messages.MoneroWatchKey)
|
||||||
def get_watch_key(
|
def get_watch_key(
|
||||||
client: "TrezorClient", n: "Address", network_type: int = 0
|
client: "TrezorClient",
|
||||||
|
n: "Address",
|
||||||
|
network_type: messages.MoneroNetworkType = messages.MoneroNetworkType.MAINNET,
|
||||||
) -> "MessageType":
|
) -> "MessageType":
|
||||||
return client.call(
|
return client.call(
|
||||||
messages.MoneroGetWatchKey(address_n=n, network_type=network_type)
|
messages.MoneroGetWatchKey(address_n=n, network_type=network_type)
|
||||||
|
Loading…
Reference in New Issue
Block a user