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
|
||||
|
||||
from .. import monero, tools
|
||||
from . import with_client
|
||||
from .. import messages, monero, tools
|
||||
from . import ChoiceType, with_client
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..client import TrezorClient
|
||||
@ -36,29 +36,38 @@ def cli() -> None:
|
||||
@click.option("-n", "--address", required=True, help=PATH_HELP)
|
||||
@click.option("-d", "--show-display", is_flag=True)
|
||||
@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
|
||||
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:
|
||||
"""Get Monero address for specified path."""
|
||||
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()
|
||||
@click.option("-n", "--address", required=True, help=PATH_HELP)
|
||||
@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
|
||||
def get_watch_key(
|
||||
client: "TrezorClient", address: str, network_type: str
|
||||
client: "TrezorClient", address: str, network_type: messages.MoneroNetworkType
|
||||
) -> Dict[str, str]:
|
||||
"""Get Monero watch key for specified path."""
|
||||
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
|
||||
assert res.address is not None
|
||||
assert res.watch_key is not None
|
||||
|
@ -36,7 +36,7 @@ def get_address(
|
||||
client: "TrezorClient",
|
||||
n: "Address",
|
||||
show_display: bool = False,
|
||||
network_type: int = 0,
|
||||
network_type: messages.MoneroNetworkType = messages.MoneroNetworkType.MAINNET,
|
||||
) -> "MessageType":
|
||||
return client.call(
|
||||
messages.MoneroGetAddress(
|
||||
@ -47,7 +47,9 @@ def get_address(
|
||||
|
||||
@expect(messages.MoneroWatchKey)
|
||||
def get_watch_key(
|
||||
client: "TrezorClient", n: "Address", network_type: int = 0
|
||||
client: "TrezorClient",
|
||||
n: "Address",
|
||||
network_type: messages.MoneroNetworkType = messages.MoneroNetworkType.MAINNET,
|
||||
) -> "MessageType":
|
||||
return client.call(
|
||||
messages.MoneroGetWatchKey(address_n=n, network_type=network_type)
|
||||
|
Loading…
Reference in New Issue
Block a user