You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.3 KiB
101 lines
3.3 KiB
5 years ago
|
from micropython import const
|
||
6 years ago
|
from ubinascii import hexlify
|
||
6 years ago
|
|
||
8 years ago
|
from trezor import ui
|
||
6 years ago
|
from trezor.messages import ButtonRequestType, OutputScriptType
|
||
4 years ago
|
from trezor.messages.TxOutputType import TxOutputType
|
||
5 years ago
|
from trezor.strings import format_amount
|
||
|
from trezor.utils import chunks
|
||
6 years ago
|
|
||
4 years ago
|
from apps.common import coininfo
|
||
|
|
||
|
if False:
|
||
4 years ago
|
from typing import Iterator
|
||
4 years ago
|
from trezor import wire
|
||
|
|
||
5 years ago
|
_LOCKTIME_TIMESTAMP_MIN_VALUE = const(500000000)
|
||
|
|
||
|
|
||
4 years ago
|
def format_coin_amount(amount: int, coin: coininfo.CoinInfo) -> str:
|
||
5 years ago
|
return "%s %s" % (format_amount(amount, coin.decimals), coin.coin_shortcut)
|
||
8 years ago
|
|
||
|
|
||
4 years ago
|
def split_address(address: str) -> Iterator[str]:
|
||
8 years ago
|
return chunks(address, 17)
|
||
|
|
||
|
|
||
4 years ago
|
def split_op_return(data: str) -> Iterator[str]:
|
||
6 years ago
|
return chunks(data, 18)
|
||
|
|
||
|
|
||
4 years ago
|
async def confirm_output(
|
||
|
ctx: wire.Context, output: TxOutputType, coin: coininfo.CoinInfo
|
||
4 years ago
|
) -> None:
|
||
5 years ago
|
from trezor.ui.text import Text
|
||
4 years ago
|
from apps.common.confirm import require_confirm
|
||
|
from . import omni
|
||
|
from .. import addresses
|
||
5 years ago
|
|
||
7 years ago
|
if output.script_type == OutputScriptType.PAYTOOPRETURN:
|
||
6 years ago
|
data = output.op_return_data
|
||
|
if omni.is_valid(data):
|
||
|
# OMNI transaction
|
||
5 years ago
|
text = Text("OMNI transaction", ui.ICON_SEND, ui.GREEN)
|
||
6 years ago
|
text.normal(omni.parse(data))
|
||
|
else:
|
||
|
# generic OP_RETURN
|
||
4 years ago
|
hex_data = hexlify(data).decode()
|
||
|
if len(hex_data) >= 18 * 5:
|
||
|
hex_data = hex_data[: (18 * 5 - 3)] + "..."
|
||
5 years ago
|
text = Text("OP_RETURN", ui.ICON_SEND, ui.GREEN)
|
||
4 years ago
|
text.mono(*split_op_return(hex_data))
|
||
7 years ago
|
else:
|
||
|
address = output.address
|
||
6 years ago
|
address_short = addresses.address_short(coin, address)
|
||
5 years ago
|
text = Text("Confirm sending", ui.ICON_SEND, ui.GREEN)
|
||
6 years ago
|
text.normal(format_coin_amount(output.amount, coin) + " to")
|
||
6 years ago
|
text.mono(*split_address(address_short))
|
||
4 years ago
|
await require_confirm(ctx, text, ButtonRequestType.ConfirmOutput)
|
||
8 years ago
|
|
||
|
|
||
4 years ago
|
async def confirm_total(
|
||
|
ctx: wire.Context, spending: int, fee: int, coin: coininfo.CoinInfo
|
||
4 years ago
|
) -> None:
|
||
5 years ago
|
from trezor.ui.text import Text
|
||
4 years ago
|
from apps.common.confirm import require_hold_to_confirm
|
||
5 years ago
|
|
||
|
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN)
|
||
6 years ago
|
text.normal("Total amount:")
|
||
6 years ago
|
text.bold(format_coin_amount(spending, coin))
|
||
6 years ago
|
text.normal("including fee:")
|
||
6 years ago
|
text.bold(format_coin_amount(fee, coin))
|
||
4 years ago
|
await require_hold_to_confirm(ctx, text, ButtonRequestType.SignTx)
|
||
8 years ago
|
|
||
|
|
||
4 years ago
|
async def confirm_feeoverthreshold(
|
||
|
ctx: wire.Context, fee: int, coin: coininfo.CoinInfo
|
||
4 years ago
|
) -> None:
|
||
5 years ago
|
from trezor.ui.text import Text
|
||
4 years ago
|
from apps.common.confirm import require_confirm
|
||
5 years ago
|
|
||
|
text = Text("High fee", ui.ICON_SEND, ui.GREEN)
|
||
6 years ago
|
text.normal("The fee of")
|
||
6 years ago
|
text.bold(format_coin_amount(fee, coin))
|
||
6 years ago
|
text.normal("is unexpectedly high.", "Continue?")
|
||
4 years ago
|
await require_confirm(ctx, text, ButtonRequestType.FeeOverThreshold)
|
||
6 years ago
|
|
||
|
|
||
4 years ago
|
async def confirm_nondefault_locktime(ctx: wire.Context, lock_time: int) -> None:
|
||
5 years ago
|
from trezor.ui.text import Text
|
||
4 years ago
|
from apps.common.confirm import require_confirm
|
||
5 years ago
|
|
||
|
text = Text("Confirm locktime", ui.ICON_SEND, ui.GREEN)
|
||
5 years ago
|
text.normal("Locktime for this transaction is set to")
|
||
|
if lock_time < _LOCKTIME_TIMESTAMP_MIN_VALUE:
|
||
|
text.normal("blockheight:")
|
||
|
else:
|
||
|
text.normal("timestamp:")
|
||
|
text.bold(str(lock_time))
|
||
|
text.normal("Continue?")
|
||
4 years ago
|
await require_confirm(ctx, text, ButtonRequestType.SignTx)
|