mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-06 14:52:33 +00:00
80 lines
2.7 KiB
Python
80 lines
2.7 KiB
Python
from trezor.utils import unimport
|
|
from trezor import wire
|
|
|
|
|
|
def format_amount(amount, coin):
|
|
return '%s %s' % (amount / 1e8, coin.coin_shortcut)
|
|
|
|
|
|
def split_address(address):
|
|
from trezor.utils import chunks
|
|
return chunks(address, 17)
|
|
|
|
|
|
async def confirm_output(session_id, output, coin):
|
|
from trezor import ui
|
|
from trezor.ui.text import Text
|
|
from trezor.messages.ButtonRequestType import ConfirmOutput
|
|
from ..common.confirm import confirm
|
|
|
|
content = Text('Confirm output', ui.ICON_RESET,
|
|
ui.BOLD, format_amount(output.amount, coin),
|
|
ui.NORMAL, 'to',
|
|
ui.MONO, *split_address(output.address))
|
|
return await confirm(session_id, content, ConfirmOutput)
|
|
|
|
|
|
async def confirm_total(session_id, spending, fee, coin):
|
|
from trezor import ui
|
|
from trezor.ui.text import Text
|
|
from trezor.messages.ButtonRequestType import SignTx
|
|
from ..common.confirm import hold_to_confirm
|
|
|
|
content = Text('Confirm transaction', ui.ICON_RESET,
|
|
'Sending: %s' % format_amount(spending, coin),
|
|
'Fee: %s' % format_amount(fee, coin))
|
|
return await hold_to_confirm(session_id, content, SignTx)
|
|
|
|
|
|
async def confirm_feeoverthreshold(session_id, fee, coin):
|
|
from trezor import ui
|
|
from trezor.ui.text import Text
|
|
from trezor.messages.ButtonRequestType import FeeOverThreshold
|
|
from ..common.confirm import confirm
|
|
|
|
content = Text('Confirm high fee:', ui.ICON_RESET,
|
|
ui.BOLD, format_amount(fee, coin))
|
|
return await confirm(session_id, content, FeeOverThreshold)
|
|
|
|
|
|
@unimport
|
|
async def layout_sign_tx(msg, session_id):
|
|
from ..common.seed import get_root_node
|
|
from ..common import signtx
|
|
|
|
from trezor.messages.RequestType import TXFINISHED
|
|
from trezor.messages.wire_types import TxAck
|
|
|
|
root = await get_root_node(session_id)
|
|
|
|
signer = signtx.sign_tx(msg, root)
|
|
res = None
|
|
while True:
|
|
try:
|
|
req = signer.send(res)
|
|
except signtx.SigningError as e:
|
|
raise wire.FailureError(*e.args)
|
|
if req.__qualname__ == 'TxRequest':
|
|
if req.request_type == TXFINISHED:
|
|
break
|
|
res = await wire.reply_message(session_id, req, TxAck)
|
|
elif req.__qualname__ == 'UiConfirmOutput':
|
|
res = await confirm_output(session_id, req.output, req.coin)
|
|
elif req.__qualname__ == 'UiConfirmTotal':
|
|
res = await confirm_total(session_id, req.spending, req.fee, req.coin)
|
|
elif req.__qualname__ == 'UiConfirmFeeOverThreshold':
|
|
res = await confirm_feeoverthreshold(session_id, req.fee, req.coin)
|
|
else:
|
|
raise TypeError('Invalid signing instruction')
|
|
return req
|