mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-22 13:21:03 +00:00
apps.wallet: add GetAddress
This commit is contained in:
parent
4e47ae1606
commit
c5dfcb53d1
@ -1,7 +1,7 @@
|
|||||||
from trezor.wire import register_type, protobuf_handler
|
from trezor.wire import register_type, protobuf_handler
|
||||||
from trezor.utils import unimport
|
from trezor.utils import unimport
|
||||||
from trezor.messages.wire_types import \
|
from trezor.messages.wire_types import \
|
||||||
GetPublicKey, SignMessage
|
GetPublicKey, GetAddress, SignMessage
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
@ -10,6 +10,12 @@ def dispatch_GetPublicKey(*args, **kwargs):
|
|||||||
return layout_get_public_key(*args, **kwargs)
|
return layout_get_public_key(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@unimport
|
||||||
|
def dispatch_GetAddress(*args, **kwargs):
|
||||||
|
from .layout_get_address import layout_get_address
|
||||||
|
return layout_get_address(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
def dispatch_SignMessage(*args, **kwargs):
|
def dispatch_SignMessage(*args, **kwargs):
|
||||||
from .layout_sign_message import layout_sign_message
|
from .layout_sign_message import layout_sign_message
|
||||||
@ -18,4 +24,5 @@ def dispatch_SignMessage(*args, **kwargs):
|
|||||||
|
|
||||||
def boot():
|
def boot():
|
||||||
register_type(GetPublicKey, protobuf_handler, dispatch_GetPublicKey)
|
register_type(GetPublicKey, protobuf_handler, dispatch_GetPublicKey)
|
||||||
|
register_type(GetAddress, protobuf_handler, dispatch_GetAddress)
|
||||||
register_type(SignMessage, protobuf_handler, dispatch_SignMessage)
|
register_type(SignMessage, protobuf_handler, dispatch_SignMessage)
|
||||||
|
46
src/apps/wallet/layout_get_address.py
Normal file
46
src/apps/wallet/layout_get_address.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
from trezor import wire, ui
|
||||||
|
from trezor.utils import unimport
|
||||||
|
|
||||||
|
|
||||||
|
@unimport
|
||||||
|
async def layout_get_address(message, session_id):
|
||||||
|
from trezor.messages.Address import Address
|
||||||
|
from trezor.messages.FailureType import Other
|
||||||
|
from ..common.seed import get_node
|
||||||
|
|
||||||
|
address_n = getattr(message, 'address_n', ())
|
||||||
|
coin_name = getattr(message, 'coin_name', None)
|
||||||
|
multisig = getattr(message, 'multisig', None)
|
||||||
|
show_display = getattr(message, 'show_display', False)
|
||||||
|
|
||||||
|
# TODO: support custom coin addresses
|
||||||
|
# TODO: support multisig addresses
|
||||||
|
|
||||||
|
if coin_name != 'Bitcoin':
|
||||||
|
raise wire.FailureError(Other, 'GetAddress.coin_name is unsupported')
|
||||||
|
if multisig:
|
||||||
|
raise wire.FailureError(Other, 'GetAddress.multisig is unsupported')
|
||||||
|
|
||||||
|
node = await get_node(session_id, address_n)
|
||||||
|
|
||||||
|
address_version = 0
|
||||||
|
address = node.address(address_version)
|
||||||
|
|
||||||
|
if show_display:
|
||||||
|
await _show_address(session_id, address)
|
||||||
|
return Address(address=address)
|
||||||
|
|
||||||
|
|
||||||
|
async def _show_address(session_id, address):
|
||||||
|
from trezor.messages.ButtonRequestType import Address
|
||||||
|
from trezor.ui.text import Text
|
||||||
|
from ..common.confirm import require_confirm
|
||||||
|
|
||||||
|
content = Text('Confirm address', ui.ICON_RESET,
|
||||||
|
ui.MONO, *_split_address(address))
|
||||||
|
await require_confirm(session_id, content, code=Address)
|
||||||
|
|
||||||
|
|
||||||
|
def _split_address(address):
|
||||||
|
from trezor.utils import chunks
|
||||||
|
return chunks(address, 17)
|
Loading…
Reference in New Issue
Block a user