apps: reduce unimport usage

unimport should be used only on the workflow dispatchers.
pull/25/head
Jan Pochyla 6 years ago
parent 898b33cffb
commit 710306495e

@ -1,5 +1,4 @@
from trezor import wire, ui, loop
from trezor.utils import unimport
# used to confirm/cancel the dialogs from outside of this module (i.e.
# through debug link)
@ -8,7 +7,6 @@ if __debug__:
@ui.layout
@unimport
async def confirm(ctx, content, code=None, *args, **kwargs):
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
from trezor.messages.ButtonRequest import ButtonRequest
@ -31,7 +29,6 @@ async def confirm(ctx, content, code=None, *args, **kwargs):
@ui.layout
@unimport
async def hold_to_confirm(ctx, content, code=None, *args, **kwargs):
from trezor.ui.confirm import HoldToConfirmDialog, CONFIRMED
from trezor.messages.ButtonRequest import ButtonRequest
@ -53,7 +50,6 @@ async def hold_to_confirm(ctx, content, code=None, *args, **kwargs):
return await waiter == CONFIRMED
@unimport
async def require_confirm(*args, **kwargs):
from trezor.messages.FailureType import ActionCancelled

@ -1,5 +1,4 @@
from trezor import wire, ui, loop
from trezor.utils import unimport
# used to confirm/cancel the dialogs from outside of this module (i.e.
# through debug link)
@ -8,7 +7,6 @@ if __debug__:
@ui.layout
@unimport
async def request_words(ctx, content, code=None, *args, **kwargs):
from trezor.ui.word_select import WordSelector
from trezor.messages.ButtonRequest import ButtonRequest

@ -1,17 +1,20 @@
from trezor import log
from trezor import loop
from trezor.utils import unimport
from trezor.wire import register, protobuf_workflow
from trezor.messages.wire_types import \
DebugLinkDecision, DebugLinkGetState, DebugLinkStop, \
DebugLinkMemoryRead, DebugLinkMemoryWrite, DebugLinkFlashErase
@unimport
async def dispatch_DebugLinkDecision(ctx, msg):
from trezor.ui.confirm import CONFIRMED, CANCELLED
from apps.common.confirm import signal
signal.send(CONFIRMED if msg.yes_no else CANCELLED)
@unimport
async def dispatch_DebugLinkGetState(ctx, msg):
from trezor.messages.DebugLinkState import DebugLinkState
from apps.common import storage
@ -26,10 +29,12 @@ async def dispatch_DebugLinkGetState(ctx, msg):
return m
@unimport
async def dispatch_DebugLinkStop(ctx, msg):
pass
@unimport
async def dispatch_DebugLinkMemoryRead(ctx, msg):
from trezor.messages.DebugLinkMemory import DebugLinkMemory
from uctypes import bytes_at
@ -38,6 +43,7 @@ async def dispatch_DebugLinkMemoryRead(ctx, msg):
return m
@unimport
async def dispatch_DebugLinkMemoryWrite(ctx, msg):
from uctypes import bytearray_at
l = len(msg.memory)
@ -45,6 +51,7 @@ async def dispatch_DebugLinkMemoryWrite(ctx, msg):
data[0:l] = msg.memory
@unimport
async def dispatch_DebugLinkFlashErase(ctx, msg):
# TODO: erase(msg.sector)
pass

@ -1,8 +1,6 @@
from trezor import wire, ui
from trezor.utils import unimport
@unimport
async def layout_ethereum_get_address(ctx, msg):
from trezor.messages.EthereumAddress import EthereumAddress
from trezor.crypto.curve import secp256k1

@ -1,13 +1,12 @@
from apps.common.confirm import *
from trezor import wire, ui
from trezor.utils import unimport, chunks
from trezor.utils import chunks
from trezor.messages import ButtonRequestType
from trezor.ui.text import Text
from ubinascii import hexlify
from . import networks
@unimport
async def confirm_tx(ctx, to, value, chain_id, token=None): # todo wording
str_to = '0x' + hexlify(to).decode() # todo use ethereum address format
content = Text('Confirm transaction', ui.ICON_RESET,
@ -17,7 +16,6 @@ async def confirm_tx(ctx, to, value, chain_id, token=None): # todo wording
return await confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
@unimport
async def confirm_fee(ctx, spending, gas_price, gas_limit, chain_id, token=None): # todo wording
content = Text('Confirm fee', ui.ICON_RESET,
'Sending: %s' % format_amount(spending, token, chain_id),
@ -26,7 +24,6 @@ async def confirm_fee(ctx, spending, gas_price, gas_limit, chain_id, token=None)
return await hold_to_confirm(ctx, content, ButtonRequestType.SignTx)
@unimport
async def confirm_data(ctx, data, data_total): # todo wording
str_data = hexlify(data[:8]).decode() + '..'
content = Text('Confirm data:', ui.ICON_RESET,

@ -1,5 +1,3 @@
from trezor.utils import unimport
def message_digest(message):
from apps.wallet.sign_tx.signing import write_varint
@ -16,7 +14,6 @@ def message_digest(message):
return h.get_digest(True)
@unimport
async def ethereum_sign_message(ctx, msg):
from trezor.messages.EthereumMessageSignature import EthereumMessageSignature
from trezor.crypto.curve import secp256k1

@ -1,4 +1,3 @@
from trezor.utils import unimport
from trezor.messages.EthereumSignTx import EthereumSignTx
from trezor.messages.EthereumTxRequest import EthereumTxRequest
from trezor.messages import FailureType
@ -10,7 +9,6 @@ from apps.ethereum import tokens, layout
MAX_CHAIN_ID = 2147483630
@unimport
async def ethereum_sign_tx(ctx, msg):
from trezor.crypto.hashlib import sha3_256

@ -1,7 +1,4 @@
from trezor.utils import unimport
@unimport
async def ethereum_verify_message(ctx, msg):
from .sign_message import message_digest
from trezor.crypto.curve import secp256k1

@ -1,8 +1,6 @@
from trezor import ui, wire
from trezor.utils import unimport
@unimport
async def layout_apply_settings(ctx, msg):
from trezor.messages.Success import Success
from trezor.messages.FailureType import ProcessError

@ -1,7 +1,6 @@
from trezor import ui
from trezor import config
from trezor.pin import pin_to_int, show_pin_timeout
from trezor.utils import unimport
async def request_pin(ctx):
@ -48,7 +47,6 @@ def confirm_change_pin(ctx, msg):
'set new PIN?'))
@unimport
async def layout_change_pin(ctx, msg):
from trezor.messages.Success import Success
from trezor.messages.Failure import Failure

@ -1,9 +1,7 @@
from trezor import wire, ui, config
from trezor.pin import pin_to_int
from trezor.utils import unimport
@unimport
async def layout_load_device(ctx, msg):
from trezor.crypto import bip39
from trezor.messages.Success import Success

@ -8,7 +8,6 @@ if __debug__:
current_word = None
@unimport
async def reset_device(ctx, msg):
from trezor.ui.text import Text
from trezor.crypto import hashlib, random, bip39

@ -1,8 +1,6 @@
from trezor import ui
from trezor.utils import unimport
@unimport
async def layout_wipe_device(ctx, msg):
from trezor.messages.Success import Success
from trezor.ui.text import Text

@ -1,5 +1,4 @@
from trezor import ui
from trezor.utils import unimport
def cipher_key_value(msg, seckey: bytes) -> bytes:
@ -25,7 +24,6 @@ def cipher_key_value(msg, seckey: bytes) -> bytes:
return aes.update(msg.value)
@unimport
async def layout_cipher_key_value(ctx, msg):
from trezor.messages.CipheredKeyValue import CipheredKeyValue
from ..common import seed

@ -1,8 +1,6 @@
from trezor import wire, ui
from trezor.utils import unimport
@unimport
async def layout_get_address(ctx, msg):
from trezor.messages.Address import Address
from trezor.messages.FailureType import ProcessError

@ -1,8 +1,6 @@
from trezor import wire, ui
from trezor.utils import unimport
@unimport
async def layout_get_entropy(ctx, msg):
from trezor.messages.Entropy import Entropy
from trezor.crypto import random

@ -1,7 +1,4 @@
from trezor.utils import unimport
@unimport
async def layout_get_public_key(ctx, msg):
from trezor.messages.HDNodeType import HDNodeType
from trezor.messages.PublicKey import PublicKey

@ -1,5 +1,4 @@
from trezor import ui
from trezor.utils import unimport
def serialize_identity(identity):
@ -80,7 +79,6 @@ def sign_challenge(seckey: bytes,
return signature
@unimport
async def layout_sign_identity(ctx, msg):
from trezor.messages.SignedIdentity import SignedIdentity
from ..common import coins

@ -1,8 +1,6 @@
from trezor import ui
from trezor.utils import unimport
@unimport
async def layout_sign_message(ctx, msg):
from trezor.messages.MessageSignature import MessageSignature
from trezor.crypto.curve import secp256k1

@ -1,8 +1,6 @@
from trezor.utils import unimport
from trezor import wire
@unimport
async def sign_tx(ctx, msg):
from trezor.messages.RequestType import TXFINISHED
from trezor.messages.wire_types import TxAck

@ -1,8 +1,6 @@
from trezor import ui
from trezor.utils import unimport
@unimport
async def layout_verify_message(ctx, msg):
from trezor.messages.Success import Success
from trezor.crypto.curve import secp256k1

@ -4,28 +4,7 @@ import gc
from trezorutils import halt, memcpy
def _gf():
yield
type_gen = type(_gf())
def _unimport_func(func):
def inner(*args, **kwargs):
mods = set(sys.modules)
try:
ret = func(*args, **kwargs)
finally:
for mod in sys.modules:
if mod not in mods:
del sys.modules[mod]
gc.collect()
return ret
return inner
def _unimport_gen(genfunc):
def unimport(genfunc):
async def inner(*args, **kwargs):
mods = set(sys.modules)
try:
@ -39,13 +18,6 @@ def _unimport_gen(genfunc):
return inner
def unimport(func):
if isinstance(func, type_gen):
return _unimport_gen(func)
else:
return _unimport_func(func)
def chunks(items, size):
for i in range(0, len(items), size):
yield items[i:i + size]

Loading…
Cancel
Save